1.在/etc/rc.d/init.d新建启动脚本startAgent.sh,内容如下

#!/bin/sh
#chkconfig: 35 20 80               分别代表运行级别,启动优先权,关闭优先权,此行代码必须
#description: wgcloud agent
/bin/echo $(/bin/date +%F_%T) >> /tmp/agent.log
/usr/local/wgcloud-v3.3.3/agent/start.sh

/usr/local/wgcloud-v3.3.3/agent/start.sh为自己的agent实际路径

2.添加可执行权限

chmod +x startAgent.sh

测试下脚本是否能成功启动agent

./startAgent.sh

3.添加脚本到开机自动启动项目中。添加到chkconfig,开机自启动

[root@localhost ~]# cd /etc/rc.d/init.d
[root@localhost ~]# chkconfig --add startAgent.sh
[root@localhost ~]# chkconfig startAgent.sh on

4. 其他说明

# 关闭开机启动 
[root@localhost ~]# chkconfig startAgent.sh off

# 从chkconfig管理中删除startAgent.sh
[root@localhost ~]# chkconfig --del startAgent.sh

# 查看chkconfig管理
[root@localhost ~]# chkconfig --list startAgent.sh

更多推荐