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