]> git.pld-linux.org Git - packages/lighttpd.git/blob - lighttpd.init
aaf4d5fae66946360f8b500221b0320f8a21e928
[packages/lighttpd.git] / lighttpd.init
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
13 upstart_controlled
14
15 # Get network config
16 . /etc/sysconfig/network
17
18 # Get service config
19 [ -f /etc/sysconfig/lighttpd ] && . /etc/sysconfig/lighttpd
20
21 DAEMON=/usr/sbin/lighttpd
22 ANGEL_DAEMON=/usr/sbin/lighttpd-angel
23 CONFIGFILE=/etc/lighttpd/lighttpd.conf
24
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
28                 msg_network_down "Lighttpd Web Server"
29                 exit 1
30         fi
31 else
32         exit 0
33 fi
34
35 configtest() {
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')
43                 echo >&2 "WARNING: found deprecated '$out', convert to 'url.rewrite-final' recommented, See http://redmine.lighttpd.net/issues/2379"
44         fi
45
46         env SHELL=/bin/sh $DAEMON -t -f $CONFIGFILE $HTTPD_OPTS
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
57                 out=$(configtest 2>&1)
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
75         fi
76 }
77
78 start() {
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
87         if is_yes "${LIGHT_ANGEL}"; then
88                 daemon --fork --pidfile /var/run/lighttpd-angel.pid --makepid \
89                         env SHELL=/bin/sh $ANGEL_DAEMON -D -f $CONFIGFILE $HTTPD_OPTS
90
91         else
92                 env SHELL=/bin/sh $DAEMON -f $CONFIGFILE $HTTPD_OPTS
93         fi
94         RETVAL=$?
95         if [ $RETVAL -eq 0 ]; then
96                 ok
97                 touch /var/lock/subsys/lighttpd
98         else
99                 fail
100         fi
101 }
102
103 stop() {
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"
111         killproc --pidfile /var/run/lighttpd.pid lighttpd
112         rm -f /var/lock/subsys/lighttpd >/dev/null 2>&1
113         rm -f /var/run/lighttpd*.pid >/dev/null 2>&1
114 }
115
116 restart() {
117         local pid
118
119         # short circuit to safe reload if pid exists and is alive
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
130         fi
131
132         checkconfig
133         stop
134         start
135 }
136
137 reload() {
138         # TODO: check if process is running. Start it in this case.
139         if [ ! -f /var/lock/subsys/lighttpd ]; then
140                 msg_not_running "Lighttpd Web Server"
141                 RETVAL=7
142                 return
143         fi
144
145         checkconfig 1
146         msg_reloading "Lighttpd Web Server"
147
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
157                 env SHELL=/bin/sh lighttpd -f $CONFIGFILE $HTTPD_OPTS
158         fi
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
182         # send HUP to main lighttpd (not angel) process to rotate logs:
183         killproc --pidfile /var/run/lighttpd.pid lighttpd -HUP
184         RETVAL=$?
185 }
186
187 RETVAL=0
188 # See how we were called.
189 case "$1" in
190   start)
191         start
192         ;;
193   stop)
194         stop
195         ;;
196   restart)
197         restart
198         ;;
199   try-restart)
200         condrestart 0
201         ;;
202   reload|force-reload|graceful)
203         reload
204         ;;
205   flush-logs)
206         flush-logs
207         ;;
208   checkconfig|configtest)
209         checkconfig 1
210         ;;
211   show-config)
212         env SHELL=/bin/sh $DAEMON -p -f $CONFIGFILE $HTTPD_OPTS
213         ;;
214   status)
215         if is_yes "${LIGHT_ANGEL}"; then
216                 status lighttpd-angel || RETVAL=$?
217         fi
218         status lighttpd || RETVAL=$?
219         ;;
220   *)
221         msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|configtest|flush-logs|show-config|status}"
222         exit 3
223         ;;
224 esac
225
226 exit $RETVAL
This page took 0.077431 seconds and 2 git commands to generate.