#!/bin/sh
#PKG icinga
#INIT 80
. /etc/rc.conf

case $1 in
autostop) ;;
autostart)
	test x"${icinga:-NO}" = x"NO" && exit 0
	exec sh $0 start
	;;
start)
	[ -d /var/run/icinga ] || mkdir -p /var/run/icinga
	[ -d /var/rw ] || mkdir -p /var/rw
	[ -d /var/spool/checkresults ] || mkdir -p /var/spool/checkresults
	touch /var/log/icinga.log
	chown icinga:icinga /var/log/icinga.log
	chown icinga:icinga /var/run/icinga
	chown icinga:icinga /var/spool/checkresults
	chown icinga:icinga /var/rw
	icinga -d /etc/icinga/icinga.cfg
	;;
stop)
	kill $(pgrep -f icinga)
	;;
restart)
	sh $0 stop
	sh $0 start
	;;
*)
	echo "Usage: $0 {start | stop | restart}"
	exit 1
	;;
esac
exit $?
