File rc.apache2 of Package apache2 (Revision 49)
Currently displaying revision 49, show latest
x
1
#!/bin/sh
2
#
3
# Copyright (c) 1996, 1997, 1998 S.u.S.E. GmbH
4
# Copyright (c) 1998, 1999, 2000, 2001 SuSE GmbH
5
# Copyright (c) 2002, 2003, (2004?) SuSE Linux AG
6
# Copyright (c) 2004(?), 2005, 2006, 2007, 2008 SUSE Linux Products GmbH
7
#
8
# Authors: Rolf Haberrecker <apache@suse.de>, 2001
9
# Peter Poeml <apache@suse.de>, 2002, 2003, 2004, 2005, 2006, 2007, 2008
10
#
11
#
12
# /etc/init.d/apache2
13
#
14
### BEGIN INIT INFO
15
# Provides: apache apache2 httpd
16
# Required-Start: $local_fs $remote_fs $network
17
# Should-Start: $named $time postgresql sendmail mysql ypclient dhcp radiusd
18
# Should-Stop: $named $time postgresql sendmail mysql ypclient dhcp radiusd
19
# Required-Stop: $local_fs $remote_fs $network
20
# Default-Start: 3 5
21
# Default-Stop: 0 1 2 6
22
# Short-Description: Apache 2.2 HTTP Server
23
# Description: Start the Apache HTTP daemon
24
### END INIT INFO
25
26
pname=apache2
27
: ${sysconfdir:=/etc/$pname}
28
: ${apache_link:=/usr/sbin/httpd2}
29
: ${sysconfig_apache:=/etc/sysconfig/$pname}
30
: ${pidfile:=/var/run/httpd2.pid}
31
: ${logdir:=/var/log/$pname}
32
: ${homedir:=/var/lib/$pname}
33
34
#
35
# load the configuration
36
#
37
38
#
39
# Note about ulimits:
40
# if you want to set ulimits, e.g. to increase the max number of open file handle,
41
# or to allow core files, you can do so by editing /etc/sysconfig/apache2 and
42
# simply write the ulimit commands into that file.
43
# Example:
44
# ulimit -n 16384
45
# ulimit -H -n 16384
46
# ulimit -c unlimited
47
# See the output of "help ulimit" in the bash, or "man 1 ulimit".
48
#
49
test -s /etc/rc.status && . /etc/rc.status && rc_reset
50
51
. /usr/share/$pname/load_configuration
52
export ${!APACHE_*}
53
54
httpd_conf=${APACHE_HTTPD_CONF:-$sysconfdir/httpd.conf}
55
56
apache_bin=$(/usr/share/$pname/find_mpm 2>/dev/null)
57
58
test -L $apache_link && apache_bin=$(readlink $apache_link)
59
60
if [ -z "$APACHE_MPM" ]; then
61
APACHE_MPM=${apache_bin##*-}
62
fi
63
64
if ! [ -x $apache_bin ]; then
65
echo >&2 ${warn}$apache_bin-$APACHE_MPM is not a valid httpd2 binary.
66
echo >&2 Check your APACHE_MPM setting in /etc/sysconfig/$pname. $norm
67
rc_failed 5
68
rc_status -v1
69
rc_exit
70
fi
71
72
# a proper home should be set, otherwise the server might end up
73
# with HOME=/root and some script might try to use that
74
HOME=$homedir
75
76
get_server_flags()
77
{
78
unset server_flags
79
case "$action" in startssl) server_flags="-DSSL";; esac
80
for i in $APACHE_SERVER_FLAGS; do
81
case $i in
82
-D) ;;
83
-D*) server_flags="$server_flags $i";;
84
*) server_flags="$server_flags -D$i";;
85
esac
86
done
87
}
88
89
action="$1"
90
case "$action" in
91
stop|try-restart|*status*|probe)
92
;;
93
*)
94
shift; get_server_flags
95
${get_module_list_done:=false} || /usr/share/$pname/get_module_list && export get_module_list_done=true
96
${get_includes:=false} || /usr/share/$pname/get_includes && export get_includes_done=true
97
;;
98
esac
99
100
#
101
# main part
102
#
103
case "$action" in
104
start*)
105
if [ -e $pidfile ]; then
106
$0 status &>/dev/null
107
ret=$?
108
if [ $ret = 1 ]; then
109
echo "Warning: found stale pidfile (unclean shutdown?)"
110
elif [ $ret = 0 ]; then
111
echo "Apache is already running ($pidfile)"
112
rc_failed $ret
113
rc_status -v1
114
rc_exit
115
fi
116
fi
117
118
echo -n "Starting httpd2 (${APACHE_MPM:-${apache_bin#*-}}) "
119
cmdline=$(echo $apache_bin -f $httpd_conf $server_flags "$@")
120
if eval $cmdline -t > $logdir/rc$pname.out 2>&1 ; then
121
export -n ${!APACHE_*}
122
eval startproc -f -t ${APACHE_START_TIMEOUT:-2} $cmdline
123
ret=$?
124
125
if test -t 1 && stty -a 2>/dev/null | grep -q -- -echo\ ; then
126
# this means that apache was still waiting for a passphrase to be entered
127
stty echo 2>/dev/null
128
echo;echo
129
echo >&2 An SSL passphrase has not been entered within ${APACHE_START_TIMEOUT:-<not set>} seconds.
130
echo >&2 To increase this timeout, adjust APACHE_START_TIMEOUT in $sysconfig_apache .
131
# this surely means that apache won't start, despite it looked good to startproc
132
killall $apache_bin
133
echo >&2 "Trying to start the server without SSL (-D NOSSL)."
134
$0 start "$@" -D NOSSL
135
# rc_failed 1
136
# rc_status -v1
137
# rc_exit
138
else
139
rc_failed $ret
140
rc_status -v
141
fi
142
else
143
if [ "$link" = "$base" ] ; then
144
cat $logdir/rc$pname.out
145
echo >&2
146
echo >&2 The command line was:
147
echo >&2 $cmdline
148
echo >&2
149
else
150
echo -e -n "\nsee $logdir/rc$pname.out for details\n";
151
fi
152
rc_failed 1
153
rc_status -v1
154
fi
155
;;
156
stop)
157
echo -n "Shutting down httpd2 "
158
if [ ! -f $pidfile -a -f $pidfile.rpmsave ]; then mv $pidfile.rpmsave $pidfile; fi
159
if ! [ -f $pidfile ]; then
160
echo -n "(not running)"
161
else
162
pid=$(<$pidfile)
163
kill -TERM $pid 2>/dev/null
164
case $? in
165
1) echo -n "(not running)";;
166
0) # wait until the processes are gone (the parent is the last one)
167
echo -n "(waiting for all children to terminate) "
168
for ((wait=0; wait<120; wait++)); do
169
if test -f $pidfile; then
170
usleep 500000
171
continue
172
fi
173
if ! test -f /proc/$pid/exe; then
174
break
175
fi
176
if test "$(readlink /proc/$pid/exe 2>/dev/null)" = $apache_bin; then
177
usleep 500000
178
else
179
break
180
fi
181
182
done
183
;;
184
esac
185
fi
186
187
rc_status -v
188
;;
189
stop-graceful)
190
echo "Shutting down httpd2 gracefully (SIGWINCH)"
191
if ! [ -f $pidfile ]; then
192
echo -n "(not running)"
193
else
194
pid=$(<$pidfile)
195
kill -WINCH $pid 2>/dev/null
196
case $? in
197
1) echo -n "(not running)";;
198
0) # wait until the pidfile is gone. The parent stays there, but closes the listen ports.
199
echo -n "(waiting for parent to close listen ports and remove pidfile) "
200
for ((wait=0; wait<120; wait++)); do
201
if test -f $pidfile; then
202
usleep 500000
203
continue
204
else
205
break
206
fi
207
done
208
;;
209
esac
210
fi
211
212
rc_status -v
213
;;
214
try-restart)
215
## Do a restart only if the service was active before.
216
## Note: try-restart is now part of LSB (as of 1.9).
217
## RH has a similar command named condrestart.
218
$0 status
219
if test $? = 0; then
220
$0 restart
221
else
222
rc_reset # Not running is not a failure.
223
fi
224
# Remember status and be quiet
225
rc_status
226
;;
227
restart)
228
$0 configtest "$@" || { rc_failed $?; rc_exit; }
229
230
if $0 status &>/dev/null; then
231
$0 stop
232
fi
233
$0 start "$@"
234
# Remember status and be quiet
235
rc_status
236
;;
237
restart-hup)
238
$0 configtest "$@" || { rc_failed $?; rc_exit; }
239
240
if $0 status &>/dev/null; then
241
echo -n "Restarting httpd2 (SIGHUP)"
242
kill -HUP $(<$pidfile) || return=$rc_failed
243
else
244
$0 start "$@"
245
fi
246
# Remember status and be quiet
247
rc_status -v
248
;;
249
restart-graceful)
250
$0 configtest "$@" || { rc_failed $?; rc_exit; }
251
252
if $0 status &>/dev/null; then
253
$0 stop-graceful "$@"
254
$0 start "$@"
255
else
256
$0 start "$@"
257
fi
258
# Remember status and be quiet
259
rc_status
260
;;
261
reload|force-reload|graceful)
262
echo -n "Reload httpd2 (graceful restart)"
263
cmdline=$(echo $apache_bin -f $httpd_conf $server_flags "$@")
264
if eval $cmdline -t &> $logdir/rc$pname.out; then
265
killproc -USR1 $apache_bin || return=$rc_failed
266
rc_status -v
267
else
268
if [ "$link" = "$base" ] ; then
269
echo -e -n "\n\n"
270
cat $logdir/rc$pname.out
271
echo >&2
272
echo >&2 The command line was:
273
echo >&2 $cmdline
274
echo >&2
275
else
276
echo -e -n "\nsee $logdir/rc$pname.out for details\n";
277
fi
278
rc_failed 6
279
rc_status -v1
280
fi
281
;;
282
status)
283
if [ ! -f $pidfile -a -f $pidfile.rpmsave ]; then mv $pidfile.rpmsave $pidfile; fi
284
echo -n "Checking for httpd2: "
285
# we don't use checkproc here since it is confused when we exchange the binaries
286
if ! [ -f $pidfile ]; then
287
# not running
288
rc_failed 3
289
elif [ -s $pidfile -a -d /proc/$(<$pidfile) ]; then
290
# running
291
:
292
else
293
# stale pid file
294
rc_failed 1
295
#rm -f $pidfile
296
fi
297
rc_status -v
298
;;
299
probe)
300
## Optional: Probe for the necessity of a reload,
301
## give out the argument which is required for a reload.
302
303
for i in $httpd_conf \
304
$APACHE_CONF_INCLUDE_FILES \
305
$APACHE_CONF_INCLUDE_DIRS
306
do
307
if [ $i -nt $pidfile ]; then
308
echo reload
309
break
310
fi
311
done
312
;;
313
314
conf*|test|syntax|check)
315
cmdline=$(echo $apache_bin -f $httpd_conf $server_flags "$@")
316
eval $cmdline -t
317
rc_failed $?
318
rc_exit
319
;;
320
321
extr*)
322
cmdline=$(echo $apache_bin -f $httpd_conf $server_flags "$@")
323
out=$(su - nobody -c "$cmdline" 2>&1)
324
case $out in
325
*make_sock:\ could\ not\ bind\ to\ address*) echo Syntax: OK; rc_failed=0;;
326
*) echo Syntax: NOT OK:; echo $out; rc_failed=1;;
327
esac
328
rc_exit
329
;;
330
331
server-status)
332
apache2ctl status
333
;;
334
335
full-server-status|fullstatus)
336
apache2ctl fullstatus
337
;;
338
339
*)
340
cat >&2 <<-EOF
341
Usage: $0 <command> <server flags>
342
343
where <command> is one of:
344
start - start httpd
345
startssl - start httpd with -DSSL
346
stop - stop httpd (sending SIGTERM to parent)
347
try-restart - stop httpd and if this succeeds (i.e. if
348
it was running before), start it again.
349
350
status - check whether httpd is running
351
352
restart - stop httpd if running; start httpd
353
restart-graceful - stop httpd gracefully if running; start httpd
354
reload|graceful - do a graceful restart by sending a SIGUSR1, or
355
start if not running
356
stop-graceful - stop httpd (sending SIGWINCH to parent)
357
358
configtest - do a configuration syntax test
359
extreme-configtest - try to run httpd as nobody (detects more errors
360
by actually loading the configuration, but cannot
361
read SSL certificates)
362
probe - probe for the necessity of a reload, give
363
out the argument which is required for a reload.
364
(by comparing conf files with pidfile timestamp)
365
366
full-server-status - dump a full status screen; requires lynx or w3m
367
and mod_status enabled
368
server-status - dump a short status screen; requires lynx or w3m
369
and mod_status enabled
370
371
help - this screen
372
373
optional server flags are passed through to httpd.
374
375
EOF
376
exit 1
377
esac
378
379
380
# Inform the caller not only verbosely and set an exit status.
381
rc_exit
382