#! /bin/sh
#
# /etc/init.d/shibboleth-sp for Solaris
#
# start/stop script for Shibboleth ServiceProvider 1.3 daemon 
#
# Created: 20050602 - Valery Tschopp - SWITCH
# Modified for Solaris: 20050916 - Dominique Petitpierre at adm.unige.ch
#
# HOWTO INSTALL: 
# cp shibboleth-sp /etc/init.d/shibboleth-sp
# chmod u+x /etc/init.d/shibboleth-sp
# ln -s ../init.d/shibboleth-sp /etc/rcS.d/K28shibboleth-sp
# ln -s ../init.d/shibboleth-sp /etc/rc0.d/K28shibboleth-sp
# ln -s ../init.d/shibboleth-sp /etc/rc1.d/K28shibboleth-sp
# ln -s ../init.d/shibboleth-sp /etc/rc2.d/K28shibboleth-sp
# ln -s ../init.d/shibboleth-sp /etc/rc3.d/S15shibboleth-sp
#  

PATH=/bin:/usr/bin:/sbin:/usr/sbin

#
# Shibboleth 1.3
#
SHIB_HOME=/opt/shibboleth-1.3
SHIB_ETC=/etc/shibboleth

SHIB_CONFIG=$SHIB_ETC/shibboleth.xml

LD_LIBRARY_PATH=$SHIB_HOME/lib

NAME=shibd
DAEMON=$SHIB_HOME/sbin/$NAME
DESC="Shibboleth 1.3 SP Daemon"

if [ ! -x $DAEMON -o ! -f $SHIB_CONFIG ] ; then
   exit
fi

case "$1" in
  start)
    if pgrep -x $NAME  >/dev/null ; then 
       echo "$DESC: $NAME is already running"
        else
        echo "Starting $DESC: $NAME"
        $DAEMON -fc $SHIB_CONFIG &
        sleep 1
        if pgrep -x $NAME >/dev/null ; then
           :
        else
           echo "$DESC: $NAME has not started"
        fi
        fi  
    ;;
  stop)
    if pgrep -x $NAME >/dev/null ; then
        echo "Stopping $DESC: $NAME"
        pkill -x $NAME
        sleep 1;
        if pgrep -x $NAME >/dev/null ; then
           echo "$DESC: $NAME has not stopped"
        fi
    else
       echo "$DESC: $NAME is not running"
        fi
    ;;
  restart)
        if $DAEMON -tc $SHIB_CONFIG >/dev/null 2>&1 ; then
        # Restart
        $0 stop
        $0 start
    else
       echo "$DESC: $NAME configuration broken, not restarting"
        fi
    ;;
  configtest)
    echo "Checking config for $DESC: $NAME"
    $DAEMON -tc $SHIB_CONFIG
    echo "Done."
    ;;
  *)
    echo "Usage: - $0 {start|stop|restart|configtest}" >&2
    exit 1
    ;;
esac

exit 0