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 the following files in nfs-checks.d so that they no longer
18 # have the ".check" suffix:
25 # * Install 20.nfs-ganesha.check to nfs-checks.d/20.nfs.check
27 # * It is recommended, but not required, to install the grace_period
28 # script (usually shipped in a utils package for NFS-Ganesha) to
29 # /usr/bin/grace_period
31 # I (Martin Schwenke) hereby relicense all of my contributions to this
32 # callout (and, previously, to 60.ganesha) to a license compatible
33 # with NFS Ganesha (right now this is LGPLv3, but I'm flexible).
34 # There may be other contributions to be considered for relicensing,
35 # particularly those in commit 28cbe527d47822f870e8252495ab2a1c8fddd12f.
37 ######################################################################
42 # Filesystem type and mount point for the (typically clustered)
43 # volume that will contain the NFS-Ganesha state.
44 state_fs
="${CTDB_NFS_STATE_FS_TYPE:-gpfs}"
45 state_dir
="${CTDB_NFS_STATE_MNT}" # No sane default.
47 # To change the following, edit the default values below. Do not set
48 # these - they aren't configuration variables, just hooks for testing.
49 nfs_exports_file
="${CTDB_NFS_EXPORTS_FILE:-/etc/ganesha/ganesha.conf}"
50 nfs_service
="${CTDB_NFS_SERVICE:-nfs-ganesha}"
51 ganesha_rec_subdir
=${CTDB_GANESHA_REC_SUBDIR:-.ganesha}
52 procfs
=${PROCFS_PATH:-/proc}
56 GANRECDIR
="/var/lib/nfs/ganesha"
59 if [ -z "${state_dir}" ]; then
60 echo "CTDB_NFS_STATE_MNT not defined for GlusterFS"
64 NODESTATEDIR
="$state_dir/nfs-ganesha/$host"
65 GANSTATEDIR
="$state_dir/nfs-ganesha/.noderefs"
66 NODESTATELN
="$GANSTATEDIR/$host"
71 ##################################################
77 usage: $_c { shutdown | startup }
78 $_c { stop | start | check } nfs
79 $_c { releaseip | takeip }
80 $_c { monitor-list-shares }
86 ##################################################
87 # Basic service stop and start
93 service
"$nfs_service" stop
104 service
"$nfs_service" start
111 ##################################################
112 # "stop" and "start" options for restarting
121 # Do nothing - used by statd-callout
136 # Do nothing - used by statd-callout
144 ##################################################
145 # Nitty gritty - monitoring and IP handling
147 # Check that a symlink exists, create it otherwise.
148 # Usage: check_ln <TARGET> <LINK>
151 if [ ! -L "${2}" ] ; then
154 _t
=$
(readlink
"${2}")
155 if [ "$_t" != "${1}" ] ; then
159 # This is not an "else". It also re-creates the link if it was
161 if [ ! -e "${2}" ]; then
162 ln -sfv "${1}" "${2}"
166 # Return 'active' if the shared filesystem is accessible.
167 get_cluster_fs_state
()
171 /usr
/lpp
/mmfs
/bin
/mmgetstate |
awk 'NR == 4 { print $3 }'
174 # Since we're past create_ganesha_recdirs(), we're active.
178 echo "File system $state_fs not supported"
184 create_ganesha_recdirs
()
186 if ! _mounts
=$
(mount |
grep $state_fs); then
187 echo "Failed to find mounts of type $state_fs"
190 if [ -z "$_mounts" ]; then
191 echo "startup $state_fs not ready"
197 _mntpt
=$
(echo "$_mounts" |
sort |
awk 'NR == 1 {print $3}')
198 _link_dst
="${_mntpt}/${ganesha_rec_subdir}"
199 mkdir
-vp "$_link_dst"
200 check_ln
"$_link_dst" "$GANRECDIR"
203 [ -d /var
/lib
/nfs.backup
] ||
mv /var
/lib
/nfs
/var
/lib
/nfs.backup
204 check_ln
${NODESTATEDIR} /var
/lib
/nfs
206 mkdir
-p ${NODESTATEDIR}/ganesha
/v4recov
207 mkdir
-p ${NODESTATEDIR}/ganesha
/v4old
208 mkdir
-p ${NODESTATEDIR}/statd
/sm
209 mkdir
-p ${NODESTATEDIR}/statd
/sm.bak
210 touch ${NODESTATEDIR}/state
211 touch ${NODESTATEDIR}/statd
/state
213 mkdir
-p ${GANSTATEDIR}
214 check_ln
${NODESTATEDIR} ${NODESTATELN}
215 for node
in `ls ${GANSTATEDIR}`; do
216 if [ "${node}" != "${host}" ]; then
217 check_ln
${GANSTATEDIR}/${node}/ganesha ${NODESTATEDIR}/ganesha/${node}
218 check_ln
${GANSTATEDIR}/${node}/statd ${NODESTATEDIR}/statd/${node}
227 create_ganesha_recdirs
229 # Always succeed if cluster filesystem is not active
230 _cluster_fs_state
=$
(get_cluster_fs_state
)
231 if [ $_cluster_fs_state != "active" ] ; then
235 # Check that NFS Ganesha is running, according to PID file
236 _pidfile
="/var/run/ganesha.pid"
237 _ganesha
="/usr/bin/ganesha.nfsd"
238 if ! { read _pid
< "$_pidfile" && \
239 grep "$_ganesha" "${procfs}/${_pid}/cmdline" ; } >/dev/null 2>&1 ; then
240 echo "ERROR
: NFS Ganesha not running according to PID
file"
247 #-------------------------------------------------
251 if [ -x "/usr
/bin
/grace_period
" ]; then
252 /usr/bin/grace_period "2:${2}"
254 dbus-send --print-reply --system --dest=org.ganesha.nfsd \
255 /org/ganesha/nfsd/admin org.ganesha.nfsd.admin.grace \
264 check_ln ${NODESTATEDIR} ${GANSTATEDIR}/${2}
267 if [ -x "/usr
/bin
/grace_period
" ]; then
268 /usr/bin/grace_period "5:${2}"
270 dbus-send --print-reply --system --dest=org.ganesha.nfsd \
271 /org/ganesha/nfsd/admin org.ganesha.nfsd.admin.grace \
276 ##################################################
277 # service init startup and final shutdown
286 basic_stop "nfs
" || true
288 create_ganesha_recdirs
291 _f="${procfs}/sys
/net
/ipv
4/tcp_tw_recycle
"
297 ##################################################
298 # list share directories
300 nfs_monitor_list_shares ()
302 grep Path $nfs_exports_file |
307 ##################################################
323 ##################################################
329 shutdown) nfs_shutdown ;;
330 startup) nfs_startup ;;
331 stop) service_stop "$1" ;;
332 start) service_start "$1" ;;
333 check) service_check "$1" ;;
334 releaseip) nfs_releaseip "$@
" ;;
335 takeip) nfs_takeip "$@
" ;;
336 monitor-list-shares) nfs_monitor_list_shares ;;
337 register) nfs_register ;;
338 monitor-pre|monitor-post)
339 # Not required/implemented