SSPCPP-654 - Move fork wait timeout from init script to sysconfig
[shibboleth/cpp-sp.git] / configs / shibd-amazon.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 SHIBD_UMASK=022
29 SHIBD_WAIT=30
30 prog=shibd
31 pidfile=@-PKGRUNDIR-@/shibd.pid
32 lockfile=/var/lock/subsys/$prog
33
34 [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
35
36 umask $SHIBD_UMASK
37
38 start() {
39         echo -n $"Starting $prog: "
40         if [ -f $lockfile ] ; then
41                 if [ -f $pidfile ]; then
42                         read kpid < $pidfile
43                         if checkpid $kpid 2>&1; then
44                                 echo "process already running"
45                                         return 1;
46                                 else
47                                         echo "lock file found but no process running for pid $kpid, continuing"
48                         fi
49                 fi
50         fi
51
52         # Make sure package run directory exists.
53         [ -d @-PKGRUNDIR-@ ] || mkdir @-PKGRUNDIR-@
54
55         export SHIBD_PID=$pidfile
56         touch $pidfile
57         chown $SHIBD_USER:$SHIBD_USER $pidfile
58
59         # Handle transition from root to non-root packages.
60         chown -R $SHIBD_USER:$SHIBD_USER @-PKGRUNDIR-@ @-PKGCACHEDIR-@ 2>/dev/null || :
61         daemon --user $SHIBD_USER $shibd -p $pidfile -f -w $SHIBD_WAIT
62
63         RETVAL=$?
64         echo
65                 [ $RETVAL -eq 0 ] && touch $lockfile
66         return $RETVAL
67 }
68
69 stop() {
70         echo -n $"Stopping $prog: "
71         killproc shibd
72
73         RETVAL=$?
74         echo
75         [ $RETVAL -eq 0 ] && rm -f $lockfile $pidfile
76         return $RETVAL
77 }
78
79 restart() {
80         stop
81         sleep 5
82         start
83 }
84
85 reload() {
86         restart
87 }
88
89 force_reload() {
90         restart
91 }
92
93 rh_status() {
94         # run checks to determine if the service is running or use generic status
95         status $prog
96 }
97
98 rh_status_q() {
99         rh_status >/dev/null 2>&1
100 }
101
102 case "$1" in
103         start)
104                 rh_status_q && exit 0
105                 $1
106                 ;;
107         stop)
108                 rh_status_q || exit 0
109                 $1
110                 ;;
111         restart)
112                 $1
113                 ;;
114         reload)
115                 rh_status_q || exit 7
116                 $1
117                 ;;
118         force-reload)
119                 force_reload
120                 ;;
121         status)
122                 rh_status
123                 ;;
124         condrestart|try-restart)
125                 rh_status_q || exit 0
126                 restart
127                 ;;
128         *)
129                 echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
130                 exit 2
131 esac
132
133 exit $?