Bug#479136: apache2: Please don't use "sleep 10" for "restart", but wait until Apache has gone away (with timeout)
Package: apache2
Version: 2.2.8-3
Severity: important
Tags: patch
User: ubuntu-devel@lists.ubuntu.com
Usertags: origin-ubuntu hardy ubuntu-patch
The apache2 init script uses "sleep 10", after "stop" before calling
"start".
Please "just" wait until Apache has gone away.
This has two benefits:
- No fixed downtime of 10 seconds (often Apache can be restarted much
quicker)
- If Apache fails to stop in 10 seconds (open connections?!), it should
get tried a bit longer (I've chosen 30 seconds for the timeout, but
feel free to adjust it).
diff -u apache2-2.2.8/debian/changelog apache2-2.2.8/debian/changelog
diff -u apache2-2.2.8/debian/apache2.2-common.apache2.init apache2-2.2.8/debian/apache2.2-common.apache2.init
--- apache2-2.2.8/debian/apache2.2-common.apache2.init
+++ apache2-2.2.8/debian/apache2.2-common.apache2.init
@@ -167,10 +167,18 @@
else
log_daemon_msg "Restarting web server" "apache2"
fi
+ APACHE2_PID=$(pidof_apache)
if ! apache_stop; then
log_end_msg 1 || true
fi
- sleep 10
+
+ # Wait until Apache has gone away:
+ MAX_WAIT=300 # 30 seconds
+ while pgrep apache2 | grep -q $APACHE2_PID && [ $MAX_WAIT -gt 0 ]; do
+ sleep 0.1
+ let MAX_WAIT=MAX_WAIT-1
+ done
+
if $APACHE2CTL start; then
if check_htcacheclean ; then
start_htcacheclean || log_end_msg 1
Reply to: