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