记录我的一些生活写照、无聊的牢骚、内心世界的活动 注册 | 登陆

Debian9/10添加开机自启动方法rc.local

Debian9/10添加开机自启动方法rc.local

1、添加rc-local.service

#以下为一整条命令,一起复制运行

XML/HTML代码
  1. cat > /etc/systemd/system/rc-local.service <<EOF  
  2. [Unit]  
  3. Description=/etc/rc.local  
  4. ConditionPathExists=/etc/rc.local  
  5.    
  6. [Service]  
  7. Type=forking  
  8. ExecStart=/etc/rc.local start  
  9. TimeoutSec=0  
  10. StandardOutput=tty  
  11. RemainAfterExit=yes  
  12. SysVStartPriority=99  
  13.    
  14. [Install]  
  15. WantedBy=multi-user.target  
  16. EOF  

2、新建rc-local文件

#以下为一整条命令,一起复制运行

XML/HTML代码
  1. cat > /etc/rc.local <<EOF  
  2. #!/bin/sh -e  
  3. #  
  4. # rc.local  
  5. #  
  6. # This script is executed at the end of each multiuser runlevel.  
  7. # Make sure that the script will "exit 0" on success or any other  
  8. # value on error.  
  9. #  
  10. # In order to enable or disable this script just change the execution  
  11. # bits.  
  12. #  
  13. # By default this script does nothing.  
  14.    
  15. # bash /root/bindip.sh  
  16.    
  17. exit 0  
  18. EOF  

3、添加权限并设置开机自启

XML/HTML代码
  1. chmod +x /etc/rc.local  
  2. systemctl enable rc-local  
  3. systemctl start rc-local.service  

检查状态

XML/HTML代码
  1. systemctl status rc-local.service  

返回Active:active信息,则成功。

最后我们就可以在/etc/rc.loacl里,添加开机的自启命令什么的了。记住添加在exit 0之前。

注意:更改自启脚本后,需要重新运行一下命令已使其生效。

systemctl enable rc-local

systemctl start rc-local.service

« 上一篇 | 下一篇 »

发表评论

评论内容 (必填):