#!/bin/sh
#
# guacd        This shell script takes care of starting and stopping the
#              Guacamole daemon
#
# chkconfig:   - 80 20
# description: Guacamole proxy daemon
# processname: guacd
# config:      /etc/sysconfig/guacd

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

RETVAL=0
prog="guacd"

# Source configuration.
if [ -f /etc/sysconfig/$prog ] ; then
        . /etc/sysconfig/$prog
fi

OPTS="$OPTS -p /var/run/$prog.pid"

start() {
        [ "$EUID" != "0" ] && exit 4

        echo -n "Starting $prog: "
        daemon $prog $OPTS
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        return $RETVAL
}

stop() {
        [ "$EUID" != "0" ] && exit 4

        echo -n "Shutting down $prog: "
        killproc $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
        return $RETVAL
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status $prog
}

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

case "$1" in
    start)
                start
                ;;
    stop)
                stop
                ;;
    status)
                rh_status
                ;;
    condrestart|try-restart)
                rh_status_q || exit 0
                restart
                ;;
    restart|force-reload)
                stop
                start
                ;;
    *)
        echo "Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|status}"
        [ "$1" = "usage" ] && exit 0
        exit 2
        ;;
esac
exit $?

