#!/bin/sh
#
# chkconfig: 2345 20 80
# description: gmetad startup script
#
GMETAD=/usr/pkg/sbin/gmetad

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

test -f /usr/pkg/etc/sysconfig/gmetad && . /usr/pkg/etc/sysconfig/gmetad

export RRDCACHED_ADDRESS

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

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

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

rh_status() {
    status $GMETAD
}

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 $?
