3 # This is an example CTDB NFS callout script for Ganesha. It is based
4 # on the last version of 60.ganesha shipped with CTDB. As such, it
5 # does not try to monitor RPC services that were not monitored by
6 # 60.ganesha - this might be a useful improvement. It has also not
7 # been properly tested.
9 # You should check your version of NFS Ganesha to see if it ships with
14 # * Set CTDB_NFS_CALLOUT in your CTDB configuration to point to this
17 # * Rename nfs-checks.d/{20.nfs.check,30.nlockmgr.check,50.mountd.check}
18 # so that they no longer have the ".check" suffix
20 # * Rename nfs-checks.d/20.nfs-ganesha.disabled to nfs-checks.d/20.nfs.check
22 # I (Martin Schwenke) hereby relicense all of my contributions to this
23 # callout (and, previously, to 60.ganesha) to a license compatible
24 # with NFS Ganesha (right now this is LGPLv3, but I'm flexible).
25 # There may be other contributions to be considered for relicensing,
26 # particularly those in commit 28cbe527d47822f870e8252495ab2a1c8fddd12f.
28 ######################################################################
33 if [ -z "$CTDB_CLUSTER_FILESYSTEM_TYPE" ] ; then
34 CTDB_CLUSTER_FILESYSTEM_TYPE
="gpfs"
37 # Override for unit testing
38 if [ -z "$PROCFS_PATH" ] ; then
42 ##################################################
48 usage: $_c { shutdown | startup }
49 $_c { stop | start | check } nfs
50 $_c { releaseip | takeip }
51 $_c { monitor-list-shares }
57 ##################################################
58 # Basic service stop and start
60 nfs_service
="nfs-ganesha-$CTDB_CLUSTER_FILESYSTEM_TYPE"
66 service
"$nfs_service" stop
77 service
"$nfs_service" start
84 ##################################################
85 # "stop" and "start" options for restarting
94 # Do nothing - used by statd-callout
109 # Do nothing - used by statd-callout
117 ##################################################
118 # Nitty gritty - monitoring and IP handling
120 GANRECDIR
="/var/lib/nfs/ganesha"
121 GANRECDIR2
="/var/lib/nfs/ganesha/recevents"
122 GANRECDIR3
="/var/lib/nfs/ganesha_local"
124 get_cluster_fs_state
()
126 case $CTDB_CLUSTER_FILESYSTEM_TYPE in
128 /usr
/lpp
/mmfs
/bin
/mmgetstate |
awk 'NR == 4 { print $3 }'
131 die
"File system $CTDB_CLUSTER_FILESYSTEM_TYPE not supported"
136 create_ganesha_recdirs
()
138 [ -n "$CTDB_GANESHA_REC_SUBDIR" ] || CTDB_GANESHA_REC_SUBDIR
=".ganesha"
140 _mounts
=$
(mount
-t $CTDB_CLUSTER_FILESYSTEM_TYPE)
141 if [ -z "$_mounts" ]; then
142 echo "startup $CTDB_CLUSTER_FILESYSTEM_TYPE not ready"
145 _mntpt
=$
(echo "$_mounts" |
sort |
awk 'NR == 1 {print $3}')
146 _link_dst
="${_mntpt}/${CTDB_GANESHA_REC_SUBDIR}"
147 mkdir
-vp "$_link_dst"
148 if [ -e "$GANRECDIR" ]; then
149 if [ ! -L "$GANRECDIR" ] ; then
152 _t
=$
(readlink
"$GANRECDIR")
153 if [ "$_t" != "$_link_dst" ] ; then
158 # This is not an "else". It also re-creates the link if it was
160 if [ ! -e "$GANRECDIR" ]; then
161 ln -sv "$_link_dst" "$GANRECDIR"
164 mkdir
-p "$GANRECDIR2"
165 mkdir
-p "$GANRECDIR3"
170 create_ganesha_recdirs
172 # Always succeed if cluster filesystem is not active
173 _cluster_fs_state
=$
(get_cluster_fs_state
)
174 if [ $_cluster_fs_state != "active" ] ; then
178 # Check that NFS Ganesha is running, according to PID file
179 _pidfile
="/var/run/ganesha.pid"
180 _ganesha
="/usr/bin/$CTDB_CLUSTER_FILESYSTEM_TYPE.ganesha.nfsd"
181 if ! { read _pid
< "$_pidfile" && \
182 grep "$_ganesha" "${PROCFS_PATH}/${_pid}/cmdline" ; } >/dev/null 2>&1 ; then
183 echo "ERROR
: NFS Ganesha not running according to PID
file"
187 # Check red conditions against limit
189 _reds=$(ls $GANRECDIR3 | grep -c "red
")
191 if [ $_reds -ge $_reds_max ] ; then
192 echo "Too many red conditions
(${_reds}/${_reds_max})"
199 _last=$(ls -t $GANRECDIR3 | sed -n -e '1s@_.*@@p')
200 [ -n $_last ] || _last=$_now # Handle startup
201 _stall=$(($_now - $_last))
202 if [ $_stall -ge $_stall_max ] ; then
203 echo "ERROR
: Stalled
for ${_stall} second
(s
)"
210 #-------------------------------------------------
214 _nodenum_file="${GANRECDIR}/gpfs_nodenum
"
216 if [ ! -f "$_nodenum_file" ]; then
217 /usr/lpp/mmfs/bin/mmlsconfig myNodeConfigNumber |
218 awk '{print $2}' >"$_nodenum_file"
226 case $CLUSTER_FILESYSTEM_TYPE in
230 _touchtgt="releaseip_
${_tdate}_${_nnum}_${2}_${3}_${1}"
231 touch "${GANRECDIR2}/${_touchtgt}"
232 touch "$GANRECDIR2/my
${_touchtgt}"
239 case $CLUSTER_FILESYSTEM_TYPE in
243 _touchtgt="takeip_
${_tdate}_${_nnum}_${2}_${3}_${1}"
244 touch "${GANRECDIR2}/${_touchtgt}"
249 ##################################################
250 # service init startup and final shutdown
259 create_ganesha_recdirs
261 basic_stop "nfs
" || true
263 _f="${PROCFS_PATH}/sys
/net
/ipv
4/tcp_tw_recycle
"
269 ##################################################
270 # list share directories
272 nfs_monitor_list_shares ()
274 grep Path /etc/ganesha/$CTDB_CLUSTER_FILESYSTEM_TYPE.ganesha.exports.conf |
279 ##################################################
285 shutdown) nfs_shutdown ;;
286 startup) nfs_startup ;;
287 stop) service_stop "$1" ;;
288 start) service_start "$1" ;;
289 check) service_check "$1" ;;
290 releaseip) nfs_releaseip "$@
" ;;
291 takeip) nfs_takeip "$@
" ;;
292 monitor-list-shares) nfs_monitor_list_shares ;;
293 register|monitor-pre|monitor-post)
294 # Not required/implemented