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操作一致
  • 注意,如果server不能开机启动成功,且没有在server/log下输出启动日志,那么可能是开机时候JDK环境变量未准备好,
    这时候可以把server/start.sh中的java改为JDK绝对路径
    server/start.sh修改前如下
    nohup java  -server -Dloader.path=./lib  -Xms256m -Xmx512m  -jar $RUN_NAME >/dev/null 2>&1 &
    修改为如下,其中/java/jdk1.8.0_152为jdk的实际路径
    nohup /java/jdk1.8.0_152/bin/java  -server -Dloader.path=./lib  -Xms256m -Xmx512m  -jar $RUN_NAME >/dev/null 2>&1 &
    再试试吧