码迷,mamicode.com
首页 > 其他好文 > 详细

将zabbix agentd注册为service服务

时间:2017-08-01 16:30:01      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:down   kill   sys   style   rc.d   zab   back   ons   res   

标记部分为启动文件和配置文件路径,以及lock文件路径。其他地方不作修改

在/etc/rc.d/init.d下面添加可执行文件,比如是11

就能使用service 11 start|stop|restart等命令了,注册service服务的好处是还能加入chkconfig中

#!/bin/sh

# Source function library.
. /etc/rc.d/init.d/functions

if [ -x /usr/sbin/zabbix_agentd ]; then
     exec=/usr/sbin/zabbix_agentd
else
     exit 5
fi

prog=${exec##*/}
conf=/etc/zabbix/zabbix_agentd.conf
pidfile=$(grep -e "^PidFile=.*$" $conf | cut -d= -f2)
timeout=10

lockfile=/var/lock/subsys/zabbix-agent

start()
{
     echo -n $"Starting Zabbix agent: "
     daemon $exec -c $conf
     rv=$?
     echo
     [ $rv -eq 0 ] && touch $lockfile
     return $rv
}

stop()
{
     echo -n $"Shutting down Zabbix agent: "
     killproc -p $pidfile -d $timeout $prog
     rv=$?
     echo
     [ $rv -eq 0 ] && rm -f $lockfile
     return $rv
}

restart()
{
     stop
     start
}

case "$1" in
     start|stop|restart)
         $1
         ;;
     force-reload)
         restart
         ;;
     status)
         status -p $pidfile $prog
         ;;
     try-restart|condrestart)
         if status $prog >/dev/null ; then
             restart
         fi
         ;;
     reload)
         action $"Service ${0##*/} does not support the reload action: " /bin/false
         exit 3
         ;;
     *)
         echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
         exit 2
         ;;
esac

将zabbix agentd注册为service服务

标签:down   kill   sys   style   rc.d   zab   back   ons   res   

原文地址:http://www.cnblogs.com/woailifang/p/7269009.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!