summaryrefslogtreecommitdiffstats
path: root/ctdb/config/events.d/41.httpd
blob: d6e7f9923584693415d387b961aac905e060786f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
# event script to manage httpd in a cluster environment

. $CTDB_BASE/functions
loadconfig ctdb

detect_init_style

case $CTDB_INIT_STYLE in
	redhat)
		CTDB_SERVICE_HTTP="httpd"
		CTDB_CONFIG_HTTP="http"
		;;
	suse)
		CTDB_SERVICE_HTTP="apache2"
		CTDB_CONFIG_HTTP="apache2"
		;;
	debian)
		CTDB_SERVICE_HTTP="apache2"
		CTDB_CONFIG_HTTP="apache2"
		;;
	*)
		# should not happen.
		# for now use red hat style as default
		CTDB_SERVICE_HTTP="httpd"
		CTDB_CONFIG_HTTP="http"
		;;
esac

loadconfig "${CTDB_CONFIG_HTTP}"

[ "$CTDB_MANAGES_HTTPD" = "yes" ] || exit 0

cmd="$1"
shift

# 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
}

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 )
	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