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