linux设置agent开机自启动说明(ubuntu)

    此文是ubuntu开机自启动说明(CentOS开机自启动点击此处debian开机自启动点击此处),如果是windows开机自启动服务,请查看将agent注册为windows系统服务

  • 1.以Ubuntu 18为例,新建rc-local.service文件,
    vim /etc/systemd/system/rc-local.service
    内容如下,将下列内容复制进rc-local.service文件
    [Unit]
    Description=/etc/rc.local Compatibility
    ConditionPathExists=/etc/rc.local
    
    [Service]
    Type=forking
    ExecStart=/etc/rc.local start
    TimeoutSec=0
    StandardOutput=tty
    RemainAfterExit=yes
    SysVStartPriority=99
    
    [Install]
    WantedBy=multi-user.target
    
  • 2.创建文件rc.local
    vim /etc/rc.local
    内容如下
    #!/bin/sh -e
    # 
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
    /usr/local/wgcloud-v3.3.5/agent/start.sh
    exit 0
    
    其中/usr/local/wgcloud-v3.3.5/agent/start.sh为自己的agent实际路径
  • 3.给rc.local加上权限
    chmod +x /etc/rc.local
  • 4.最后一步,启用服务,
    systemctl enable rc-local
  • 5.server开机启动,和agent操作一致