#!/bin/sh
#
# vgauthd - SAML token and ticketing authentication for VMware
#
# chkconfig:   - 81 19
# description: SAML token and ticketing authentication for VMware.

### BEGIN INIT INFO
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SAML token and ticketing authentication for VMware.
# Description: Service to support SAML token and ticketing authentication for
#              VMware products.
### END INIT INFO

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

exec="/usr/bin/VGAuthService"
prog=${exec##*/}

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog

start() {
    [ -x $exec ] || exit 5
    echo -n $"Starting $prog: "
    $exec -b --background=/var/run/vmware/vgauthsvclog_pid.txt 2>/dev/null 1>&2 && success || failure $"$prog start"
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

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)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    force-reload)
        restart
        ;;
    status)
        rh_status
        ;;
    try-restart|condrestart)
        rh_status_q || exit 0
        restart
	  ;;
    reload)
        action $"Service ${0##*/} does not support the reload action: " /bin/false
        exit 3
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
        exit 2
esac
exit $?
