操作
在/etc/init.d下新建示例腳本文件(customize.sh),該腳本會啟動zookeeper服務。內容如下:
1 #!/bin/sh 2 3 /usr/local/zookeeper-3.4.10/bin/zkServer.sh start
執行如下命令將customize.sh腳本添加到系統服務中。
root@jacob-PC:~# chkconfig --add customize.sh insserv: warning: script 'K01customize.sh' missing LSB tags and overrides insserv: warning: script 'customize.sh' missing LSB tags and overrides customize.sh 0:off 1:off 2:on 3:on 4:on 5:on 6:off root@jacob-PC:~# chkconfig customize.sh on insserv: warning: script 'K01customize.sh' missing LSB tags and overrides insserv: warning: script 'customize.sh' missing LSB tags and overrides
jacob@jacob-PC:/etc/init.d$ chkconfig acpid on alsa-utils on avahi-daemon on bluetooth on bumblebeed on cron on cryptdisks on cryptdisks-early on cups on customize.sh 2345 dbus on dnsmasq on docker on hwclock.sh on ipsec off kmod on lightdm on lvm2 on lvm2-lvmetad on lvm2-lvmpolld on mdadm on mdadm-waitidle off mysql on network-manager on networking on nmbd on nscd on open-vm-tools on openvpn off plymouth on plymouth-log on pppd-dns on procps on rcS off redis-server on samba-ad-dc on smbd on sudo off udev on x11-common on xl2tpd off
如果沒有安裝chkconfig,可以自行安裝一個,例如:ubuntu或deepin系統可以采用下面命令
sudo apt-get install chkconfig
原理
通過chkconfig命令將自定義的sh腳本添加到系統的服務當中。
root@jacob-PC:~# chkconfig --add customize.sh insserv: warning: script 'K01customize.sh' missing LSB tags and overrides insserv: warning: script 'customize.sh' missing LSB tags and overrides customize.sh 0:off 1:off 2:on 3:on 4:on 5:on 6:off
增加服務時,會提示0-6的一些狀態,實際上這些是對應於 /etc/rc*.d的目錄。
root@jacob-PC:/etc# ls -l | grep rc -rw-r--r-- 1 root root 1863 3月 1 20:11 bash.bashrc -rw-r--r-- 1 root root 4479 3月 1 20:11 drirc -rw-r--r-- 1 root root 1748 3月 1 20:11 inputrc -rw-r--r-- 1 root root 288 4月 11 2017 mecabrc -rw-r--r-- 1 root root 9333 3月 1 20:11 nanorc drwxr-xr-x 2 root root 4096 3月 1 20:16 ODBCDataSources drwxr-xr-x 2 root root 4096 3月 31 21:49 rc0.d drwxr-xr-x 2 root root 4096 3月 31 21:49 rc1.d drwxr-xr-x 2 root root 4096 3月 31 21:49 rc2.d drwxr-xr-x 2 root root 4096 3月 31 21:49 rc3.d drwxr-xr-x 2 root root 4096 3月 31 21:49 rc4.d drwxr-xr-x 2 root root 4096 3月 31 21:49 rc5.d drwxr-xr-x 2 root root 4096 3月 31 21:49 rc6.d drwxr-xr-x 2 root root 4096 3月 1 20:11 rcS.d -rw-r--r-- 1 root root 4942 3月 1 20:11 wgetrc
#0 ——停機(不能使用)
#1——單用戶模式
#2——多用戶模式,但是沒有NFS
#3——完全多用戶模式
#4——沒有使用
#5——圖形界面模式
#6——重啟模式(不能使用)
對於這幾個目錄的解釋,有幾篇文章可以參考:
https://blog.csdn.net/feiyinzilgd/article/details/5750168
文章里說cat /etc/inittab里面存放了默認的啟動模式,但是我deepin系統好像沒有這個文件,也不打算深究了。
