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