https://issues.shibboleth.net/jira/browse/SSPCPP-411
[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         # Make sure package run directory exists.
36         [ -d @-PKGRUNDIR-@ ] || mkdir @-PKGRUNDIR-@
37
38         export SHIBD_PID=$pidfile
39         touch $pidfile
40         chown $SHIBD_USER:$SHIBD_USER $pidfile
41         if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
42                 /sbin/restorecon $pidfile
43         fi
44         # Handle transition from root to non-root packages.
45         chown -R $SHIBD_USER:$SHIBD_USER @-PKGRUNDIR-@ 2>/dev/null || :
46         daemon --user $SHIBD_USER $shibd -p $pidfile -f -w 30
47
48         RETVAL=$?
49         echo
50                 [ $RETVAL -eq 0 ] && touch $lockfile
51         return $RETVAL
52 }
53
54 stop() {
55         echo -n $"Stopping $prog: "
56         killproc shibd
57
58         RETVAL=$?
59         echo
60         [ $RETVAL -eq 0 ] && rm -f $lockfile $pidfile
61         return $RETVAL
62 }
63
64 restart() {
65         stop
66         sleep 5
67         start
68 }
69
70 reload() {
71         restart
72 }
73
74 force_reload() {
75         restart
76 }
77
78 rh_status() {
79         # run checks to determine if the service is running or use generic status
80         status $prog
81 }
82
83 rh_status_q() {
84         rh_status >/dev/null 2>&1
85 }
86
87 case "$1" in
88         start)
89                 rh_status_q && exit 0
90                 $1
91                 ;;
92         stop)
93                 rh_status_q || exit 0
94                 $1
95                 ;;
96         restart)
97                 $1
98                 ;;
99         reload)
100                 rh_status_q || exit 7
101                 $1
102                 ;;
103         force-reload)
104                 force_reload
105                 ;;
106         status)
107                 rh_status
108                 ;;
109         condrestart|try-restart)
110                 rh_status_q || exit 0
111                 restart
112                 ;;
113         *)
114                 echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
115                 exit 2
116 esac
117
118 exit $?