41.httpd event script workaround for RHEL5-ism.
authorMartin Schwenke <martin@meltin.net>
Mon, 11 May 2009 04:50:28 +0000 (14:50 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 11 May 2009 22:53:32 +0000 (08:53 +1000)
RHEL5 can SIGKILL httpd when stopping it, causing it to leak
semaphores.  This means that eventually a node runs out of semaphores
and httpd can't be started.  So, before we attempt to start httpd we
clean up any semaphores owned by apache.  We also try to restart httpd
in the monitor event if httpd has gone away.

Signed-off-by: Martin Schwenke <martin@meltin.net>
config/events.d/41.httpd

index fae9f47f55e159a21f3a84d0adff226e436233c0..4d8c44008bbd8889acf1692c9545f6466b68315e 100755 (executable)
@@ -34,19 +34,35 @@ loadconfig "${CTDB_CONFIG_HTTP}"
 cmd="$1"
 shift
 
-case $cmd in 
-     startup)
-        service "${CTDB_SERVICE_HTTP}" stop > /dev/null 2>&1
-        service "${CTDB_SERVICE_HTTP}" start
-        ;;
+# RHEL5 sometimes use a SIGKILL to terminate httpd, which then leaks
+# semaphores.  This is a hack to clean them up.
+cleanup_httpd_semaphore_leak() {
+    killall -q -0 "${CTDB_SERVICE_HTTP}" ||
+    for i in $(ipcs -s | awk '$3 == "apache" { print $2 }') ; do
+       ipcrm -s $i
+    done
+}
 
-     shutdown)
-        service "${CTDB_SERVICE_HTTP}" stop
-        ;;
+case $cmd in
+    startup)
+       cleanup_httpd_semaphore_leak
+       service "${CTDB_SERVICE_HTTP}" start
+       ;;
+
+    shutdown)
+       service "${CTDB_SERVICE_HTTP}" stop
+       killall -q -9 "${CTDB_SERVICE_HTTP}"
+       ;;
 
      monitor)
-        ctdb_check_tcp_ports "http" 80
-        ;;
+       ( ctdb_check_tcp_ports "http" 80 )
+       if [ $? -ne 0 ] ; then
+           echo "HTTPD is not running. Trying to restart HTTPD."
+           cleanup_httpd_semaphore_leak
+           service "${CTDB_SERVICE_HTTP}" start
+           exit 1
+       fi
+       ;;
 esac
 
 exit 0