By accessing the website and accepting the Cookie Policy, you agree to use the cookies provided by the Site in accordance with to analyze traffic, remember your preferences, and optimize your experience.

标签 - 自启动

debian rc.local 自启动    2018-11-23 17:07:33    2006    0    0

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.  
  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文件

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

  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、添加权限并设置开机自启

  1. chmod +/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.servi