https://issues.shibboleth.net/jira/browse/SSPCPP-247
[shibboleth/cpp-sp.git] / configs / shibd-redhat.in
index 059e3d5..7ffb186 100644 (file)
@@ -3,17 +3,18 @@
 # Startup script for the Shibboleth Service Provider Daemon
 #
 # chkconfig: - 98 02
-# description: Shibboleth Service Provider Daemon
+# description: Shibboleth Service Provider Daemon
 # processname: shibd
-# pidfile: @-VARRUNDIR-@/shibd.pid
-# config: @-PKGSYSCONFDIR-@/shibboleth.xml
+# pidfile: @-PKGRUNDIR-@/shibd.pid
+# config: @-PKGSYSCONFDIR-@/shibboleth2.xml
 
 # Source function library.
 . /etc/rc.d/init.d/functions
 shibd="@-PREFIX-@/sbin/shibd"
 SHIBD_USER=root
-pidfile=@-VARRUNDIR-@/shibd.pid
+pidfile=@-PKGRUNDIR-@/shibd.pid
 prog=shibd
+VER=`cat /etc/redhat-release | awk '{print $3}' | awk -F . '{print $1}'`
 RETVAL=0
 
 start() {
@@ -24,7 +25,7 @@ start() {
                        if checkpid $kpid 2>&1; then
                                echo "process already running"
                                        return -1
-                       else
+                               else
                                        echo "lock file found but no process running for pid $kpid, continuing"
                        fi
                fi
@@ -33,8 +34,14 @@ start() {
        export SHIBD_PID=$pidfile
        touch $pidfile
        chown $SHIBD_USER:$SHIBD_USER $pidfile
-       # daemon function just hangs, so I'm using su directly
-       su - $SHIBD_USER -c "$shibd -p $pidfile -f &"
+       if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
+               /sbin/restorecon $pidfile
+       fi
+       if [ 5 -le $VER ] ; then
+               daemon --user $SHIBD_USER --pidfile $pidfile $shibd -p $pidfile -f -w 30
+       else
+               daemon --user $SHIBD_USER $shibd -p $pidfile -f -w 30
+       fi
 
        RETVAL=$?
        echo
@@ -44,11 +51,10 @@ start() {
 
 stop() {
        echo -n $"Stopping $prog: "
-       if [ -f $pidfile ]; then
-               read kpid < $pidfile
-               kill $kpid
+       if [ -f $pidfile -a 5 -le $VER] ; then
+               killproc -p $pidfile shibd
        else
-           killproc shibd
+               killproc shibd
        fi
 
        RETVAL=$?
@@ -65,7 +71,7 @@ case "$1" in
        stop
        ;;
   status)
-        status $shibd
+       status $shibd
        RETVAL=$?
        ;;
   restart)
@@ -74,7 +80,7 @@ case "$1" in
        start
        ;;
   *)
-       echo $"Usage: $prog {start|stop|restart}"
+       echo $"Usage: $prog {start|stop|status|restart}"
        exit 1
 esac