]>
Commit | Line | Data |
---|---|---|
cb1656fe AM |
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 | |
cb1656fe AM |
22 | msg_network_down lighttpd |
23 | exit 1 | |
24 | fi | |
25 | else | |
26 | exit 0 | |
27 | fi | |
28 | ||
1ae7ff0d ER |
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 | ||
29afef3d | 40 | start() { |
dd1d7d33 | 41 | env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS |
29afef3d | 42 | RETVAL=$? |
dd1d7d33 ER |
43 | if [ $RETVAL -eq 0 ]; then |
44 | ok | |
45 | touch /var/lock/subsys/lighttpd | |
46 | else | |
47 | fail | |
48 | fi | |
29afef3d ER |
49 | return $RETVAL |
50 | } | |
51 | ||
52 | stop() { | |
53 | killproc --pidfile /var/run/lighttpd.pid lighttpd | |
54 | rm -f /var/lock/subsys/lighttpd >/dev/null 2>&1 | |
55 | } | |
56 | ||
57 | reload() { | |
58 | # sending INT signal will make lighttpd close all listening sockets and | |
59 | # wait for client connections to terminate. | |
60 | killproc --pidfile /var/run/lighttpd.pid lighttpd -INT | |
61 | env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS | |
62 | } | |
63 | ||
cb1656fe AM |
64 | RETVAL=0 |
65 | # See how we were called. | |
66 | case "$1" in | |
67 | start) | |
68 | # Check if the service is already running? | |
69 | if [ ! -f /var/lock/subsys/lighttpd ]; then | |
70 | msg_starting lighttpd | |
1ae7ff0d | 71 | configtest || exit 1 |
29afef3d | 72 | start |
cb1656fe AM |
73 | else |
74 | msg_already_running lighttpd | |
75 | fi | |
76 | ;; | |
77 | stop) | |
78 | # Stop daemons. | |
79 | if [ -f /var/lock/subsys/lighttpd ]; then | |
80 | msg_stopping lighttpd | |
29afef3d | 81 | stop |
cb1656fe AM |
82 | else |
83 | msg_not_running lighttpd | |
84 | fi | |
85 | ;; | |
86 | status) | |
87 | status lighttpd | |
88 | RETVAL=$? | |
89 | ;; | |
29afef3d | 90 | restart) |
ca225ce7 | 91 | if [ -f /var/lock/subsys/lighttpd ]; then |
1ae7ff0d | 92 | configtest || exit 1 |
29afef3d ER |
93 | |
94 | # short circuit to safe reload if pid exists and is alive | |
95 | pid=$(pidofproc lighttpd lighttpd.pid) | |
96 | if [ "$pid" ] && checkpid $pid; then | |
97 | msg_reloading lighttpd | |
98 | reload | |
99 | else | |
100 | msg_stopping lighttpd | |
101 | stop | |
102 | msg_starting lighttpd | |
103 | start | |
104 | fi | |
105 | RETVAL=$? | |
106 | else | |
107 | msg_not_running lighttpd | |
108 | msg_starting lighttpd | |
109 | start | |
ca225ce7 | 110 | fi |
cb1656fe | 111 | ;; |
29afef3d | 112 | reload|graceful|force-reload) |
cb1656fe AM |
113 | if [ -f /var/lock/subsys/lighttpd ]; then |
114 | msg_reloading lighttpd | |
c8d81971 | 115 | configtest || exit 1 |
29afef3d ER |
116 | reload |
117 | RETVAL=$? | |
118 | else | |
119 | msg_not_running lighttpd | |
120 | RETVAL=7 | |
121 | fi | |
122 | ;; | |
404d7754 ER |
123 | configtest) |
124 | show "Checking lighttpd config syntax" | |
125 | configtest | |
126 | RETVAL=$? | |
127 | [ $RETVAL = 0 ] && ok || fail | |
128 | ;; | |
29afef3d ER |
129 | flush-logs) |
130 | if [ -f /var/lock/subsys/lighttpd ]; then | |
131 | nls "Rotating %s logs" lighttpd | |
647b6537 | 132 | killproc --pidfile /var/run/lighttpd.pid lighttpd -HUP |
cb1656fe AM |
133 | RETVAL=$? |
134 | else | |
135 | msg_not_running lighttpd | |
136 | RETVAL=7 | |
137 | fi | |
138 | ;; | |
139 | *) | |
404d7754 | 140 | msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|configtest|flush-logs|status}" |
cb1656fe AM |
141 | exit 3 |
142 | ;; | |
143 | esac | |
144 | ||
145 | exit $RETVAL |