Debian 9/Ubuntu18.04添加rc.local开机自启

debian9和ubuntu18.04默认已经没有rc.local文件,但设置启动执行命令这又是最简单的办法需要手动开启
新建 /etc/systemd/system/rc-local.service 文件

[Unit]
Description=/etc/rc.local
ConditionPathExists=/etc/rc.local
 
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
 
[Install]
WantedBy=multi-user.target

新建/etc/rc.local文件

#!/bin/sh
#
# 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

添加权限设置自启

chmod +x /etc/rc.local
systemctl enable rc-local
systemctl start rc-local.service

检测启动状态

systemctl status rc-local.service

吧命令添加到/etc/rc.local文件 exit 0前即可

https://www.moerats.com/archives/623/

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注