]> git.pld-linux.org Git - packages/cherokee.git/blame_incremental - cherokee.init
systemd unit added
[packages/cherokee.git] / cherokee.init
... / ...
CommitLineData
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
23 msg_network_down "Cherokee Web Server"
24 exit 1
25 fi
26else
27 exit 0
28fi
29
30# configtest itself
31# must return non-zero if check failed
32# output is discarded if checkconfig is ran without details
33configtest() {
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
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)
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
75start() {
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 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
89 fi
90}
91
92stop() {
93 if [ ! -f /var/lock/subsys/cherokee ]; then
94 msg_not_running "Cherokee Web Server"
95 return
96 fi
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
105}
106
107condrestart() {
108 if [ ! -f /var/lock/subsys/cherokee ]; then
109 msg_not_running "Cherokee Web Server"
110 RETVAL=$1
111 return
112 fi
113
114 checkconfig
115 stop
116 start
117}
118
119reload() {
120 if [ ! -f /var/lock/subsys/cherokee ]; then
121 msg_not_running "Cherokee Web Server"
122 RETVAL=7
123 fi
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
139}
140
141upstart_controlled --except configtest
142
143RETVAL=0
144# See how we were called.
145case "$1" in
146 start)
147 start
148 ;;
149 stop)
150 stop
151 ;;
152 restart)
153 checkconfig
154 stop
155 start
156 ;;
157 reload|force-reload)
158 reload $1
159 ;;
160 try-restart)
161 condrestart 0
162 ;;
163 checkconfig|configtest)
164 checkconfig 1
165 RETVAL=$?
166 ;;
167 status)
168 status cherokee
169 RETVAL=$?
170 ;;
171 *)
172 msg_usage "$0 {start|stop|restart|try-restart|force-reload|configtest|status}"
173 exit 3
174esac
175
176exit $RETVAL
This page took 0.024885 seconds and 4 git commands to generate.