1. 程式人生 > >添加服務到chkconfig中

添加服務到chkconfig中

chkconfig chkconfig添加服務

man chkconfig
For example, random.init has these three lines:
# chkconfig: 2345 20 80 解釋:2345 是在這幾個級別上默認on 20 80 是啟動關閉順序
# description: Saves and restores system entropy pool for \
# higher quality random number generation.

重點:需要把腳本放在/etc/init.d/目錄下

添加:

[root@csa ~]# vim nopsmile.sh 
#!/bin/sh
# chkconfig: 2345 20 80
# description: test
echo "I‘m nopsmile"

[root@csa ~]# mv nopsmile.sh /etc/init.d/
[root@csa ~]# chkconfig --add nopsmile.sh 
[root@csa ~]# chkconfig --list | grep nopsmile
nopsmile.sh     0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@csa ~]# ls -l /etc/rc.d/rc3.d/*nopsmile*
lrwxrwxrwx 1 root root 21 Mar 16 09:09 /etc/rc.d/rc3.d/S20nopsmile.sh -> ../init.d/nopsmile.sh

[root@csa ~]# chkconfig --level 3 nopsmile.sh off
[root@csa ~]# chkconfig --list | grep nopsmile           
nopsmile.sh     0:off   1:off   2:on    3:off   4:on    5:on    6:off
[root@csa ~]# ls -l /etc/rc.d/rc3.d/*nopsmile*
lrwxrwxrwx 1 root root 21 Mar 16 09:16 /etc/rc.d/rc3.d/K80nopsmile.sh -> ../init.d/nopsmile.sh
[on是在S20 ,off是在K80]
刪除:

[root@csa ~]# chkconfig --del nopsmile.sh 
[root@csa ~]# chkconfig --list | grep nopsmile
結果是空。
[root@csa ~]# ls -l /etc/rc.d/rc3.d/*nopsmile*
ls: cannot access /etc/rc.d/rc3.d/*nopsmile*: No such file or directory
原理:
/etc/rc.d/ 下2345 如rc3.d/添加鏈接

添加服務到chkconfig中