centos设置开机自动运行脚本 vofill

方式一

  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

 

原文地址:https://www.cnblogs.com/vofill/p/15752997.html