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

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

 

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

1、添加rc-local.service

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

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

2、新建rc-local文件

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

 
  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. # bash /root/bindip.sh
  15. exit 0
  16. EOF

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

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

检查状态

 
  1. systemctl status rc-local.service

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

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

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

systemctl enable rc-local

systemctl start rc-local.service

posted @ 2020-09-19 17:55  yang-leo  阅读(7333)  评论(0编辑  收藏  举报