#!/bin/sh
#
# zabbix_server	This script starts and stops zabbix service
#
# chkconfig: - 90 10
# description:	the zabbix network monitor server
# processname: zabbix_mysql
# config: /etc/zabbix/zabbix_server.conf
# pidfile: /var/run/zabbix/zabbix_server.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

PIDFILE=/var/run/zabbix/zabbix_server.pid
LOCKFILE=/var/lock/subsys/zabbix
RETVAL=0

start()
{
	get_status >/dev/null
	if [ $RETVAL -eq 1 ]; then
		echo "Removing stale pidfile"
		rm -f "$PIDFILE"
	fi
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --name zabbix_mysql \
	--expect-user zabbix -- zabbix_mysql
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user zabbix -- zabbix_mysql
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading template
	stop_daemon --pidfile "$PIDFILE" --expect-user zabbix -HUP -- zabbix_mysql
	RETVAL=$?
	return $RETVAL
} 

get_status()
{
	status --pidfile "$PIDFILE" --expect-user zabbix -- zabbix_mysql
	RETVAL=$?
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		get_status
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
