]>
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 | ||
21 | # Check that networking is up. | |
22 | if is_yes "${NETWORKING}"; then | |
23 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then | |
75526508 | 24 | msg_network_down "Lighttpd Web Server" |
cb1656fe AM |
25 | exit 1 |
26 | fi | |
27 | else | |
28 | exit 0 | |
29 | fi | |
30 | ||
1ae7ff0d | 31 | configtest() { |
5be0ba14 ER |
32 | env SHELL=/bin/sh lighttpd -t -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS |
33 | } | |
34 | ||
35 | # wrapper for configtest | |
36 | checkconfig() { | |
37 | local details=${1:-0} | |
38 | ||
39 | if [ $details = 1 ]; then | |
40 | # run config test and display report (status action) | |
41 | show "Checking %s configuration" "Lighttpd Web Server"; busy | |
42 | local out | |
43 | out=`configtest 2>&1` | |
44 | RETVAL=$? | |
45 | if [ $RETVAL = 0 ]; then | |
46 | ok | |
47 | else | |
48 | fail | |
49 | fi | |
50 | [ "$out" ] && echo >&2 "$out" | |
51 | else | |
52 | # run config test and abort with nice message if failed | |
53 | # (for actions checking status before action). | |
54 | configtest >/dev/null 2>&1 | |
55 | RETVAL=$? | |
56 | if [ $RETVAL != 0 ]; then | |
57 | show "Checking %s configuration" "Lighttpd Web Server"; fail | |
58 | nls 'Configuration test failed. See details with %s "checkconfig"' $0 | |
59 | exit $RETVAL | |
60 | fi | |
1ae7ff0d | 61 | fi |
1ae7ff0d ER |
62 | } |
63 | ||
29afef3d | 64 | start() { |
5be0ba14 ER |
65 | # Check if the service is already running? |
66 | if [ -f /var/lock/subsys/lighttpd ]; then | |
67 | msg_already_running "Lighttpd Web Server" | |
68 | return | |
69 | fi | |
70 | ||
71 | checkconfig | |
72 | msg_starting "Lighttpd Web Server"; busy | |
61fdfa32 PG |
73 | if is_yes "${LIGHT_ANGEL}"; then |
74 | daemon --fork --pidfile /var/run/lighttpd-angel.pid --makepid \ | |
75 | env SHELL=/bin/sh lighttpd-angel -D -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS 1>&2 | |
76 | ||
77 | else | |
78 | env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS | |
79 | fi | |
29afef3d | 80 | RETVAL=$? |
dd1d7d33 ER |
81 | if [ $RETVAL -eq 0 ]; then |
82 | ok | |
6a790b88 | 83 | touch /var/lock/subsys/lighttpd |
dd1d7d33 ER |
84 | else |
85 | fail | |
86 | fi | |
29afef3d ER |
87 | } |
88 | ||
89 | stop() { | |
5be0ba14 ER |
90 | # Stop daemons. |
91 | if [ ! -f /var/lock/subsys/lighttpd ]; then | |
92 | msg_not_running "Lighttpd Web Server" | |
93 | return | |
94 | fi | |
95 | ||
96 | msg_stopping "Lighttpd Web Server" | |
29afef3d ER |
97 | killproc --pidfile /var/run/lighttpd.pid lighttpd |
98 | rm -f /var/lock/subsys/lighttpd >/dev/null 2>&1 | |
61fdfa32 | 99 | rm -f /var/run/lighttpd*.pid >/dev/null 2>&1 |
29afef3d ER |
100 | } |
101 | ||
5be0ba14 ER |
102 | restart() { |
103 | local pid | |
104 | ||
105 | # short circuit to safe reload if pid exists and is alive | |
61fdfa32 PG |
106 | if is_yes "${LIGHT_ANGEL}"; then |
107 | if [ -f /var/lock/subsys/lighttpd ] && pid=$(pidofproc lighttpd-angel lighttpd-angel.pid) && checkpid $pid; then | |
108 | reload | |
109 | return | |
110 | fi | |
111 | else | |
112 | if [ -f /var/lock/subsys/lighttpd ] && pid=$(pidofproc lighttpd lighttpd.pid) && checkpid $pid; then | |
113 | reload | |
114 | return | |
115 | fi | |
5be0ba14 ER |
116 | fi |
117 | ||
118 | checkconfig | |
119 | stop | |
120 | start | |
121 | } | |
122 | ||
29afef3d | 123 | reload() { |
61fdfa32 | 124 | # TODO: check if process is running. Start it in this case. |
5be0ba14 ER |
125 | if [ ! -f /var/lock/subsys/lighttpd ]; then |
126 | msg_not_running "Lighttpd Web Server" | |
127 | RETVAL=7 | |
128 | return | |
129 | fi | |
130 | ||
131 | checkconfig | |
132 | msg_reloading "Lighttpd Web Server" | |
133 | ||
61fdfa32 PG |
134 | if is_yes "${LIGHT_ANGEL}"; then |
135 | # sending HUP signal to angel will make lighttpd close all listening | |
136 | # sockets and wait for client connections to terminate. After that new | |
137 | # child will be started | |
138 | killproc lighttpd-angel -HUP | |
139 | else | |
140 | # sending INT signal will make lighttpd close all listening sockets and | |
141 | # wait for client connections to terminate. | |
142 | killproc --pidfile /var/run/lighttpd.pid lighttpd -INT | |
143 | env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS | |
144 | fi | |
5be0ba14 ER |
145 | RETVAL=$? |
146 | } | |
147 | ||
148 | condrestart() { | |
149 | if [ ! -f /var/lock/subsys/lighttpd ]; then | |
150 | msg_not_running "Lighttpd Web Server" | |
151 | RETVAL=$1 | |
152 | return | |
153 | fi | |
154 | ||
155 | checkconfig | |
156 | stop | |
157 | start | |
158 | } | |
159 | ||
160 | flush-logs() { | |
161 | if [ ! -f /var/lock/subsys/lighttpd ]; then | |
162 | msg_not_running "Lighttpd Web Server" | |
163 | RETVAL=7 | |
164 | return | |
165 | fi | |
166 | ||
167 | show "Rotating %s logs" lighttpd | |
61fdfa32 | 168 | # send HUP to main lighttpd (not angel) process to rotate logs: |
5be0ba14 ER |
169 | killproc --pidfile /var/run/lighttpd.pid lighttpd -HUP |
170 | RETVAL=$? | |
29afef3d ER |
171 | } |
172 | ||
cb1656fe AM |
173 | RETVAL=0 |
174 | # See how we were called. | |
175 | case "$1" in | |
176 | start) | |
5be0ba14 | 177 | start |
cb1656fe AM |
178 | ;; |
179 | stop) | |
5be0ba14 | 180 | stop |
cb1656fe | 181 | ;; |
29afef3d | 182 | restart) |
5be0ba14 | 183 | restart |
cb1656fe | 184 | ;; |
5be0ba14 ER |
185 | try-restart) |
186 | condrestart 0 | |
29afef3d | 187 | ;; |
5be0ba14 ER |
188 | reload|force-reload|graceful) |
189 | reload | |
404d7754 | 190 | ;; |
29afef3d | 191 | flush-logs) |
6a790b88 | 192 | flush-logs |
5be0ba14 ER |
193 | ;; |
194 | checkconfig|configtest) | |
195 | checkconfig 1 | |
196 | ;; | |
a3d8706e ER |
197 | show-config) |
198 | env SHELL=/bin/sh lighttpd -p -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS | |
199 | ;; | |
5be0ba14 | 200 | status) |
d5fc2c4c ER |
201 | if is_yes "${LIGHT_ANGEL}"; then |
202 | status lighttpd-angel || RETVAL=$? | |
203 | fi | |
204 | status lighttpd || RETVAL=$? | |
cb1656fe AM |
205 | ;; |
206 | *) | |
a3d8706e | 207 | msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|configtest|flush-logs|show-config|status}" |
cb1656fe AM |
208 | exit 3 |
209 | ;; | |
210 | esac | |
211 | ||
212 | exit $RETVAL |