4003ea44fe4190aeb14bf65ab9ccbbfc9908037c
[rusty/ctdb.git] / config / events.d / 62.cnfs
1 #!/bin/sh
2 # event script to integrate with gpfs cnfs
3
4 . $CTDB_BASE/functions
5
6 loadconfig
7
8 STATEDIR=$CTDB_BASE/state/gpfs
9
10
11 # filesystems needed by nfs
12 NFS_FSS=`cat /etc/exports | egrep -v "^#" | sed -e "s/[ \t]*[^ \t]*$//" -e "s/\"//g"`
13
14
15
16 check_if_healthy() {
17         mkdir -p $STATEDIR/fs
18         FS=`(cd $STATEDIR/fs ; ls )`
19         [ -z "$FS" ] || {
20                 MISSING=`echo $FS | sed -e "s/@/\//g"`
21                 logger Filesystems required for NFS are missing. Node is UNHEALTHY. [$MISSING]
22                 $CTDB_BASE/events.d/62.cnfs unhealthy "GPFS filesystems required for NFS are not mounted : [$MISSING]"
23                 exit 0
24         }
25
26         logger All required GPFS resources are available. CNFS part is healthy.
27         $CTDB_BASE/events.d/62.cnfs healthy
28 }
29
30 case "$1" in
31     startup)
32         mkdir -p $STATEDIR
33         check_if_healthy
34         ;;
35
36
37     # This event is called from the GPFS callbacks when a filesystem is
38     # unmounted
39     gpfsumount)
40         # is this a filesystem we need for nfs?
41         echo "$NFS_FSS" | egrep "^$2" >/dev/null || {
42                 # no
43                 exit 0
44         }
45
46         logger "GPFS unmounted filesystem $2 used by NFS. Mark node as UNHEALTHY"
47
48         MFS=`echo $2 | sed -e "s/\//@/g"`
49         mkdir -p $STATEDIR/fs
50         touch "$STATEDIR/fs/$MFS"
51         $CTDB_BASE/events.d/62.cnfs unhealthy "GPFS unmounted filesystem $2 used by NFS"
52         ;;
53
54     # This event is called from the GPFS callbacks when a filesystem is
55     # mounted
56     gpfsmount)
57         # is this a filesystem we need for nfs?
58         echo "$NFS_FSS" | egrep "^$2" >/dev/null || {
59                 # no
60                 exit 0
61         }
62
63         logger "GPFS mounted filesystem $2 used by NFS."
64
65         MFS=`echo $2 | sed -e "s/\//@/g"`
66         mkdir -p $STATEDIR/fs
67         rm -f "$STATEDIR/fs/$MFS"
68
69         check_if_healthy
70         ;;
71
72
73
74     # This event is called from the gpfs callback when GPFS is being shutdown.
75     gpfsshutdown)
76         logger "GPFS is shutting down. Marking node as UNHEALTHY and trigger a CTDB failover"
77         $CTDB_BASE/events.d/62.cnfs unhealthy "GPFS was shut down!"
78         ;;
79
80
81     # This event is called from the gpfs callback when GPFS has started.
82     # It checks that all required NFS filesystems are mounted 
83     # and flags the node healthy if so.
84     gpfsstartup)
85         logger "GPFS is is started."
86         check_if_healthy
87         ;;
88
89
90
91
92
93     unhealthy)
94         # Mark the node as UNHEALTHY which means all public addresses
95         # will be migrated off the node.
96         shift
97         TMPFILE=/tmp/ctdb.cnfs.$$
98         echo "$*" > $TMPFILE
99         ctdb_setstatus unhealthy $TMPFILE
100         rm $TMPFILE
101
102         # force a monitor event so we pick up immediately that this script
103         # will now fail and make the node unhealthy.
104         ctdb eventscript monitor
105
106         # Wait until we no longer serve any ip addresses at all
107         PNN=`ctdb pnn | cut -d: -f2`
108         while `ctdb -Y ip | cut -d: -f3 | egrep "^$PNN$" >/dev/null`; do
109                 sleep 1
110         done
111         ;;
112
113     healthy)
114         # mark the node as healthy
115         ctdb_setstatus healthy
116         ;;
117
118
119     monitor)
120         ctdb_checkstatus
121         exit $?
122         ;;
123
124     *)
125         ctdb_standard_event_handler "$@"
126         ;;
127 esac
128
129 exit 0
130