https://issues.shibboleth.net/jira/browse/SSPCPP-247
[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 start() {
21         echo -n $"Starting $prog: "
22         if [ -f /var/lock/subsys/shibd ] ; then
23                 if [ -f $pidfile ]; then
24                         read kpid < $pidfile
25                         if checkpid $kpid 2>&1; then
26                                 echo "process already running"
27                                         return -1
28                                 else
29                                         echo "lock file found but no process running for pid $kpid, continuing"
30                         fi
31                 fi
32         fi
33  
34         export SHIBD_PID=$pidfile
35         touch $pidfile
36         chown $SHIBD_USER:$SHIBD_USER $pidfile
37         if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
38                 /sbin/restorecon $pidfile
39         fi
40         if [ 5 -le $VER ] ; then
41                 daemon --user $SHIBD_USER --pidfile $pidfile $shibd -p $pidfile -f -w 30
42         else
43                 daemon --user $SHIBD_USER $shibd -p $pidfile -f -w 30
44         fi
45
46         RETVAL=$?
47         echo
48                 [ $RETVAL = 0 ] && touch /var/lock/subsys/shibd
49         return $RETVAL
50 }
51
52 stop() {
53         echo -n $"Stopping $prog: "
54         if [ -f $pidfile -a 5 -le $VER] ; then
55                 killproc -p $pidfile shibd
56         else
57                 killproc shibd
58         fi
59
60         RETVAL=$?
61         echo
62         [ $RETVAL = 0 ] && rm -f /var/lock/subsys/shibd $pidfile
63 }
64
65 # See how we were called.
66 case "$1" in
67   start)
68         start
69         ;;
70   stop)
71         stop
72         ;;
73   status)
74         status $shibd
75         RETVAL=$?
76         ;;
77   restart)
78         stop
79         sleep 5
80         start
81         ;;
82   *)
83         echo $"Usage: $prog {start|stop|status|restart}"
84         exit 1
85 esac
86
87 exit $RETVAL