]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | # | |
3 | # apache Apache Web Server | |
4 | # | |
5 | # chkconfig: 345 85 15 | |
6 | # description: Apache is a World Wide Web server. It is used to serve \ | |
7 | # HTML files and CGI. | |
8 | # processname: httpd | |
9 | # pidfile: /var/run/httpd.pid | |
10 | # config: /etc/httpd/apache.conf | |
11 | ||
12 | # Source function library | |
13 | . /etc/rc.d/init.d/functions | |
14 | ||
15 | # Get network config | |
16 | . /etc/sysconfig/network | |
17 | ||
18 | # Get service config | |
19 | [ -f /etc/sysconfig/httpd ] && . /etc/sysconfig/httpd | |
20 | ||
21 | # Check that networking is up. | |
22 | if is_yes "${NETWORKING}"; then | |
23 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then | |
24 | msg_network_down "Apache 2.4 Web Server" | |
25 | exit 1 | |
26 | fi | |
27 | else | |
28 | exit 0 | |
29 | fi | |
30 | ||
31 | SVC_NAME="Apache 2.4 Web Server" | |
32 | ||
33 | if [ -n "${HTTPD_CONF}" ]; then | |
34 | if [ -d "${HTTPD_CONF}" ] || [ -f "${HTTPD_CONF}" ]; then | |
35 | CFG="-f ${HTTPD_CONF}" | |
36 | else | |
37 | echo "error: HTTPD_CONF='$HTTPD_CONF': not a file, not a directory" | |
38 | exit 1 | |
39 | fi | |
40 | fi | |
41 | ||
42 | # configtest itself | |
43 | configtest() { | |
44 | /usr/sbin/httpd -t $CFG $HTTPD_OPTS 2>&1 | |
45 | return $? | |
46 | } | |
47 | ||
48 | # wrapper for configtest: | |
49 | checkconfig() { | |
50 | local details=${1:-0} | |
51 | ||
52 | if [ $details -eq 1 ]; then | |
53 | # run config test and display report (status action) | |
54 | show "Checking %s configuration" "$SVC_NAME"; busy | |
55 | local out | |
56 | out=`configtest 2>&1` | |
57 | RETVAL=$? | |
58 | [ $RETVAL -eq 0 ] && ok || fail | |
59 | [ "$out" ] && echo >&2 "$out" | |
60 | else | |
61 | # run config test and abort with nice message if failed | |
62 | # (for actions checking status before action). | |
63 | show "Checking %s configuration" "$SVC_NAME"; busy | |
64 | configtest >/dev/null 2>&1 | |
65 | RETVAL=$? | |
66 | if [ $RETVAL -eq 0 ]; then | |
67 | ok | |
68 | else | |
69 | fail | |
70 | nls 'Configuration test failed. See details with %s "checkconfig"' $0 | |
71 | exit $RETVAL | |
72 | fi | |
73 | fi | |
74 | } | |
75 | ||
76 | start() { | |
77 | # Check if the service is already running? | |
78 | if [ -f /var/lock/subsys/httpd ]; then | |
79 | msg_already_running "$SVC_NAME" | |
80 | return | |
81 | fi | |
82 | ||
83 | [ "$1" -eq 0 ] || checkconfig | |
84 | msg_starting "$SVC_NAME" | |
85 | # remove ssl_scache on startup, otherwise httpd may go into | |
86 | # infinite loop if there are db transaction logs laying around | |
87 | rm -f /var/cache/httpd/*ssl_scache* | |
88 | daemon --pidfile /var/run/httpd.pid /usr/sbin/httpd $CFG $HTTPD_OPTS | |
89 | RETVAL=$? | |
90 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/httpd | |
91 | } | |
92 | ||
93 | stop() { | |
94 | # Stop daemons. | |
95 | if [ ! -f /var/lock/subsys/httpd ]; then | |
96 | msg_not_running "$SVC_NAME" | |
97 | return | |
98 | fi | |
99 | ||
100 | msg_stopping "$SVC_NAME" | |
101 | killproc --pidfile /var/run/httpd.pid httpd | |
102 | rm -f /var/lock/subsys/httpd /var/run/httpd.pid /var/run/httpd.loc* >/dev/null 2>&1 | |
103 | } | |
104 | ||
105 | ||
106 | reload() { | |
107 | if [ ! -f /var/lock/subsys/httpd ]; then | |
108 | msg_not_running "$SVC_NAME" | |
109 | RETVAL=7 | |
110 | return | |
111 | fi | |
112 | ||
113 | checkconfig | |
114 | msg_reloading "$SVC_NAME" | |
115 | busy | |
116 | /usr/sbin/httpd $CFG $HTTPD_OPTS -k graceful | |
117 | RETVAL=$? | |
118 | [ $RETVAL -eq 0 ] && ok || fail | |
119 | } | |
120 | ||
121 | condrestart() { | |
122 | if [ ! -f /var/lock/subsys/httpd ]; then | |
123 | msg_not_running "$SVC_NAME" | |
124 | RETVAL=$1 | |
125 | return | |
126 | fi | |
127 | ||
128 | checkconfig | |
129 | stop | |
130 | start | |
131 | } | |
132 | ||
133 | RETVAL=0 | |
134 | # See how we were called. | |
135 | case "$1" in | |
136 | start) | |
137 | start | |
138 | ;; | |
139 | stop) | |
140 | stop | |
141 | ;; | |
142 | restart) | |
143 | checkconfig | |
144 | stop | |
145 | start 0 | |
146 | ;; | |
147 | try-restart) | |
148 | condrestart 0 | |
149 | ;; | |
150 | reload|force-reload|graceful|flush-logs) | |
151 | reload | |
152 | ;; | |
153 | checkconfig|configtest) | |
154 | checkconfig 1 | |
155 | ;; | |
156 | status) | |
157 | status httpd | |
158 | RETVAL=$? | |
159 | /usr/sbin/httpd $CFG $HTTPD_OPTS -S | |
160 | ;; | |
161 | *) | |
162 | msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|graceful|configtest|status}" | |
163 | exit 3 | |
164 | ;; | |
165 | esac | |
166 | ||
167 | exit $RETVAL |