TMP: add a ctdb snapshot of current ctdb master (git://git.samba.org/ctdb.git) to...
[obnox/samba/samba-obnox.git] / ctdb / 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 ()
31 {
32     cleanup_httpd_semaphore_leak
33     service $service_name start
34 }
35 service_stop ()
36 {
37     service $service_name stop
38     killall -q -9 $service_name || true
39 }
40
41 loadconfig
42
43 ctdb_start_stop_service
44
45 is_ctdb_managed_service || exit 0
46
47 ctdb_service_check_reconfigure
48
49 case "$1" in
50     startup)
51         ctdb_service_start
52         ;;
53
54     shutdown)
55         ctdb_service_stop
56         ;;
57
58     monitor)
59         if ctdb_check_tcp_ports 80 >/dev/null 2>/dev/null ; then
60             ctdb_counter_init
61         else
62             ctdb_counter_incr
63
64             ctdb_check_counter warn -eq 2 || {
65                 echo "HTTPD is not running. Trying to restart HTTPD."
66                 service_stop
67                 service_start
68                 exit 0
69             }
70             ctdb_check_counter warn -ge 5 || {
71                 echo "HTTPD is not running. Trying to restart HTTPD."
72                 service_stop
73                 service_start
74                 exit 1
75             }
76         fi
77         ;;
78
79     *)
80         ctdb_standard_event_handler "$@"
81         ;;
82 esac
83
84 exit 0
85