]> git.pld-linux.org Git - packages/cherokee.git/blame - cherokee.init
- Release: 2
[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
82 emit starting JOB=cherokee SERVICE=web-server
83 msg_starting "Cherokee Web Server"
84 daemon cherokee -d
85 RETVAL=$?
86 if [ $RETVAL -eq 0 ]; then
87 touch /var/lock/subsys/cherokee
88 emit --no-wait started JOB=cherokee SERVICE=web-server
cf957d96 89 fi
9ad9ac92
ER
90}
91
92stop() {
2ee27799 93 if [ ! -f /var/lock/subsys/cherokee ]; then
1f50c961 94 msg_not_running "Cherokee Web Server"
2ee27799 95 return
cf957d96 96 fi
2ee27799
ER
97
98 # Stop daemons.
99 emit stopping JOB=cherokee SERVICE=web-server
100 msg_stopping "Cherokee Web Server"
101 killproc cherokee
102 RETVAL=$?
103 rm -f /var/lock/subsys/cherokee >/dev/null 2>&1
104 emit --no-wait stopped JOB=cherokee SERVICE=web-server
9ad9ac92
ER
105}
106
107condrestart() {
2ee27799 108 if [ ! -f /var/lock/subsys/cherokee ]; then
9ad9ac92
ER
109 msg_not_running "Cherokee Web Server"
110 RETVAL=$1
2ee27799 111 return
9ad9ac92 112 fi
2ee27799
ER
113
114 checkconfig
115 stop
116 start
9ad9ac92
ER
117}
118
6f4ea149 119reload() {
2ee27799 120 if [ ! -f /var/lock/subsys/cherokee ]; then
6f4ea149
JK
121 msg_not_running "Cherokee Web Server"
122 RETVAL=7
123 fi
2ee27799
ER
124
125 checkconfig
126 msg_reloading "Cherokee Web Server"
127 pid="$(pidofproc cherokee)"
128 if [ -n "$pid" ] && kill -HUP $(pidofproc cherokee); then
129 ok
130 elif [ "$1" = "force-reload" ] ; then
131 fail
132 stop
133 start
134 RETVAL=$?
135 else
136 fail
137 RETVAL=1
138 fi
6f4ea149
JK
139}
140
ac2feb08
JK
141upstart_controlled --except configtest
142
9ad9ac92
ER
143RETVAL=0
144# See how we were called.
145case "$1" in
146 start)
2ee27799 147 start
cf957d96 148 ;;
9ad9ac92 149 stop)
2ee27799 150 stop
9ad9ac92
ER
151 ;;
152 restart)
2ee27799
ER
153 checkconfig
154 stop
155 start
6f4ea149
JK
156 ;;
157 reload|force-reload)
2ee27799 158 reload $1
9ad9ac92
ER
159 ;;
160 try-restart)
161 condrestart 0
162 ;;
2ee27799
ER
163 checkconfig|configtest)
164 checkconfig 1
cf957d96
ER
165 RETVAL=$?
166 ;;
2ee27799
ER
167 status)
168 status cherokee
6f4ea149
JK
169 RETVAL=$?
170 ;;
cf957d96 171 *)
2ee27799 172 msg_usage "$0 {start|stop|restart|try-restart|force-reload|configtest|status}"
cf957d96
ER
173 exit 3
174esac
175
176exit $RETVAL
This page took 0.175984 seconds and 4 git commands to generate.