zabbix-server或者agent启动脚本

#!/bin/sh
#chkconfig:345 95 95
#description:zabbix server
# zabbix_server_ctl 
#
# control script to stop/start/restart zabbix_server
# author: charlie collins
#
# (setup for Red Hat 7.3 with Zabbix)
# (should work for other Red Hat and Sys V style init machines as well)
#
# (modeled after apache style control scripts)
# (this script can be placed in init.d and respective runlevel for startup usage)

# The exit codes returned are:
# 0 - operation completed successfully
# 1 - 
# 2 - usage error
# 3 - zabbix_server could not be started
# 4 - zabbix_server could not be stopped
# 5 - zabbix_server could not be started during a restart
# 6 - zabbix_server could not be restarted during a restart
#
#


# **************
# config options
# **************
#
# (set config options to match your system settings) 


# base zabbix dir
BASEDIR=/usr/local/zabbix
# PID file
PIDFILE=/tmp/zabbix_server.pid
# binary file
ZABBIX_SUCKERD=$BASEDIR/sbin/zabbix_server




# **************
# logic section (below here) does NOT normally need any modification
# **************


# establish args
ERROR=0
ARGV="$@"
if [ "x$ARGV" = "x" ] ; then 
    ARGS="help"
fi




# perform action based on args
for ARG in $@ $ARGS
do
# check if PIDFILE exists and ensure is not zero size and react accordingly
if [ -f $PIDFILE  ] && [ -s $PIDFILE ] ; then
   PID=`cat $PIDFILE`
if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
       STATUS="zabbix_server (pid $PID) running"
       RUNNING=1
   else
       STATUS="zabbix_server (pid $PID?) not running"
       RUNNING=0
   fi
    else
   STATUS="zabbix_server (no pid file) not running"
   RUNNING=0
    fi

# parse arg and react accordingly
    case $ARG in
    
start)
if [ $RUNNING -eq 1 ]; then
   echo "$0 $ARG: zabbix_server (pid $PID) already running"
   continue
fi
if $ZABBIX_SUCKERD ; then
   echo "$0 $ARG: zabbix_server started"
else
   echo "$0 $ARG: zabbix_server could not be started"
   ERROR=3
fi
;;
    
stop)
if [ $RUNNING -eq 0 ]; then
   echo "stop called - in running eq 0"
echo "$0 $ARG: $STATUS"
   continue
fi
if kill $PID ; then
echo "$0 $ARG: zabbix_server process(es) stopped"
   else
       echo "$0 $ARG: zabbix_server process(es) could not be stopped"
       ERROR=4
   fi
;;
    
restart)
if [ $RUNNING -eq 0 ]; then
   echo "$0 $ARG: zabbix_server not running, trying to start"
   if $ZABBIX_SUCKERD ; then
   echo "$0 $ARG: zabbix_server started"
   else
   echo "$0 $ARG: zabbix_server could not be started"
ERROR=5
   fi
else
   if kill $PID ; then
   if $ZABBIX_SUCKERD ; then
           echo "$0 $ARG: zabbix_server restarted"
else
echo "$0 $ARG: zabbix_server could not be started"
ERROR=3
fi
else
   echo "$0 $ARG: zabbix_server could not be restarted"
   ERROR=6
fi    
    fi
;;
    
*)             

echo "usage: $0 (start|stop|restart|help)"
cat <<EOF


start      - start zabbix_server
stop       - stop zabbix_server
restart    - restart zabbix_server if running by sending a SIGHUP or start if not running
help       - this screen


EOF


    ERROR=2
    ;;


    esac


done


exit $ERROR
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值