Skip to content

Instantly share code, notes, and snippets.

@shui
Created January 29, 2018 06:01
Show Gist options
  • Save shui/11898b6a797ada1a7c91c403fb98904c to your computer and use it in GitHub Desktop.
Save shui/11898b6a797ada1a7c91c403fb98904c to your computer and use it in GitHub Desktop.
用update-rc.d命令给Debian添加开机启动项

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

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

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

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

2.设置开机自启

update-rc.d test.sh defaults  

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

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

#!/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.删除开机启动

update-rc.d -f test.sh remove  

Ref:用update-rc.d命令给Debian添加开机启动项

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment