https://issues.shibboleth.net/jira/browse/SSPCPP-353
[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 prog=shibd
16 pidfile=@-PKGRUNDIR-@/shibd.pid
17 lockfile=/var/lock/subsys/$prog
18
19 [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
20
21 start() {
22         echo -n $"Starting $prog: "
23         if [ -f $lockfile ] ; then
24                 if [ -f $pidfile ]; then
25                         read kpid < $pidfile
26                         if checkpid $kpid 2>&1; then
27                                 echo "process already running"
28                                         return 1;
29                                 else
30                                         echo "lock file found but no process running for pid $kpid, continuing"
31                         fi
32                 fi
33         fi
34
35         export SHIBD_PID=$pidfile
36         touch $pidfile
37         chown $SHIBD_USER:$SHIBD_USER $pidfile
38         if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
39                 /sbin/restorecon $pidfile
40         fi
41         # Handle transition from root to non-root packages.
42         chown $SHIBD_USER:$SHIBD_USER @-PKGRUNDIR-@/* 2>/dev/null || :
43         daemon --user $SHIBD_USER $shibd -p $pidfile -f -w 30
44
45         RETVAL=$?
46         echo
47                 [ $RETVAL -eq 0 ] && touch $lockfile
48         return $RETVAL
49 }
50
51 stop() {
52         echo -n $"Stopping $prog: "
53         killproc shibd
54
55         RETVAL=$?
56         echo
57         [ $RETVAL -eq 0 ] && rm -f $lockfile $pidfile
58         return $RETVAL
59 }
60
61 restart() {
62         stop
63         sleep 5
64         start
65 }
66
67 reload() {
68         restart
69 }
70
71 force_reload() {
72         restart
73 }
74
75 rh_status() {
76         # run checks to determine if the service is running or use generic status
77         status $prog
78 }
79
80 rh_status_q() {
81         rh_status >/dev/null 2>&1
82 }
83
84 case "$1" in
85         start)
86                 rh_status_q && exit 0
87                 $1
88                 ;;
89         stop)
90                 rh_status_q || exit 0
91                 $1
92                 ;;
93         restart)
94                 $1
95                 ;;
96         reload)
97                 rh_status_q || exit 7
98                 $1
99                 ;;
100         force-reload)
101                 force_reload
102                 ;;
103         status)
104                 rh_status
105                 ;;
106         condrestart|try-restart)
107                 rh_status_q || exit 0
108                 restart
109                 ;;
110         *)
111                 echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
112                 exit 2
113 esac
114
115 exit $?