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

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

服务检测:

cat /lib/systemd/system/rc.local.service

因为文件丢失,我们需要手工添加一个 /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

测试服务是否正常:

systemctl status rc-local

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

» 本文链接:解决Debian 9.x无法通过/etc/rc.local 开机启动问题
» 转载请注明来源:刺客博客
» VPS推荐:Hostdare 年付16美元的GIA 洛杉矶Crea机房
» 如果文章失效或者安装失败,请联系站长微信:myjinr2(备注博客)
评论 (1)
  1. 沙发
    Sai 11 天前

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

请输入以下运算结果: