]>
Commit | Line | Data |
---|---|---|
cb1656fe AM |
1 | #!/bin/sh |
2 | # | |
3 | # lighttpd lighttpd Web Server | |
4 | # | |
5 | # chkconfig: 345 85 15 | |
6 | # description: lighttpd is a World Wide Web server. It is used to serve \ | |
7 | # HTML files and CGI. | |
8 | # | |
9 | ||
10 | # Source function library | |
11 | . /etc/rc.d/init.d/functions | |
12 | ||
f6bfb2a7 ER |
13 | upstart_controlled |
14 | ||
cb1656fe AM |
15 | # Get network config |
16 | . /etc/sysconfig/network | |
17 | ||
18 | # Get service config | |
19 | [ -f /etc/sysconfig/lighttpd ] && . /etc/sysconfig/lighttpd | |
20 | ||
8f80a943 ER |
21 | DAEMON=/usr/sbin/lighttpd |
22 | ANGEL_DAEMON=/usr/sbin/lighttpd-angel | |
e4eb660d ER |
23 | CONFIGFILE=/etc/lighttpd/lighttpd.conf |
24 | ||
cb1656fe AM |
25 | # Check that networking is up. |
26 | if is_yes "${NETWORKING}"; then | |
27 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then | |
75526508 | 28 | msg_network_down "Lighttpd Web Server" |
cb1656fe AM |
29 | exit 1 |
30 | fi | |
31 | else | |
32 | exit 0 | |
33 | fi | |
34 | ||
1ae7ff0d | 35 | configtest() { |
0ba2e99c ER |
36 | # check for deprecated config options that cause bad side effects |
37 | # TODO: should remove the deprecated options in pld after some time being warned out | |
38 | local out | |
39 | out=$(env SHELL=/bin/sh $DAEMON -f $CONFIGFILE $HTTPD_OPTS -p 2>&1 | grep -oE '(url.rewrite|url.rewrite-final)[[:space:]]') | |
40 | if [ -n "$out" ]; then | |
41 | # make it unique, format nicely | |
42 | out=$(echo "$out" | sort -u | xargs | sed -e 's/ /, /g') | |
eda1edc6 | 43 | echo >&2 "WARNING: found deprecated '$out', convert to 'url.rewrite-once' recommended, See https://redmine.lighttpd.net/issues/2379" |
0ba2e99c ER |
44 | fi |
45 | ||
8f80a943 | 46 | env SHELL=/bin/sh $DAEMON -t -f $CONFIGFILE $HTTPD_OPTS |
5be0ba14 ER |
47 | } |
48 | ||
49 | # wrapper for configtest | |
50 | checkconfig() { | |
51 | local details=${1:-0} | |
52 | ||
53 | if [ $details = 1 ]; then | |
54 | # run config test and display report (status action) | |
55 | show "Checking %s configuration" "Lighttpd Web Server"; busy | |
56 | local out | |
8f80a943 | 57 | out=$(configtest 2>&1) |
5be0ba14 ER |
58 | RETVAL=$? |
59 | if [ $RETVAL = 0 ]; then | |
60 | ok | |
61 | else | |
62 | fail | |
63 | fi | |
64 | [ "$out" ] && echo >&2 "$out" | |
65 | else | |
66 | # run config test and abort with nice message if failed | |
67 | # (for actions checking status before action). | |
68 | configtest >/dev/null 2>&1 | |
69 | RETVAL=$? | |
70 | if [ $RETVAL != 0 ]; then | |
71 | show "Checking %s configuration" "Lighttpd Web Server"; fail | |
72 | nls 'Configuration test failed. See details with %s "checkconfig"' $0 | |
73 | exit $RETVAL | |
74 | fi | |
1ae7ff0d | 75 | fi |
1ae7ff0d ER |
76 | } |
77 | ||
29afef3d | 78 | start() { |
5be0ba14 ER |
79 | # Check if the service is already running? |
80 | if [ -f /var/lock/subsys/lighttpd ]; then | |
81 | msg_already_running "Lighttpd Web Server" | |
82 | return | |
83 | fi | |
84 | ||
85 | checkconfig | |
86 | msg_starting "Lighttpd Web Server"; busy | |
61fdfa32 PG |
87 | if is_yes "${LIGHT_ANGEL}"; then |
88 | daemon --fork --pidfile /var/run/lighttpd-angel.pid --makepid \ | |
8f80a943 | 89 | env SHELL=/bin/sh $ANGEL_DAEMON -D -f $CONFIGFILE $HTTPD_OPTS |
61fdfa32 PG |
90 | |
91 | else | |
8f80a943 | 92 | env SHELL=/bin/sh $DAEMON -f $CONFIGFILE $HTTPD_OPTS |
61fdfa32 | 93 | fi |
29afef3d | 94 | RETVAL=$? |
dd1d7d33 ER |
95 | if [ $RETVAL -eq 0 ]; then |
96 | ok | |
6a790b88 | 97 | touch /var/lock/subsys/lighttpd |
dd1d7d33 ER |
98 | else |
99 | fail | |
100 | fi | |
29afef3d ER |
101 | } |
102 | ||
103 | stop() { | |
5be0ba14 ER |
104 | # Stop daemons. |
105 | if [ ! -f /var/lock/subsys/lighttpd ]; then | |
106 | msg_not_running "Lighttpd Web Server" | |
107 | return | |
108 | fi | |
109 | ||
110 | msg_stopping "Lighttpd Web Server" | |
29afef3d ER |
111 | killproc --pidfile /var/run/lighttpd.pid lighttpd |
112 | rm -f /var/lock/subsys/lighttpd >/dev/null 2>&1 | |
61fdfa32 | 113 | rm -f /var/run/lighttpd*.pid >/dev/null 2>&1 |
29afef3d ER |
114 | } |
115 | ||
5be0ba14 ER |
116 | restart() { |
117 | local pid | |
118 | ||
119 | # short circuit to safe reload if pid exists and is alive | |
61fdfa32 PG |
120 | if is_yes "${LIGHT_ANGEL}"; then |
121 | if [ -f /var/lock/subsys/lighttpd ] && pid=$(pidofproc lighttpd-angel lighttpd-angel.pid) && checkpid $pid; then | |
122 | reload | |
123 | return | |
124 | fi | |
125 | else | |
126 | if [ -f /var/lock/subsys/lighttpd ] && pid=$(pidofproc lighttpd lighttpd.pid) && checkpid $pid; then | |
127 | reload | |
128 | return | |
129 | fi | |
5be0ba14 ER |
130 | fi |
131 | ||
132 | checkconfig | |
133 | stop | |
134 | start | |
135 | } | |
136 | ||
29afef3d | 137 | reload() { |
61fdfa32 | 138 | # TODO: check if process is running. Start it in this case. |
5be0ba14 ER |
139 | if [ ! -f /var/lock/subsys/lighttpd ]; then |
140 | msg_not_running "Lighttpd Web Server" | |
141 | RETVAL=7 | |
142 | return | |
143 | fi | |
144 | ||
0ba2e99c | 145 | checkconfig 1 |
5be0ba14 ER |
146 | msg_reloading "Lighttpd Web Server" |
147 | ||
61fdfa32 PG |
148 | if is_yes "${LIGHT_ANGEL}"; then |
149 | # sending HUP signal to angel will make lighttpd close all listening | |
150 | # sockets and wait for client connections to terminate. After that new | |
151 | # child will be started | |
152 | killproc lighttpd-angel -HUP | |
153 | else | |
154 | # sending INT signal will make lighttpd close all listening sockets and | |
155 | # wait for client connections to terminate. | |
156 | killproc --pidfile /var/run/lighttpd.pid lighttpd -INT | |
e4eb660d | 157 | env SHELL=/bin/sh lighttpd -f $CONFIGFILE $HTTPD_OPTS |
61fdfa32 | 158 | fi |
5be0ba14 ER |
159 | RETVAL=$? |
160 | } | |
161 | ||
162 | condrestart() { | |
163 | if [ ! -f /var/lock/subsys/lighttpd ]; then | |
164 | msg_not_running "Lighttpd Web Server" | |
165 | RETVAL=$1 | |
166 | return | |
167 | fi | |
168 | ||
169 | checkconfig | |
170 | stop | |
171 | start | |
172 | } | |
173 | ||
174 | flush-logs() { | |
175 | if [ ! -f /var/lock/subsys/lighttpd ]; then | |
176 | msg_not_running "Lighttpd Web Server" | |
177 | RETVAL=7 | |
178 | return | |
179 | fi | |
180 | ||
181 | show "Rotating %s logs" lighttpd | |
61fdfa32 | 182 | # send HUP to main lighttpd (not angel) process to rotate logs: |
5be0ba14 ER |
183 | killproc --pidfile /var/run/lighttpd.pid lighttpd -HUP |
184 | RETVAL=$? | |
29afef3d ER |
185 | } |
186 | ||
cb1656fe AM |
187 | RETVAL=0 |
188 | # See how we were called. | |
189 | case "$1" in | |
190 | start) | |
5be0ba14 | 191 | start |
cb1656fe AM |
192 | ;; |
193 | stop) | |
5be0ba14 | 194 | stop |
cb1656fe | 195 | ;; |
29afef3d | 196 | restart) |
5be0ba14 | 197 | restart |
cb1656fe | 198 | ;; |
5be0ba14 ER |
199 | try-restart) |
200 | condrestart 0 | |
29afef3d | 201 | ;; |
5be0ba14 ER |
202 | reload|force-reload|graceful) |
203 | reload | |
404d7754 | 204 | ;; |
29afef3d | 205 | flush-logs) |
6a790b88 | 206 | flush-logs |
5be0ba14 ER |
207 | ;; |
208 | checkconfig|configtest) | |
209 | checkconfig 1 | |
210 | ;; | |
a3d8706e | 211 | show-config) |
8f80a943 | 212 | env SHELL=/bin/sh $DAEMON -p -f $CONFIGFILE $HTTPD_OPTS |
a3d8706e | 213 | ;; |
5be0ba14 | 214 | status) |
d5fc2c4c ER |
215 | if is_yes "${LIGHT_ANGEL}"; then |
216 | status lighttpd-angel || RETVAL=$? | |
217 | fi | |
218 | status lighttpd || RETVAL=$? | |
cb1656fe AM |
219 | ;; |
220 | *) | |
a3d8706e | 221 | msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|configtest|flush-logs|show-config|status}" |
cb1656fe AM |
222 | exit 3 |
223 | ;; | |
224 | esac | |
225 | ||
226 | exit $RETVAL |