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