15a35ea1cfad455d68176face856bebd25559065
[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 ; then
56             echo "HTTPD is not running. Trying to restart HTTPD."
57             ctdb_service_start
58             exit 1
59         fi
60         ;;
61
62     *)
63         ctdb_standard_event_handler "$@"
64         ;;
65 esac
66
67 exit 0
68