Debian_Ubuntu添加rc.local开机自启

Debian_Ubuntu添加rc.local开机自启

现在debian和ubuntu默认取消了rc.local,只能自己手动开启了

1. 添加rc-local.service,下方命令直接复制粘贴到SSH回车

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文件,下方命令直接复制粘贴到SSH回车

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. 检查状态,直接复制粘贴到SSH回车

systemctl status rc-local.service

5. 在 /etc/rc.local 里加入自己要开机自启的命令,需要把命令添加 exit 0 之前,exit 0 结尾

© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容