41.HTTPD
[sahlberg/ctdb.git] / config / events.d / 41.httpd
1 #!/bin/sh
2 # event script to manage httpd in a cluster environment
3
4 . $CTDB_BASE/functions
5
6 detect_init_style
7
8 case $CTDB_INIT_STYLE in
9     redhat)
10         service_name="httpd"
11         service_config="http"
12         ;;
13     suse|debian|*)
14         service_name="apache2"
15         service_config="apache2"
16         ;;
17 esac
18
19 # RHEL5 sometimes use a SIGKILL to terminate httpd, which then leaks
20 # semaphores.  This is a hack to clean them up.
21 cleanup_httpd_semaphore_leak() {
22     killall -q -0 "$service_name" ||
23     for i in $(ipcs -s | awk '$3 == "apache" { print $2 }') ; do
24         ipcrm -s $i
25     done
26 }
27
28 ##########
29
30 service_start="cleanup_httpd_semaphore_leak; service $service_name start"
31 service_stop="service $service_name stop; killall -q -9 $service_name || true"
32 service_reconfigure="service $service_name restart"
33
34 loadconfig
35
36 ctdb_start_stop_service
37
38 is_ctdb_managed_service || exit 0
39
40 case "$1" in
41     startup)
42         ctdb_service_start
43         ;;
44
45     shutdown)
46         ctdb_service_stop
47         ;;
48
49     monitor)
50         if ctdb_service_needs_reconfigure ; then
51             ctdb_service_reconfigure
52             exit 0
53         fi
54
55         if ctdb_check_tcp_ports 80 >/dev/null 2>/dev/null ; then
56             ctdb_counter_init
57         else
58             ctdb_counter_incr
59
60             ctdb_check_counter_equal 5 || {
61                 echo "HTTPD is not running. Trying to restart HTTPD."
62                 ctdb_service_stop
63                 ctdb_service_start
64                 exit 0
65             }
66             ctdb_check_counter_limit 10 quiet|| {
67                 echo "HTTPD is not running. Trying to restart HTTPD."
68                 ctdb_service_stop
69                 ctdb_service_start
70                 exit 1
71             }
72         fi
73         ;;
74
75     *)
76         ctdb_standard_event_handler "$@"
77         ;;
78 esac
79
80 exit 0
81