https://issues.shibboleth.net/jira/browse/SSPCPP-646
[shibboleth/cpp-sp.git] / configs / shibd-redhat.in
1 #!/bin/bash
2 #
3 # shibd Shibboleth Service Provider Daemon
4 #
5 # chkconfig: - 80 20
6 # description: Shibboleth 2 Service Provider Daemon
7 # processname: shibd
8 # pidfile: @-PKGRUNDIR-@/shibd.pid
9 # config: @-PKGSYSCONFDIR-@/shibboleth2.xml
10
11 ### BEGIN INIT INFO
12 # Provides: shibd
13 # Required-Start: $local_fs $remote_fs $network
14 # Should-Start: $time
15 # Should-Stop: $time
16 # Required-Stop: $local_fs $remote_fs $network
17 # Default-Start: 3 5
18 # Default-Stop: 0 1 2 6 
19 # Short-Description: Shibboleth 2 Service Provider Daemon
20 # Description: Starts the separate daemon used by the Shibboleth Apache module to manage state and SAML interactions.
21 ### END INIT INFO
22
23 # Source function library.
24 . /etc/rc.d/init.d/functions
25
26 shibd="@-PREFIX-@/sbin/shibd"
27 SHIBD_USER=root
28 prog=shibd
29 pidfile=@-PKGRUNDIR-@/shibd.pid
30 lockfile=/var/lock/subsys/$prog
31
32 [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
33
34 start() {
35         echo -n $"Starting $prog: "
36         if [ -f $lockfile ] ; then
37                 if [ -f $pidfile ]; then
38                         read kpid < $pidfile
39                         if checkpid $kpid 2>&1; then
40                                 echo "process already running"
41                                         return 1;
42                                 else
43                                         echo "lock file found but no process running for pid $kpid, continuing"
44                         fi
45                 fi
46         fi
47
48         # Make sure package run directory exists.
49         [ -d @-PKGRUNDIR-@ ] || mkdir @-PKGRUNDIR-@
50
51         export SHIBD_PID=$pidfile
52         touch $pidfile
53         chown $SHIBD_USER:$SHIBD_USER $pidfile
54
55         # Handle transition from root to non-root packages.
56         chown -R $SHIBD_USER:$SHIBD_USER @-PKGRUNDIR-@ 2>/dev/null || :
57         daemon --user $SHIBD_USER $shibd -p $pidfile -f -w 30
58
59     # Adjust native logging directory permission so log roll-over works
60     chown apache:apache @-SHIRELOGDIR-@
61
62         RETVAL=$?
63         echo
64                 [ $RETVAL -eq 0 ] && touch $lockfile
65         return $RETVAL
66 }
67
68 stop() {
69         echo -n $"Stopping $prog: "
70         killproc shibd
71
72         RETVAL=$?
73         echo
74         [ $RETVAL -eq 0 ] && rm -f $lockfile $pidfile
75         return $RETVAL
76 }
77
78 restart() {
79         stop
80         sleep 5
81         start
82 }
83
84 reload() {
85         restart
86 }
87
88 force_reload() {
89         restart
90 }
91
92 rh_status() {
93         # run checks to determine if the service is running or use generic status
94         status $prog
95 }
96
97 rh_status_q() {
98         rh_status >/dev/null 2>&1
99 }
100
101 case "$1" in
102         start)
103                 rh_status_q && exit 0
104                 $1
105                 ;;
106         stop)
107                 rh_status_q || exit 0
108                 $1
109                 ;;
110         restart)
111                 $1
112                 ;;
113         reload)
114                 rh_status_q || exit 7
115                 $1
116                 ;;
117         force-reload)
118                 force_reload
119                 ;;
120         status)
121                 rh_status
122                 ;;
123         condrestart|try-restart)
124                 rh_status_q || exit 0
125                 restart
126                 ;;
127         *)
128                 echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
129                 exit 2
130 esac
131
132 exit $?