]> git.pld-linux.org Git - packages/cherokee.git/blame - cherokee.init
drop all Upstart hacks
[packages/cherokee.git] / cherokee.init
CommitLineData
cf957d96
ER
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.
21if is_yes "${NETWORKING}"; then
22 if [ ! -f /var/lock/subsys/network ]; then
1f50c961 23 msg_network_down "Cherokee Web Server"
cf957d96
ER
24 exit 1
25 fi
26else
27 exit 0
28fi
29
2ee27799
ER
30# configtest itself
31# must return non-zero if check failed
32# output is discarded if checkconfig is ran without details
6f4ea149 33configtest() {
2ee27799 34 local test_result="$(/usr/sbin/cherokee -t 2>&1)"
6f4ea149
JK
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
2ee27799
ER
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
47checkconfig() {
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)
cf957d96 55 RETVAL=$?
2ee27799
ER
56 if [ $RETVAL = 0 ]; then
57 ok
58 else
59 fail
1f50c961 60 fi
2ee27799 61 [ "$out" ] && echo >&2 "$out"
cf957d96 62 else
2ee27799
ER
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
75start() {
76 # Check if the service is already running?
77 if [ -f /var/lock/subsys/cherokee ]; then
1f50c961 78 msg_already_running "Cherokee Web Server"
2ee27799
ER
79 return
80 fi
81
2ee27799
ER
82 msg_starting "Cherokee Web Server"
83 daemon cherokee -d
84 RETVAL=$?
85 if [ $RETVAL -eq 0 ]; then
86 touch /var/lock/subsys/cherokee
cf957d96 87 fi
9ad9ac92
ER
88}
89
90stop() {
2ee27799 91 if [ ! -f /var/lock/subsys/cherokee ]; then
1f50c961 92 msg_not_running "Cherokee Web Server"
2ee27799 93 return
cf957d96 94 fi
2ee27799
ER
95
96 # Stop daemons.
2ee27799
ER
97 msg_stopping "Cherokee Web Server"
98 killproc cherokee
99 RETVAL=$?
100 rm -f /var/lock/subsys/cherokee >/dev/null 2>&1
9ad9ac92
ER
101}
102
103condrestart() {
2ee27799 104 if [ ! -f /var/lock/subsys/cherokee ]; then
9ad9ac92
ER
105 msg_not_running "Cherokee Web Server"
106 RETVAL=$1
2ee27799 107 return
9ad9ac92 108 fi
2ee27799
ER
109
110 checkconfig
111 stop
112 start
9ad9ac92
ER
113}
114
6f4ea149 115reload() {
2ee27799 116 if [ ! -f /var/lock/subsys/cherokee ]; then
6f4ea149
JK
117 msg_not_running "Cherokee Web Server"
118 RETVAL=7
119 fi
2ee27799
ER
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
6f4ea149
JK
135}
136
9ad9ac92
ER
137RETVAL=0
138# See how we were called.
139case "$1" in
140 start)
2ee27799 141 start
cf957d96 142 ;;
9ad9ac92 143 stop)
2ee27799 144 stop
9ad9ac92
ER
145 ;;
146 restart)
2ee27799
ER
147 checkconfig
148 stop
149 start
6f4ea149
JK
150 ;;
151 reload|force-reload)
2ee27799 152 reload $1
9ad9ac92
ER
153 ;;
154 try-restart)
155 condrestart 0
156 ;;
2ee27799
ER
157 checkconfig|configtest)
158 checkconfig 1
cf957d96
ER
159 RETVAL=$?
160 ;;
2ee27799
ER
161 status)
162 status cherokee
6f4ea149
JK
163 RETVAL=$?
164 ;;
cf957d96 165 *)
2ee27799 166 msg_usage "$0 {start|stop|restart|try-restart|force-reload|configtest|status}"
cf957d96
ER
167 exit 3
168esac
169
170exit $RETVAL
This page took 0.083209 seconds and 4 git commands to generate.