]>
Commit | Line | Data |
---|---|---|
8faab90e | 1 | #!/bin/sh |
58f9559b | 2 | # |
34c86420 | 3 | # apache Apache Web Server |
58f9559b | 4 | # |
34c86420 | 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 | |
5980b766 | 10 | # config: /etc/httpd/apache.conf |
34c86420 | 11 | |
12 | # Source function library | |
58f9559b AF |
13 | . /etc/rc.d/init.d/functions |
14 | ||
34c86420 | 15 | # Get network config |
16 | . /etc/sysconfig/network | |
17 | ||
18 | # Get service config | |
9dd5ff04 | 19 | [ -f /etc/sysconfig/httpd ] && . /etc/sysconfig/httpd |
34c86420 | 20 | |
58f9559b | 21 | # Check that networking is up. |
a7f729cf | 22 | if is_yes "${NETWORKING}"; then |
bc107690 | 23 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then |
9841efdf | 24 | msg_network_down "Apache 2.2 Web Server" |
a7f729cf | 25 | exit 1 |
26 | fi | |
27 | else | |
28 | exit 0 | |
036261c0 | 29 | fi |
1f86fa83 | 30 | |
7728b647 | 31 | [ -z "$HTTPD_MPM" ] && HTTPD_MPM="prefork" |
9841efdf | 32 | SVC_NAME="Apache 2.2 Web Server ($HTTPD_MPM)" |
83998870 ER |
33 | |
34 | if [ -n "${HTTPD_CONF}" ]; then | |
35 | if [ -d "${HTTPD_CONF}" ] || [ -f "${HTTPD_CONF}" ]; then | |
36 | CFG="-f ${HTTPD_CONF}" | |
37 | else | |
38 | echo "error: HTTPD_CONF='$HTTPD_CONF': not a file, not a directory" | |
39 | exit 1 | |
40 | fi | |
812867fe | 41 | fi |
7728b647 | 42 | |
861999ba | 43 | # configtest itself |
fa160d07 | 44 | configtest() { |
861999ba ER |
45 | /usr/sbin/httpd.${HTTPD_MPM} -t $CFG $HTTPD_OPTS 2>&1 |
46 | return $? | |
fa160d07 ER |
47 | } |
48 | ||
861999ba ER |
49 | # wrapper for configtest: |
50 | checkconfig() { | |
51 | local details=${1:-0} | |
52 | ||
b59d522e | 53 | if [ $details -eq 1 ]; then |
861999ba ER |
54 | # run config test and display report (status action) |
55 | show "Checking %s configuration" "$SVC_NAME"; busy | |
56 | local out | |
57 | out=`configtest 2>&1` | |
a7f729cf | 58 | RETVAL=$? |
b59d522e | 59 | [ $RETVAL -eq 0 ] && ok || fail |
861999ba | 60 | [ "$out" ] && echo >&2 "$out" |
34c86420 | 61 | else |
861999ba ER |
62 | # run config test and abort with nice message if failed |
63 | # (for actions checking status before action). | |
b59d522e | 64 | show "Checking %s configuration" "$SVC_NAME"; busy |
861999ba ER |
65 | configtest >/dev/null 2>&1 |
66 | RETVAL=$? | |
b59d522e TP |
67 | if [ $RETVAL -eq 0 ]; then |
68 | ok | |
69 | else | |
70 | fail | |
861999ba ER |
71 | nls 'Configuration test failed. See details with %s "checkconfig"' $0 |
72 | exit $RETVAL | |
73 | fi | |
74 | fi | |
75 | } | |
76 | ||
77 | start() { | |
78 | # Check if the service is already running? | |
79 | if [ -f /var/lock/subsys/httpd ]; then | |
9841efdf | 80 | msg_already_running "$SVC_NAME" |
861999ba | 81 | return |
34c86420 | 82 | fi |
861999ba ER |
83 | |
84 | checkconfig | |
85 | msg_starting "$SVC_NAME" | |
86 | daemon --pidfile /var/run/httpd.pid /usr/sbin/httpd.${HTTPD_MPM} $CFG $HTTPD_OPTS | |
87 | RETVAL=$? | |
88 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/httpd | |
edb12654 ER |
89 | } |
90 | ||
91 | stop() { | |
a7f729cf | 92 | # Stop daemons. |
861999ba | 93 | if [ ! -f /var/lock/subsys/httpd ]; then |
9841efdf | 94 | msg_not_running "$SVC_NAME" |
861999ba | 95 | return |
a4aad8e2 | 96 | fi |
861999ba ER |
97 | |
98 | msg_stopping "$SVC_NAME" | |
99 | killproc --pidfile /var/run/httpd.pid httpd.${HTTPD_MPM} | |
100 | rm -f /var/lock/subsys/httpd /var/run/httpd.pid /var/run/httpd.loc* >/dev/null 2>&1 | |
101 | } | |
102 | ||
103 | ||
104 | reload() { | |
105 | if [ ! -f /var/lock/subsys/httpd ]; then | |
106 | msg_not_running "$SVC_NAME" | |
107 | RETVAL=7 | |
108 | return | |
109 | fi | |
110 | ||
111 | checkconfig | |
112 | msg_reloading "$SVC_NAME" | |
113 | busy | |
114 | /usr/sbin/httpd.${HTTPD_MPM} $CFG $HTTPD_OPTS -k graceful | |
115 | RETVAL=$? | |
116 | [ $RETVAL -eq 0 ] && ok || fail | |
edb12654 ER |
117 | } |
118 | ||
6c46b529 | 119 | condrestart() { |
861999ba | 120 | if [ ! -f /var/lock/subsys/httpd ]; then |
9841efdf | 121 | msg_not_running "$SVC_NAME" |
6c46b529 | 122 | RETVAL=$1 |
861999ba | 123 | return |
6c46b529 | 124 | fi |
861999ba ER |
125 | |
126 | checkconfig | |
127 | stop | |
128 | start | |
6c46b529 JB |
129 | } |
130 | ||
edb12654 ER |
131 | RETVAL=0 |
132 | # See how we were called. | |
133 | case "$1" in | |
134 | start) | |
4676a5d0 | 135 | start |
edb12654 ER |
136 | ;; |
137 | stop) | |
4676a5d0 | 138 | stop |
58f9559b | 139 | ;; |
40350f98 | 140 | restart) |
edb12654 ER |
141 | stop |
142 | start | |
58f9559b | 143 | ;; |
6c46b529 JB |
144 | try-restart) |
145 | condrestart 0 | |
146 | ;; | |
deb97ce3 | 147 | reload|force-reload|graceful|flush-logs) |
b59d522e | 148 | reload |
861999ba ER |
149 | ;; |
150 | checkconfig|configtest) | |
151 | checkconfig 1 | |
1f79aa47 | 152 | ;; |
861999ba ER |
153 | status) |
154 | status httpd.${HTTPD_MPM} | |
155 | RETVAL=$? | |
156 | /usr/sbin/httpd.${HTTPD_MPM} $CFG $HTTPD_OPTS -S | |
fa160d07 | 157 | ;; |
58f9559b | 158 | *) |
fa160d07 | 159 | msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|graceful|configtest|status}" |
e156d1e7 | 160 | exit 3 |
58f9559b AF |
161 | ;; |
162 | esac | |
163 | ||
a4aad8e2 | 164 | exit $RETVAL |