Debian Codegraph @

ctdb/config/events/legacy/41.httpd.script

raw
1 #!/bin/sh
2 # event script to manage httpd in a cluster environment
3
4 [ -n "$CTDB_BASE" ] || \
5 CTDB_BASE=$(d="$(dirname "$0")" && cd -P "$d/../../" && 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 ;;
15 suse|debian|*)
16 service_name="apache2"
17 ;;
18 esac
19
20 load_script_options
21
22 ctdb_setup_state_dir "service" "$service_name"
23
24 # RHEL5 sometimes use a SIGKILL to terminate httpd, which then leaks
25 # semaphores. This is a hack to clean them up.
26 cleanup_httpd_semaphore_leak() {
27 killall -q -0 "$service_name" ||
28 for i in $(ipcs -s | awk '$3 == "apache" { print $2 }') ; do
29 ipcrm -s "$i"
30 done
31 }
32
33 ##########
34
35 service_start ()
36 {
37 cleanup_httpd_semaphore_leak
38 service $service_name start
39 }
40 service_stop ()
41 {
42 service $service_name stop
43 killall -q -9 $service_name || true
44 }
45
46 case "$1" in
47 startup)
48 service_start
49 ctdb_counter_init
50 ;;
51
52 shutdown)
53 service_stop
54 ;;
55
56 monitor)
57 if ctdb_check_tcp_ports 80 >/dev/null 2>/dev/null ; then
58 ctdb_counter_init
59 else
60 ctdb_counter_incr
61 num_fails=$(ctdb_counter_get)
62 if [ "$num_fails" -eq 2 ] ; then
63 echo "HTTPD is not running. Trying to restart HTTPD."
64 service_stop
65 service_start
66 exit 0
67 elif [ "$num_fails" -ge 5 ] ; then
68 echo "HTTPD is not running. Trying to restart HTTPD."
69 service_stop
70 service_start
71 exit 1
72 fi
73 fi
74 ;;
75 esac
76
77 exit 0
78