#!/bin/sh

# chkconfig: 345 98 02

### BEGIN INIT INFO
# Provides:          puppet-dashboard
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: puppet-dashboard
# Description:       puppet web interface
### END INIT INFO

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

# Get network configuration
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

NAME=puppet-dashboard
LOCKFILE=/var/lock/subsys/$NAME
PIDFILE=/var/run/$NAME/server.pid
DAEMON=/usr/share/puppet-dashboard/script/server
USER=dashboard
ENVIRONMENT=production

# Read configuration variable file if it is present
[ -r /etc/sysconfig/puppet-dashboard ] && . /etc/sysconfig/puppet-dashboard

do_start() {
    gprintf "Starting %s: " "$NAME"
    daemon --pidfile $PIDFILE -u $USER \
	"$DAEMON -e $ENVIRONMENT --daemon >/dev/null 2>&1"
    rc=$?
    echo
    [ $rc -eq 0 ] && touch $LOCKFILE
}

do_stop() {
    gprintf "Stopping %s: " "$NAME"
    killproc -p $PIDFILE shinken-$module
    rc=$?
    echo
    [ $rc -eq 0 ] && rm -f $LOCKFILE $NAME
}

do_status() {
    status -p $PIDFILE $NAME
}

case "$1" in
    start)
        do_start
        ;;
    stop)
        do_stop
        ;;
    restart)
        do_stop
        do_start
        ;;
    condrestart)
	if [ -f $LOCKFILE ]; then
	    restart
	fi
	;;
    status)
        do_status
        ;;
    *)
        gprintf "Usage: %s {start|stop|restart|condrestart|status}\n" "$0"
        RETVAL=1
        ;;
esac

exit $RETVAL
