有些时候我们需要用
/etc/rc.local
管理开机启动,Debian 9+/Ubuntu 17+以后系统都没有rc.local文件了,想要像以前一样,在/etc/rc.local
中设置开机启动程序,按下面教程设置即可。
1.添加rc-local.service服务文件:
cat > /etc/systemd/system/rc-local.service <<EOF
[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
EOF
2.新建rc-local文件:
cat > /etc/rc.local <<EOF
#!/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
EOF
3.添加权限 /设置开机自启 /启动脚本:
chmod +x /etc/rc.local
systemctl enable rc-local
systemctl start rc-local.service
4.检查状态:
systemctl status rc-local.service
5.完成之后就可以在/etc/rc.local
中的exit
前增加你想启动的脚本了。
One comment
非技术的路过。