]> git.pld-linux.org Git - packages/lighttpd.git/blob - lighttpd.init
- remove revno-s for smaller diffs
[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         env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS
72         RETVAL=$?
73         if [ $RETVAL -eq 0 ]; then
74                 ok
75                 touch /var/lock/subsys/lighttpd
76         else
77                 fail
78         fi
79 }
80
81 stop() {
82         # Stop daemons.
83         if [ ! -f /var/lock/subsys/lighttpd ]; then
84                 msg_not_running "Lighttpd Web Server"
85                 return
86         fi
87
88         msg_stopping "Lighttpd Web Server"
89         killproc --pidfile /var/run/lighttpd.pid lighttpd
90         rm -f /var/lock/subsys/lighttpd >/dev/null 2>&1
91 }
92
93 restart() {
94         local pid
95
96         # short circuit to safe reload if pid exists and is alive
97         if [ -f /var/lock/subsys/lighttpd ] && pid=$(pidofproc lighttpd lighttpd.pid) && checkpid $pid; then
98                 reload
99                 return
100         fi
101
102         checkconfig
103         stop
104         start
105 }
106
107 reload() {
108         if [ ! -f /var/lock/subsys/lighttpd ]; then
109                 msg_not_running "Lighttpd Web Server"
110                 RETVAL=7
111                 return
112         fi
113
114         checkconfig
115         msg_reloading "Lighttpd Web Server"
116
117         # sending INT signal will make lighttpd close all listening sockets and
118         # wait for client connections to terminate.
119         killproc --pidfile /var/run/lighttpd.pid lighttpd -INT
120         env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS
121         RETVAL=$?
122 }
123
124 condrestart() {
125         if [ ! -f /var/lock/subsys/lighttpd ]; then
126                 msg_not_running "Lighttpd Web Server"
127                 RETVAL=$1
128                 return
129         fi
130
131         checkconfig
132         stop
133         start
134 }
135
136 flush-logs() {
137         if [ ! -f /var/lock/subsys/lighttpd ]; then
138                 msg_not_running "Lighttpd Web Server"
139                 RETVAL=7
140                 return
141         fi
142
143         show "Rotating %s logs" lighttpd
144         killproc --pidfile /var/run/lighttpd.pid lighttpd -HUP
145         RETVAL=$?
146 }
147
148 RETVAL=0
149 # See how we were called.
150 case "$1" in
151   start)
152         start
153         ;;
154   stop)
155         stop
156         ;;
157   restart)
158         restart
159         ;;
160   try-restart)
161         condrestart 0
162         ;;
163   reload|force-reload|graceful)
164         reload
165         ;;
166   flush-logs)
167         flush-logs
168         ;;
169   checkconfig|configtest)
170         checkconfig 1
171         ;;
172   status)
173         status lighttpd
174         RETVAL=$?
175         ;;
176   *)
177         msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|configtest|flush-logs|status}"
178         exit 3
179         ;;
180 esac
181
182 exit $RETVAL
This page took 0.036162 seconds and 3 git commands to generate.