ランレベルの話など

備忘録的に書いておこうと思います。

ランレベル


OS起動時のランレベルを調べる必要があるときもあります。


「/etc/inittab」の「initdefault」の値になります。


RedHat系のLinuxでは、このような記載があれば、ランレベルは3になります。
(Debian系は最近触ってないので忘れました・・・)

id:3:initdefault:


実際のランレベルを確認するには「runlevel」コマンドです。

# runlevel
N 3

ランレベル毎の起動サービスの設定


RedHat系の場合、「chkconfig」コマンドで実行します。


「chkconfig --list」で登録されているサービスの一覧を表示します。


下の例は、結構いろんなサービス動かしっぱなしです。

# chkconfig --list
Monitoring            0:off	1:off	2:off	3:on	4:on	5:on	6:off
MonitoringScout  0:off	1:off	2:off	3:on	4:on	5:on	6:off
NetworkManager 0:off	1:off	2:off	3:off	4:off	5:off	6:off
acpid                      0:off	1:off	2:on	3:on	4:on	5:on	6:off
anacron        	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
apmd           	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
atd            	        0:off	1:off	2:off	3:on	4:on	5:on	6:off
auditd         	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
autofs         	        0:off	1:off	2:off	3:on	4:on	5:on	6:off
avahi-daemon   	0:off	1:off	2:off	3:on	4:on	5:on	6:off
avahi-dnsconfd 	0:off	1:off	2:off	3:off	4:off	5:off	6:off
bluetooth      	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
cobblerd       	        0:off	1:off	2:off	3:on	4:on	5:on	6:off
conman         	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
cpuspeed       	0:off	1:on	2:on	3:on	4:on	5:on	6:off
crond          	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
cups           	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
dc_client      	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
dc_server      	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
dnsmasq        	0:off	1:off	2:off	3:off	4:off	5:off	6:off
dund           	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
firstboot      	        0:off	1:off	2:off	3:on	4:off	5:on	6:off
gpm            	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
haldaemon      	0:off	1:off	2:off	3:on	4:on	5:on	6:off
hidd           	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
httpd          	        0:off	1:off	2:off	3:on	4:on	5:on	6:off
ibmasm         	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
ip6tables      	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
iptables       	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
irda           	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
irqbalance     	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
jabberd        	        0:off	1:off	2:off	3:on	4:on	5:on	6:off
kudzu          	        0:off	1:off	2:off	3:on	4:on	5:on	6:off
lvm2-monitor   	0:off	1:on	2:on	3:on	4:on	5:on	6:off
mcstrans       	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
mdmonitor      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
mdmpd          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
messagebus     	0:off	1:off	2:off	3:on	4:on	5:on	6:off
microcode_ctl  	0:off	1:off	2:on	3:on	4:on	5:on	6:off
multipathd     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
netfs          	        0:off	1:off	2:off	3:on	4:on	5:on	6:off
netplugd       	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
network        	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
nfs            	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
nfslock        	        0:off	1:off	2:off	3:on	4:on	5:on	6:off
nscd           	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
ntpd           	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
oddjobd                 0:off	1:off	2:off	3:off	4:off	5:off	6:off
osa-dispatcher 	0:off	1:off	2:off	3:on	4:on	5:on	6:off
pand           	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
pcscd          	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
portmap        	        0:off	1:off	2:off	3:on	4:on	5:on	6:off
postgresql     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
psacct         	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
rawdevices     	0:off	1:off	2:off	3:on	4:on	5:on	6:off
rdisc          	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
readahead_early	0:off	1:off	2:on	3:on	4:on	5:on	6:off
readahead_later	0:off	1:off	2:off	3:off	4:off	5:on	6:off
restorecond    	0:off	1:off	2:on	3:on	4:on	5:on	6:off
rhn-search     	0:off	1:off	2:off	3:on	4:on	5:on	6:off
rpcgssd        	        0:off	1:off	2:off	3:on	4:on	5:on	6:off
rpcidmapd      	0:off	1:off	2:off	3:on	4:on	5:on	6:off
rpcsvcgssd     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
saslauthd      	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
sendmail       	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
smartd         	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
sshd           	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
syslog         	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
taskomatic     	0:off	1:off	2:off	3:on	4:on	5:on	6:off
tcsd           	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
tomcat5        	        0:off	1:off	2:off	3:on	4:on	5:on	6:off
vsftpd         	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
wpa_supplicant 	0:off	1:off	2:off	3:off	4:off	5:off	6:off
xfs            	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
xinetd         	        0:off	1:off	2:on	3:on	4:on	5:on	6:off
ypbind         	        0:off	1:off	2:off	3:off	4:off	5:off	6:off
yum-updatesd   	0:off	1:off	2:on	3:on	4:on	5:on	6:off

