首页 > 运维类 > LINUX运维 > Debian添加开机启动项

2212

浏览

0

评论

Debian添加开机启动项

作者:stephen | 分类:LINUX运维 | 标签:

Linux系统设置开机启动有很多方法,网上也有许多详细教程。本文只关注用 update-rc.d 命令给 Debian 添加开机启动。

例如:将test.sh脚本添加到开机自启。

1.将 test.sh 脚本放到 /etc/init.d/ 目录下

1
2
3
cp test.sh /etc/init.d/  
cd /etc/init.d/  
chmod +x  test.sh

2.设置开机自启

1
update-rc.d test.sh defaults

运行 update-rc.d 很可能会出现错误提示:

1
insserv: warning: script 'test.sh' missing LSB tags and overrides

这是因为 test.sh 不符合 debian 开机自启文件的内容规范,debian 要求文件头部有启动信息。参考同目录下的 /etc/init.d/skeleton 文件头,把以下内容复制到 test.sh 再运行 update-rc.d test.sh defaults 。

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/sh
### BEGIN INIT INFO
# Provides:          test
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description: test
# Description: test
### END INIT INFO

3.删除开机启动

1
update-rc.d -f test.sh remove


本文链接:https://www.stephenwxf.com/post/156.html
原创文章如转载请注明:转载自王显璠的个人博客谢谢!

Copyright Your stephenwxf.com Rights Reserved.