1) 将你的启动脚本复制到 /etc/init.d目录下
以下假设你的脚本文件名为 test.sh。
2) 设置脚本文件的权限
$ sudo chmod 755 /etc/init.d/test.sh
3) 执行如下命令将脚本放到启动脚本中去:
1$ cd /etc/init.d 2$ sudo update-rc.d test.sh defaults 95
注:其中数字95是脚本启动的顺序号,按照自己的需要相应修改即可。在你有多个启动脚本,而它们之间又有先后启动的依赖关系时你就知道这个数字的具体作用了。该命令的输出信息参考如下:
1update-rc.d: warning: /etc/init.d/test.sh missing LSB information 2update-rc.d: see <http://wiki.debian.org/LSBInitScripts> 3 Adding system startup for /etc/init.d/test.sh ... 4 /etc/rc0.d/K95test -> ../init.d/test.sh 5 /etc/rc1.d/K95test -> ../init.d/test.sh 6 /etc/rc6.d/K95test -> ../init.d/test.sh 7 /etc/rc2.d/S95test -> ../init.d/test.sh 8 /etc/rc3.d/S95test -> ../init.d/test.sh 9 /etc/rc4.d/S95test -> ../init.d/test.sh 10 /etc/rc5.d/S95test -> ../init.d/test.sh
卸载启动脚本的方法:
1$ cd /etc/init.d 2$ sudo update-rc.d -f test.sh remove
命令输出的信息参考如下:
1Removing any system startup links for /etc/init.d/test.sh ... 2 /etc/rc0.d/K95test.sh 3 /etc/rc1.d/K95test.sh 4 /etc/rc2.d/S95test.sh 5 /etc/rc3.d/S95test.sh 6 /etc/rc4.d/S95test.sh 7 /etc/rc5.d/S95test.sh 8 /etc/rc6.d/K95test.sh