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