ctdb-eventscripts: Perform share check before NFS RPC checks in 60.ganesha
[Samba.git] / ctdb / config / events.d / 60.ganesha
blob6e7d47df339a34764631a94b047bad2f7998c52e
1 #!/bin/sh
2 # script to manage nfs in a clustered environment
4 [ -n "$CTDB_BASE" ] || \
5 export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD")
7 . $CTDB_BASE/functions
9 GANRECDIR="/var/lib/nfs/ganesha"
10 GANRECDIR2="/var/lib/nfs/ganesha/recevents"
11 GPFS_STATE="/usr/lpp/mmfs/bin/mmgetstate"
12 GANRECDIR3="/var/lib/nfs/ganesha_local"
15 service_start ()
17 startstop_ganesha stop
18 startstop_ganesha start
19 set_proc "sys/net/ipv4/tcp_tw_recycle" 1
22 service_stop ()
24 startstop_ganesha stop
27 service_reconfigure ()
29 # if the ips have been reallocated, we must restart ganesha
30 # across all nodes and ping all statd listeners
31 [ -x $CTDB_BASE/statd-callout ] && {
32 $CTDB_BASE/statd-callout notify &
33 } >/dev/null 2>&1
36 loadconfig "nfs"
39 [ -n "$CTDB_CLUSTER_FILESYSTEM_TYPE" ] || CTDB_CLUSTER_FILESYSTEM_TYPE="gpfs"
41 service_name="nfs-ganesha-$CTDB_CLUSTER_FILESYSTEM_TYPE"
43 [ "${CTDB_NFS_SERVER_MODE:-${NFS_SERVER_MODE}}" = "ganesha" ] || exit 0
45 ctdb_setup_service_state_dir
47 ctdb_start_stop_service
49 is_ctdb_managed_service || exit 0
51 ctdb_service_check_reconfigure
53 get_cluster_fs_state ()
55 case $CTDB_CLUSTER_FILESYSTEM_TYPE in
56 gpfs)
57 STATE=`$GPFS_STATE | awk 'NR <= 3 {next} {printf "%-6s", $3}'`
58 echo $STATE
61 die "File system $CTDB_CLUSTER_FILESYSTEM_TYPE not supported"
63 esac
66 create_ganesha_recdirs ()
68 if [ -z "$(mount -t $CTDB_CLUSTER_FILESYSTEM_TYPE)" ]; then
69 echo "startup $CTDB_CLUSTER_FILESYSTEM_TYPE not ready"
70 exit 1
72 MNTPT=`mount -t $CTDB_CLUSTER_FILESYSTEM_TYPE | sort | awk '{print $3}' | head -n 1`
73 mkdir -p $MNTPT/.ganesha
74 if [ -e $GANRECDIR ]; then
75 if [ ! -L $GANRECDIR ] ; then
76 rm -rf $GANRECDIR
77 if ! ln -s $MNTPT/.ganesha $GANRECDIR ; then
78 echo "ln failed"
81 else
82 if ! ln -sf $MNTPT/.ganesha $GANRECDIR ; then
83 echo "ln failed"
87 mkdir -p $GANRECDIR2
88 mkdir -p $GANRECDIR3
91 monitor_ganesha_nfsd ()
93 create_ganesha_recdirs
94 service_name=${service_name}_process
96 PIDFILE="/var/run/ganesha.pid"
97 CUR_STATE=`get_cluster_fs_state`
98 GANESHA="/usr/bin/$CTDB_CLUSTER_FILESYSTEM_TYPE.ganesha.nfsd"
99 if { read PID < $PIDFILE && \
100 grep "$GANESHA" "/proc/$PID/cmdline" ; } >/dev/null 2>&1 ; then
101 ctdb_counter_init "$service_name"
102 else
103 if [ $CUR_STATE = "active" ]; then
104 echo "Trying fast restart of NFS service"
105 startstop_ganesha restart
106 ctdb_counter_incr "$service_name"
107 ctdb_check_counter "error" "-ge" "6" "$service_name"
111 service_name="nfs-ganesha-$CTDB_CLUSTER_FILESYSTEM_TYPE"_service
112 # check that NFS is posting forward progress
113 if [ $CUR_STATE = "active" -a "$CTDB_NFS_SKIP_KNFSD_ALIVE_CHECK" != "yes" ] ; then
114 MAXREDS=2
115 MAXSTALL=120
116 RESTART=0
118 NUMREDS=`ls $GANRECDIR3 | grep "red" | wc -l`
119 LASTONE=`ls -t $GANRECDIR3 | sed 's/_/ /' | awk 'NR > 1 {next} {printf $1} '`
120 # Beware of startup
121 if [ -z $LASTONE ] ; then
122 LASTONE=`date +"%s"`
124 TNOW=$(date +"%s")
125 TSTALL=$(($TNOW - $LASTONE))
126 if [ $NUMREDS -ge $MAXREDS ] ; then
127 echo restarting because of $NUMREDS red conditions
128 RESTART=1
129 ctdb_counter_incr "$service_name"
130 ctdb_check_counter "error" "-ge" "6" "$service_name"
132 if [ $TSTALL -ge $MAXSTALL ] ; then
133 echo restarting because of $TSTALL second stall
134 RESTART=1
135 ctdb_counter_incr "$service_name"
136 ctdb_check_counter "error" "-ge" "6" "$service_name"
138 if [ $RESTART -gt 0 ] ; then
139 startstop_ganesha restart
140 else
141 ctdb_counter_init "$service_name"
146 ############################################################
148 case "$1" in
149 init)
150 # read statd from persistent database
152 startup)
153 create_ganesha_recdirs
154 ctdb_service_start
157 shutdown)
158 ctdb_service_stop
161 takeip)
162 if [ -n "$2" ] ; then
163 case $CTDB_CLUSTER_FILESYSTEM_TYPE in
164 gpfs)
165 NNUM=`/usr/lpp/mmfs/bin/mmlsconfig myNodeConfigNumber | awk '{print $2}'`
166 TDATE=`date +"%s"`
167 TOUCHTGT=$1"_"$TDATE"_"$NNUM"_"$3"_"$4"_"$2
168 touch $GANRECDIR2/$TOUCHTGT
170 esac
172 ctdb_service_set_reconfigure
175 releaseip)
176 if [ -n "$2" ] ; then
177 case $CTDB_CLUSTER_FILESYSTEM_TYPE in
178 gpfs)
179 NNUM=`/usr/lpp/mmfs/bin/mmlsconfig myNodeConfigNumber | awk '{print $2}'`
180 TDATE=`date +"%s"`
181 TOUCHTGT=$1"_"$TDATE"_"$NNUM"_"$3"_"$4"_"$2
182 touch $GANRECDIR2/$TOUCHTGT
184 esac
186 ctdb_service_set_reconfigure
189 monitor)
190 # Check that directories for shares actually exist.
191 [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
192 grep Path /etc/ganesha/$CTDB_CLUSTER_FILESYSTEM_TYPE.ganesha.exports.conf |
193 cut -f2 -d\" | sort -u | ctdb_check_directories
194 } || exit $?
196 update_tickles 2049
198 # check that statd responds to rpc requests
199 # if statd is not running we try to restart it
200 # we only do this IF we have a rpc.statd command.
201 # For platforms where rpc.statd does not exist, we skip
202 # the check completely
203 p="rpc.statd"
204 which $p >/dev/null 2>/dev/null && \
205 nfs_check_rpc_service "statd" \
206 -ge 6 "verbose unhealthy" \
207 -eq 4 "verbose restart" \
208 -eq 2 "restart:b"
210 if [ "$CTDB_SKIP_GANESHA_NFSD_CHECK" != "yes" ] ; then
211 monitor_ganesha_nfsd
214 # rquotad is sometimes not started correctly on RHEL5
215 # not a critical service so we dont flag the node as unhealthy
216 nfs_check_rpc_service "rquotad" \
217 -gt 0 "verbose restart:b"
221 ctdb_standard_event_handler "$@"
223 esac
225 exit 0