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