这里主要想介绍一下用chkconfig
配置自启动服务,包括如何控制服务启动顺序以及启动依赖。虽然本文中提到的脚本的测试环境都是在CentOS上,但是因为使用的配置文件是LSB-style的,所以在其他Linux上也基本能用,只是使用的工具不一样,如在debian上使用update-rc.d
。首先从如何简单的添加一个自启动服务说起。
如何添加一个自启动服务
首先,你需要一个服务配置脚本,在/etc/init.d下面创建一个文件,如test-init
touch /etc/init.d/test-init chmod +x /etc/init.d/test-init
给这个文件写入如下内容
#!/bin/sh # chkconfig: 2345 20 80 # description: Saves and restores system entropy pool for \ # higher quality random number generation. case "$1" in start) echo "start testinit" >> /root/test.init ;; stop) echo "stop testinit" >> /root/test.init ;; restart) echo "restart testinit" >> /root/test.init ;; *)