]> git.pld-linux.org Git - packages/lighttpd.git/blob - lighttpd.init
- add lost configtest to reload target
[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
23                 exit 1
24         fi
25 else
26         exit 0
27 fi
28
29 configtest() {
30         out=`env SHELL=/bin/sh lighttpd -t -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS 2>&1`
31         rc=$?
32         if [ "$rc" = 0 ]; then
33                 return
34         fi
35         echo >&2 ""
36         echo >&2 "$out"
37         fail
38 }
39
40 start() {
41         daemon env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS
42         RETVAL=$?
43         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/lighttpd
44         return $RETVAL
45 }
46
47 stop() {
48         killproc --pidfile /var/run/lighttpd.pid lighttpd
49         rm -f /var/lock/subsys/lighttpd >/dev/null 2>&1
50 }
51
52 reload() {
53         # sending INT signal will make lighttpd close all listening sockets and
54         # wait for client connections to terminate.
55         killproc --pidfile /var/run/lighttpd.pid lighttpd -INT
56         env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS
57 }
58
59 RETVAL=0
60 # See how we were called.
61 case "$1" in
62   start)
63         # Check if the service is already running?
64         if [ ! -f /var/lock/subsys/lighttpd ]; then
65                 msg_starting lighttpd
66                 configtest || exit 1
67                 start
68         else
69                 msg_already_running lighttpd
70         fi
71         ;;
72   stop)
73         # Stop daemons.
74         if [ -f /var/lock/subsys/lighttpd ]; then
75                 msg_stopping lighttpd
76                 stop
77         else
78                 msg_not_running lighttpd
79         fi
80         ;;
81   status)
82         status lighttpd
83         RETVAL=$?
84         ;;
85   restart)
86         if [ -f /var/lock/subsys/lighttpd ]; then
87                 configtest || exit 1
88
89                 # short circuit to safe reload if pid exists and is alive
90                 pid=$(pidofproc lighttpd lighttpd.pid)
91                 if [ "$pid" ] && checkpid $pid; then
92                         msg_reloading lighttpd
93                         reload
94                 else
95                         msg_stopping lighttpd
96                         stop
97                         msg_starting lighttpd
98                         start
99                 fi
100                 RETVAL=$?
101         else
102                 msg_not_running lighttpd
103                 msg_starting lighttpd
104                 start
105         fi
106         ;;
107   reload|graceful|force-reload)
108         if [ -f /var/lock/subsys/lighttpd ]; then
109                 msg_reloading lighttpd
110                 configtest || exit 1
111                 reload
112                 RETVAL=$?
113         else
114                 msg_not_running lighttpd
115                 RETVAL=7
116         fi
117         ;;
118   flush-logs)
119         if [ -f /var/lock/subsys/lighttpd ]; then
120                 nls "Rotating %s logs" lighttpd
121                 configtest || exit 1
122                 killproc --pidfile /var/run/lighttpd.pid lighttpd -HUP
123                 RETVAL=$?
124         else
125                 msg_not_running lighttpd
126                 RETVAL=7
127         fi
128         ;;
129   *)
130         msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|flush-logs|status}"
131         exit 3
132         ;;
133 esac
134
135 exit $RETVAL
This page took 0.033623 seconds and 4 git commands to generate.