解决Debian 9.x无法通过/etc/rc.local 开机启动问题

在程序部署中,我们会遇到某些软件并没有附加到系统服务中,无法通过systemctl或者service来控制开机自启,所以一些脚本中,我都是推荐添加启动命令到 /etc/rc.local 文件中,但是 Debian 9非常奇葩, 默认不带 /etc/rc.local 文件,但是却没阉割掉rc.local 服务,所以我们需要补齐缺失的文件。

创建服务:

cat > /etc/systemd/system/rc-local.service <

因为rc.local文件丢失,我们需要手工添加一个 /etc/rc.local文件:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0

或者执行快速添加脚本:

echo " 
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0 " > /etc/rc.local

然后赋予权限:

chmod +x /etc/rc.local

接着启动 rc-local 服务:

systemctl start rc-local.service

将 rc-local 加入开机自启:

systemctl enable rc-local

测试服务是否正常:

systemctl status rc-local.service

将需要开机自动启动的脚本放在/etc/rc.local 中exit 0 之前,就可以开机自动执行了。

» 本文链接:解决Debian 9.x无法通过/etc/rc.local 开机启动问题
» 转载请注明来源:刺客博客
» 如果文章失效或者安装失败,请留言进行反馈。
debianrc.local
Comments (1)
Add Comment
  • Sai

    个人感觉,不是debian奇葩,是因为debian遵循等级配置,部署到相应rcx目录下!求大虾莫拍砖!