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