ctdb-scripts: Event scripts must end with ".script" suffix
[kai/samba-autobuild/.git] / ctdb / config / events / legacy / 01.reclock.script
1 #!/bin/sh
2 # script to check accessibility to the reclock file on a node
3
4 [ -n "$CTDB_BASE" ] || \
5     CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD")
6
7 . "${CTDB_BASE}/functions"
8
9 load_script_options
10
11 ctdb_setup_state_dir "service" "reclock"
12
13 ctdb_get_reclock_option ()
14 {
15         _reclock_opt_file="${CTDB_SCRIPT_VARDIR}/recovery_lock.cache"
16
17         if [ -f "$_reclock_opt_file" ] ; then
18                 . "$_reclock_opt_file"
19                 return
20         fi
21
22         ctdb_translate_option "cluster" \
23                               "recovery lock" \
24                               "CTDB_RECOVERY_LOCK" >"$_reclock_opt_file"
25
26         . "$_reclock_opt_file"
27 }
28
29 ctdb_get_reclock_option
30
31 # If CTDB_RECOVERY_LOCK specifies a helper then exit because this
32 # script can't do anything useful.
33 case "$CTDB_RECOVERY_LOCK" in
34 !*) exit 0 ;;
35 esac
36
37 case "$1" in
38 init)
39         ctdb_counter_init
40
41         if [ -n "$CTDB_RECOVERY_LOCK" ] ; then
42             d=$(dirname "$CTDB_RECOVERY_LOCK")
43             mkdir -vp "$d"
44         fi
45         ;;
46
47 monitor)
48         # Early exit if not using a reclock file
49         [ -n "$CTDB_RECOVERY_LOCK" ] || exit 0
50
51         # Try to stat the reclock file as a background process so that
52         # we don't block in case the cluster filesystem is unavailable
53         (
54             if stat "$CTDB_RECOVERY_LOCK" ; then
55                 # We could stat the file, reset the counter
56                 ctdb_counter_init
57             fi
58         ) >/dev/null 2>&1 &
59
60         ctdb_counter_incr
61         num_fails=$(ctdb_counter_get)
62         if [ "$num_fails" -ge 200 ] ; then
63             echo "Reclock file \"$CTDB_RECOVERY_LOCK\" can not be accessed. Shutting down."
64             df
65             sleep 1
66             $CTDB shutdown
67             exit 1
68         elif [ "$num_fails" -ge 4 ] ; then
69                 die "ERROR: ${num_fails} consecutive failures checking reclock"
70         fi
71         ;;
72 esac
73
74 exit 0