ctdb-scripts: Quote some variable expansions
[nivanova/samba-autobuild/.git] / ctdb / config / events.d / 01.reclock
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 loadconfig
10
11 # If CTDB_RECOVERY_LOCK specifies a helper then exit because this
12 # script can't do anything useful.
13 case "$CTDB_RECOVERY_LOCK" in
14 !*) exit 0 ;;
15 esac
16
17 case "$1" in
18     init)
19         ctdb_counter_init
20
21         if [ -n "$CTDB_RECOVERY_LOCK" ] ; then
22             d=$(dirname "$CTDB_RECOVERY_LOCK")
23             mkdir -vp "$d"
24         fi
25         ;;
26
27     monitor)
28         # Early exit if not using a reclock file
29         [ -n "$CTDB_RECOVERY_LOCK" ] || exit 0
30
31         # Try to stat the reclock file as a background process so that
32         # we don't block in case the cluster filesystem is unavailable
33         (
34             if stat "$CTDB_RECOVERY_LOCK" ; then
35                 # We could stat the file, reset the counter
36                 ctdb_counter_init
37             fi
38         ) >/dev/null 2>&1 &
39
40         ctdb_counter_incr
41         if ! ctdb_check_counter "quiet" -ge 200 ; then
42             echo "Reclock file \"$CTDB_RECOVERY_LOCK\" can not be accessed. Shutting down."
43             df
44             sleep 1
45             $CTDB shutdown
46         fi
47
48         ctdb_check_counter "error" -gt 3
49         ;;
50
51     *)
52         ctdb_standard_event_handler "$@"
53         ;;
54 esac
55
56 exit 0