#!/bin/sh
#
# chkconfig: 234 80 30
# description: zabbix agent
# zabbix_agentd_ctl 
#
# Modified to work more like the apache restart
#
#
#
. /etc/rc.d/init.d/functions
# **************
# config options
# **************
#
# (set config options to match your system settings) 

# base zabbix dir
BASEDIR=/opt/zabbix
# pid file (as of 1.0 beta 10)
PIDFILE=$BASEDIR/var/run/zabbix_agentd.pid
# Config File
CONFIG_FILE=$BASEDIR/etc/zabbix_agentd.conf
# binary file
prog=zabbix_agent
ZABBIX_AGENT="$BASEDIR/sbin/zabbix_agentd"
#ZABBIX_AGENTD="$ZABBIX_AGENT -c $CONFIG_FILE"
OPTIONS="-c $CONFIG_FILE"
lockfile=${LOCKFILE-/var/lock/subsys/zabbix_agent}


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

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

stop() {
        echo -n $"Stopping $prog: "
        killproc -p $PIDFILE -d 3 $ZABBIX_AGENT
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
start() {
        echo -n $"Starting $prog: "
        daemon --pidfile=${PIDFILE} $ZABBIX_AGENT $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# perform action based on args
for ARG in $@ $ARGS
do
    case $ARG in
    
  start)
  start;
  ;;
    
  stop)
  stop;
  ;;
    
  restart)
  stop;
  start;
  ;;

  status)
  status -p $PIDFILE $ZABBIX_AGENT
        RETVAL=$?
  ;;
    
  *)             
  
  echo "usage: $0 (start|stop|restart|status|help)"
  cat <<EOF

start      - start zabbix_agentd
stop       - stop zabbix_agentd
restart    - restart zabbix_agentd if running by sending a SIGHUP or start if not running
status     - check to see if zabbix_agent is running
help       - this screen

EOF

    ERROR=2
    ;;

    esac

done

exit $ERROR
