#! /bin/sh
# Copyright (c) 1995-2006 SUSE Linux Products GmbH, Nuernberg, Germany.
# All rights reserved.
#
# Author: Thomas Siedentopf
# Please send feedback to http://www.suse.de/feedback/
#
# /etc/init.d/nagiosgrapher
#   and its symbolic link
# /(usr/)sbin/nagiosgrapher
#
### BEGIN INIT INFO
# Provides:          nagiosgrapher
# Required-Start:    $local_fs $syslog
# X-UnitedLinux-Should-Start: nagios
# Required-Stop:     $local_fs $syslog
# X-UnitedLinux-Should-Stop: nagios
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: nagiosgrapher daemon
# Description:       start the nagiosgrapher daemon
### END INIT INFO

# Check for missing binaries (stale symlinks should not happen)
nagiosgrapher_BIN=/usr/lib/nagios/contrib/collect2.pl
test -x $nagiosgrapher_BIN || { echo "$nagiosgrapher_BIN not installed"; exit 5; }

# Check for existence of needed config file
nagiosgrapher_CONFIG=/etc/nagios/ngraph.ncfg
test -r $nagiosgrapher_CONFIG || { echo "$nagiosgrapher_CONFIG not existing"; exit 6; }

# Source LSB init functions
. /etc/rc.status

# Reset status of this service
rc_reset

case "$1" in
    start)
	echo -n "Starting nagiosgrapher "
	startproc $nagiosgrapher_BIN
	rc_status -v
	;;
    stop)
	echo -n "Shutting down nagiosgrapher "
	killproc -TERM $nagiosgrapher_BIN
	rc_status -v
	;;
    try-restart|condrestart)
	if test "$1" = "condrestart"; then
		echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
	fi
	$0 status
	if test $? = 0; then
		$0 restart
	else
		rc_reset	# Not running is not a failure.
	fi
	rc_status
	;;
    restart)
	$0 stop
	$0 start
	rc_status
	;;
    status)
	echo -n "Checking for service nagiosgrapher "
	checkproc $nagiosgrapher_BIN
	rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart}"
	exit 1
	;;
esac
rc_exit
