Don't need chown of new log dir, clean up some indents
[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-@ @-PKGCACHEDIR-@ 2>/dev/null || :
57         daemon --user $SHIBD_USER $shibd -p $pidfile -f -w 30
58
59         RETVAL=$?
60         echo
61                 [ $RETVAL -eq 0 ] && touch $lockfile
62         return $RETVAL
63 }
64
65 stop() {
66         echo -n $"Stopping $prog: "
67         killproc shibd
68
69         RETVAL=$?
70         echo
71         [ $RETVAL -eq 0 ] && rm -f $lockfile $pidfile
72         return $RETVAL
73 }
74
75 restart() {
76         stop
77         sleep 5
78         start
79 }
80
81 reload() {
82         restart
83 }
84
85 force_reload() {
86         restart
87 }
88
89 rh_status() {
90         # run checks to determine if the service is running or use generic status
91         status $prog
92 }
93
94 rh_status_q() {
95         rh_status >/dev/null 2>&1
96 }
97
98 case "$1" in
99         start)
100                 rh_status_q && exit 0
101                 $1
102                 ;;
103         stop)
104                 rh_status_q || exit 0
105                 $1
106                 ;;
107         restart)
108                 $1
109                 ;;
110         reload)
111                 rh_status_q || exit 7
112                 $1
113                 ;;
114         force-reload)
115                 force_reload
116                 ;;
117         status)
118                 rh_status
119                 ;;
120         condrestart|try-restart)
121                 rh_status_q || exit 0
122                 restart
123                 ;;
124         *)
125                 echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
126                 exit 2
127 esac
128
129 exit $?