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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM