linux系统增加开机启动服务/应用

操作

在/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系统好像没有这个文件,也不打算深究了。

posted @ 2018-03-31 22:22  海华85  阅读(5181)  评论(0编辑  收藏  举报