xinetd ベースのサービス:
	chargen-dgram: 	off
	chargen-stream:	off
	daytime-dgram: 	off
	daytime-stream:	off
	discard-dgram: 	off
	discard-stream:	off
	echo-dgram:    	off
	echo-stream:   	off
	eklogin:       	        off
	ekrb5-telnet:  	off
	gssftp:        	        off
	klogin:        	        off
	krb5-telnet:   	off
	kshell:        	        off
	rsync:         	        off
	tcpmux-server: 	off
	tftp:          	        on
	time-dgram:    	off
	time-stream:   	off


「 chkconfig --level [level] [service name] [on | off]」で
ランレベル毎のサービス起動/停止を変更できます。


下はsendmailについて、設定のon/offをしている例です。

# chkconfig --list sendmail
sendmail       	0:off	1:off	2:on	3:on	4:on	5:on	6:off

# chkconfig --level 2345 sendmail off
# chkconfig --list sendmail
sendmail       	0:off	1:off	2:off	3:off	4:off	5:off	6:off

# chkconfig --level 2345 sendmail on
# chkconfig --list sendmail
sendmail       	0:off	1:off	2:on	3:on	4:on	5:on	6:off


サービスの登録/解除は、「chkconfig --add / chkconfig --del」です。


下はsendmailのサービス登録/解除を行っている例です。

# chkconfig --list sendmail
sendmail       	0:off	1:off	2:on	3:on	4:on	5:on	6:off

# chkconfig --del sendmail
# chkconfig --list sendmail
サービス sendmail は chkconfig をサポートしますが実行レベルで参照されていません (run 'chkconfig --add sendmail')

# chkconfig --add sendmail
# chkconfig --list sendmail
sendmail       	0:off	1:off	2:on	3:on	4:on	5:on	6:off


「chkconfig」を使って、サービスを登録すると、「/etc/init.d」以下の起動スクリプトが使われます。


コメント中の「chkconfig」の所には、[onにするランレベル] [起動時の優先度] [停止時の優先度]が書かれています。


下はsendmailの例です。
ランレベル2 - 5」「起動時の優先度は80」「停止時の優先度は30」になるはず。

#!/bin/bash
#
# sendmail      This shell script takes care of starting and stopping
#               sendmail.
#
# chkconfig: 2345 80 30
# description: Sendmail is a Mail Transport Agent, which is the program \
#              that moves mail from one machine to another.
# processname: sendmail
# config: /etc/mail/sendmail.cf
# pidfile: /var/run/sendmail.pid
# ls -la /etc/rc2.d/S80sendmail 
lrwxrwxrwx 1 root root 18 11月  7 13:10 /etc/rc2.d/S80sendmail -> ../init.d/sendmail

# ls -la /etc/rc6.d/K30sendmail 
lrwxrwxrwx 1 root root 18 11月  7 13:10 /etc/rc6.d/K30sendmail -> ../init.d/sendmail


「service」コマンドを使うと、サービスに対しての制御を行えます。
「/etc/init.d/xxxx xxxx」みたいな事をやるのに近いでしょうか。
(私は/etc/init.d/xxxx でやってしまうタイプです。)


「service [service name] --hl」で引数一覧を表示します。

# service sendmail --hl
使い方: /etc/init.d/sendmail {start|stop|restart|condrestart|status}


下はsendmailを起動/停止する例です。

# service sendmail stop
sm-client を停止中:                                        [  OK  ]
sendmail を停止中:                                         [  OK  ]

# service sendmail start
sendmail を起動中:                                         [  OK  ]
sm-client を起動中:                                        [  OK  ]


これでも変わらないですね。

# /etc/init.d/sendmail stop
sm-client を停止中:                                        [  OK  ]
sendmail を停止中:                                         [  OK  ]

# /etc/init.d/sendmail start
sendmail を起動中:                                         [  OK  ]
sm-client を起動中:                                        [  OK  ]

参考

今日はこんなところで。