#!/bin/sh
#
### BEGIN INIT INFO
# Provides:       zabbix_web_service
# Required-Start: $network $syslog
# Required-Stop:
# Default-Start:
# Default-Stop:
# Description:    Starts Zabbix Web Service
### END INIT INFO

# zabbix_web_service	This script starts and stops zabbix_web_service service
#
# chkconfig: - 90 10
# description:	the Zabbix Web Service
# processname: zabbix_web_service
# config: /etc/zabbix/zabbix_web_service.conf
# pidfile: /run/zabbix/zabbix_web_service.pid


# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

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

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

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

restart()
{
	stop
	sleep 2
	start
}

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

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

check_rundir()
{
	if [ ! -d /run/zabbix ]; then
		mkdir -p -m 0775 /run/zabbix
		chown root:zabbix /run/zabbix
	fi
}

# 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
