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