Debian 9+/Ubuntu 17+添加rc.local开机自启

2022-11-25 20:10:31 数码网络 17次阅读

有些时候我们需要用/etc/rc.local管理开机启动,Debian 9+/Ubuntu 17+以后系统都没有rc.local文件了,想要像以前一样,在/etc/rc.local中设置开机启动程序,按下面教程设置即可。Hbu最优选-有趣的知识分享平台!

1.添加rc-local.service服务文件:Hbu最优选-有趣的知识分享平台!

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文件:Hbu最优选-有趣的知识分享平台!

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.添加权限 /设置开机自启 /启动脚本:Hbu最优选-有趣的知识分享平台!

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

4.检查状态:Hbu最优选-有趣的知识分享平台!

systemctl status rc-local.service

5.完成之后就可以在/etc/rc.local中的exit前增加你想启动的脚本了。Hbu最优选-有趣的知识分享平台!

声明:本站资料均来源互联网收集整理,作品版权归作者所有,如果侵犯了您的版权,请跟我们联系246888487@qq.com