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