#!/bin/sh
#
# chkconfig: 2345 70 40
# description: gmond startup script
#
GMOND=/usr/pkg/sbin/gmond

# TMPDIR set to SysV IPC ramdrive to avoid include processing failures
TMPDIR=/dev/shm
export TMPDIR

. /etc/rc.d/init.d/functions

start() {
    [ -x $GMOND ] || exit 5
    [ -f /usr/pkg/etc/ganglia/gmond.conf ] || exit 6
    echo -n "Starting GANGLIA gmond: "
    daemon $GMOND
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /usr/pkg/var/lock/subsys/gmond
    return $RETVAL
}

stop() {
    echo -n "Shutting down GANGLIA gmond: "
    killproc gmond
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /usr/pkg/var/lock/subsys/gmond
    return $RETVAL
}

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

rh_status() {
    status $GMOND
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

usage() {
    echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
}

case "$1" in
    start)
	rh_status_q && exit 0
	$1
	;;
    stop)
	rh_status_q || exit 1
	$1
	;;
    restart)
	$1
	;;
    reload)
	rh_status_q || exit 7
	$1
	;;
    force-reload)
	force_reload
	;;
    status)
	rh_status
	;;
    condrestart|try-restart)
	rh_status_q || exit 0
	restart
	;;
    usage)
	$1
	;;
    *)
	usage
	exit 2
esac
exit $?
