https://issues.shibboleth.net/jira/browse/SSPCPP-353
[shibboleth/cpp-sp.git] / configs / shibd-redhat.in
1 #!/bin/bash
2 #
3 # Startup script for the Shibboleth Service Provider Daemon
4 #
5 # chkconfig: - 98 02
6 # description: Shibboleth 2 Service Provider Daemon
7 # processname: shibd
8 # pidfile: @-PKGRUNDIR-@/shibd.pid
9 # config: @-PKGSYSCONFDIR-@/shibboleth2.xml
10
11 # Source function library.
12 . /etc/rc.d/init.d/functions
13 shibd="@-PREFIX-@/sbin/shibd"
14 SHIBD_USER=root
15 pidfile=@-PKGRUNDIR-@/shibd.pid
16 prog=shibd
17 #VER=`cat /etc/redhat-release | awk '{print $3}' | awk -F . '{print $1}'`
18 RETVAL=0
19
20 if [ -f /etc/sysconfig/shibd ] ; then
21     . /etc/sysconfig/shibd
22 fi
23
24 start() {
25         echo -n $"Starting $prog: "
26         if [ -f /var/lock/subsys/shibd ] ; then
27                 if [ -f $pidfile ]; then
28                         read kpid < $pidfile
29                         if checkpid $kpid 2>&1; then
30                                 echo "process already running"
31                                         return -1
32                                 else
33                                         echo "lock file found but no process running for pid $kpid, continuing"
34                         fi
35                 fi
36         fi
37
38 #_RHEL6_        export LD_LIBRARY_PATH=/opt/shibboleth/lib:$LD_LIBRARY_PATH
39         export SHIBD_PID=$pidfile
40         touch $pidfile
41         chown $SHIBD_USER:$SHIBD_USER $pidfile
42         if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
43                 /sbin/restorecon $pidfile
44         fi
45         # Handle transition from root to non-root packages.
46         chown $SHIBD_USER:$SHIBD_USER @-PKGRUNDIR-@/*
47         daemon --user $SHIBD_USER $shibd -p $pidfile -f -w 30
48
49         RETVAL=$?
50         echo
51                 [ $RETVAL = 0 ] && touch /var/lock/subsys/shibd
52         return $RETVAL
53 }
54
55 stop() {
56         echo -n $"Stopping $prog: "
57         killproc shibd
58
59         RETVAL=$?
60         echo
61         [ $RETVAL = 0 ] && rm -f /var/lock/subsys/shibd $pidfile
62 }
63
64 # See how we were called.
65 case "$1" in
66   start)
67         start
68         ;;
69   stop)
70         stop
71         ;;
72   status)
73         status $shibd
74         RETVAL=$?
75         ;;
76   restart)
77         stop
78         sleep 5
79         start
80         ;;
81   *)
82         echo $"Usage: $prog {start|stop|status|restart}"
83         exit 1
84 esac
85
86 exit $RETVAL