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