]> git.pld-linux.org Git - packages/cherokee.git/blob - cherokee.init
rel 4
[packages/cherokee.git] / cherokee.init
1 #!/bin/sh
2 #
3 # cherokee      Start the cherokee HTTP server.
4 #
5 # chkconfig:    345 20 80
6 #
7 # description:  Cherokee is Fast, Flexible and Lightweight Web server
8 #
9
10 # Source function library
11 . /etc/rc.d/init.d/functions
12
13 # Get network config
14 . /etc/sysconfig/network
15
16 # Get service config - may override defaults
17 [ -f /etc/sysconfig/cherokee ] && . /etc/sysconfig/cherokee
18
19 # Check that networking is up.
20 if is_yes "${NETWORKING}"; then
21         if [ ! -f /var/lock/subsys/network ]; then
22                 msg_network_down "Cherokee Web Server"
23                 exit 1
24         fi
25 else
26         exit 0
27 fi
28
29 # configtest itself
30 # must return non-zero if check failed
31 # output is discarded if checkconfig is ran without details
32 configtest() {
33         local test_result="$(/usr/sbin/cherokee -t 2>&1)"
34         # exit status is not usable here, parse the output
35         if [ "${test_result##Test on*: }" = "OK" ] ; then
36                 return 0
37         else
38                 echo $test_result >&2
39                 return 1
40         fi
41 }
42
43 # wrapper for configtest
44 # with $details = 1 will report ok/fail status to output (status action)
45 # with $details = 0 will silently discard ok output, and with fail exit script with failure
46 checkconfig() {
47         local details=${1:-0}
48
49         if [ $details = 1 ]; then
50                 # run config test and display report (status action)
51                 show "Checking %s configuration" "Cherokee Web Server"; busy
52                 local out
53                 out=$(configtest 2>&1)
54                 RETVAL=$?
55                 if [ $RETVAL = 0 ]; then
56                         ok
57                 else
58                         fail
59                 fi
60                 [ "$out" ] && echo >&2 "$out"
61         else
62                 # run config test and abort with nice message if failed
63                 # (for actions checking status before action).
64                 configtest >/dev/null 2>&1
65                 RETVAL=$?
66                 if [ $RETVAL != 0 ]; then
67                         show "Checking %s configuration" "Cherokee Web Server"; fail
68                         nls 'Configuration test failed. See details with %s "checkconfig"' $0
69                         exit $RETVAL
70                 fi
71         fi
72 }
73
74 start() {
75         # Check if the service is already running?
76         if [ -f /var/lock/subsys/cherokee ]; then
77                 msg_already_running "Cherokee Web Server"
78                 return
79         fi
80
81         msg_starting "Cherokee Web Server"
82         daemon cherokee -d
83         RETVAL=$?
84         if [ $RETVAL -eq 0 ]; then
85                 touch /var/lock/subsys/cherokee
86         fi
87 }
88
89 stop() {
90         if [ ! -f /var/lock/subsys/cherokee ]; then
91                 msg_not_running "Cherokee Web Server"
92                 return
93         fi
94
95         # Stop daemons.
96         msg_stopping "Cherokee Web Server"
97         killproc cherokee
98         RETVAL=$?
99         rm -f /var/lock/subsys/cherokee >/dev/null 2>&1
100 }
101
102 condrestart() {
103         if [ ! -f /var/lock/subsys/cherokee ]; then
104                 msg_not_running "Cherokee Web Server"
105                 RETVAL=$1
106                 return
107         fi
108
109         checkconfig
110         stop
111         start
112 }
113
114 reload() {
115         if [ ! -f /var/lock/subsys/cherokee ]; then
116                 msg_not_running "Cherokee Web Server"
117                 RETVAL=7
118         fi
119
120         checkconfig
121         msg_reloading "Cherokee Web Server"
122         pid="$(pidofproc cherokee)"
123         if [ -n "$pid" ] && kill -HUP $(pidofproc cherokee); then
124                 ok
125         elif [ "$1" = "force-reload" ] ; then
126                 fail
127                 stop
128                 start
129                 RETVAL=$?
130         else
131                 fail
132                 RETVAL=1
133         fi
134 }
135
136 RETVAL=0
137 # See how we were called.
138 case "$1" in
139   start)
140         start
141         ;;
142   stop)
143         stop
144         ;;
145   restart)
146         checkconfig
147         stop
148         start
149         ;;
150   reload|force-reload)
151         reload $1
152         ;;
153   try-restart)
154         condrestart 0
155         ;;
156   checkconfig|configtest)
157         checkconfig 1
158         RETVAL=$?
159         ;;
160   status)
161         status cherokee
162         RETVAL=$?
163         ;;
164   *)
165         msg_usage "$0 {start|stop|restart|try-restart|force-reload|configtest|status}"
166         exit 3
167 esac
168
169 exit $RETVAL
This page took 0.092879 seconds and 3 git commands to generate.