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