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