centos設置開機自動運行腳本


方式一

  1、權限編輯/etc/rc.d/rc.local

    cd /etc/rc.d/

      vim rc.local

  2、在末尾添加執行腳本命令

    sh /home/test.sh

  3、給腳本賦權限

    chmod +x /etc/rc.d/rc.local
    chmod +x /home/test.sh

方式二:

  1、添加啟動服務

    cd /usr/lib/systemd/system

    vim test-autorun.service

    將以下內容寫到service

      [Unit]

      Description=emqx for auto start

      Wants=network-online.target

 

      [Service]

      User=root

      Type=forking

      ExecStart=/usr/bin/bash /home/test.sh start

      ExecStop=/usr/bin/bash /root/test.sh stop

 

      [Install]

      WantedBy=multi-user.target

   2、重新加載systemd配置

    systemctl daemon-reload

  3、添加開機自啟動

    systemctl enable test-autorun.service

 

 

 


免責聲明!

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



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