auth/credentials: if credentials have principal set, they are not anonymous anymore
[Samba.git] / ctdb / config / nfs-ganesha-callout
blobb66611c84f9a86a04cff3521163a073cb899b498
1 #!/bin/sh
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
10 # a newer callout.
12 # To use this:
14 # * Set CTDB_NFS_CALLOUT in your CTDB configuration to point to this
15 # script
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 ######################################################################
30 # Exit on 1st error
31 set -e
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
39 PROCFS_PATH="/proc"
42 ##################################################
44 usage ()
46 _c=$(basename $0)
47 cat <<EOF
48 usage: $_c { shutdown | startup }
49 $_c { stop | start | check } nfs
50 $_c { releaseip | takeip }
51 $_c { monitor-list-shares }
52 EOF
53 exit 1
57 ##################################################
58 # Basic service stop and start
60 nfs_service="nfs-ganesha-$CTDB_CLUSTER_FILESYSTEM_TYPE"
62 basic_stop ()
64 case "$1" in
65 nfs)
66 service "$nfs_service" stop
69 usage
70 esac
73 basic_start ()
75 case "$1" in
76 nfs)
77 service "$nfs_service" start
80 usage
81 esac
84 ##################################################
85 # "stop" and "start" options for restarting
87 service_stop ()
89 case "$1" in
90 nfs)
91 basic_stop "nfs"
93 nlockmgr)
94 # Do nothing - used by statd-callout
98 usage
99 esac
102 service_start ()
104 case "$1" in
105 nfs)
106 basic_start "nfs"
108 nlockmgr)
109 # Do nothing - used by statd-callout
113 usage
114 esac
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
127 gpfs)
128 /usr/lpp/mmfs/bin/mmgetstate | awk 'NR == 4 { print $3 }'
131 die "File system $CTDB_CLUSTER_FILESYSTEM_TYPE not supported"
133 esac
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"
143 exit 0
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
150 rm -vrf "$GANRECDIR"
151 else
152 _t=$(readlink "$GANRECDIR")
153 if [ "$_t" != "$_link_dst" ] ; then
154 rm -v "$GANRECDIR"
158 # This is not an "else". It also re-creates the link if it was
159 # removed above!
160 if [ ! -e "$GANRECDIR" ]; then
161 ln -sv "$_link_dst" "$GANRECDIR"
164 mkdir -p "$GANRECDIR2"
165 mkdir -p "$GANRECDIR3"
168 service_check ()
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
175 exit 0
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"
184 return 1
187 # Check red conditions against limit
188 _reds_max=2
189 _reds=$(ls $GANRECDIR3 | grep -c "red")
191 if [ $_reds -ge $_reds_max ] ; then
192 echo "Too many red conditions (${_reds}/${_reds_max})"
193 return 1
196 # Check for stall
197 _stall_max=120
198 _now=$(date +"%s")
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)"
204 return 1
207 return 0
210 #-------------------------------------------------
212 get_nodenum ()
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"
221 cat "$_nodenum_file"
224 nfs_releaseip ()
226 case $CLUSTER_FILESYSTEM_TYPE in
227 gpfs)
228 _nnum=$(get_nodenum)
229 _tdate=$(date +"%s")
230 _touchtgt="releaseip_${_tdate}_${_nnum}_${2}_${3}_${1}"
231 touch "${GANRECDIR2}/${_touchtgt}"
232 touch "$GANRECDIR2/my${_touchtgt}"
234 esac
237 nfs_takeip ()
239 case $CLUSTER_FILESYSTEM_TYPE in
240 gpfs)
241 _nnum=$(get_nodenum)
242 _tdate=$(date +"%s")
243 _touchtgt="takeip_${_tdate}_${_nnum}_${2}_${3}_${1}"
244 touch "${GANRECDIR2}/${_touchtgt}"
246 esac
249 ##################################################
250 # service init startup and final shutdown
252 nfs_shutdown ()
254 basic_stop "nfs"
257 nfs_startup ()
259 create_ganesha_recdirs
261 basic_stop "nfs" || true
262 basic_start "nfs"
263 _f="${PROCFS_PATH}/sys/net/ipv4/tcp_tw_recycle"
264 if [ "$_f" ] ; then
265 echo 1 >"$_f"
269 ##################################################
270 # list share directories
272 nfs_monitor_list_shares ()
274 grep Path /etc/ganesha/$CTDB_CLUSTER_FILESYSTEM_TYPE.ganesha.exports.conf |
275 cut -f2 -d\" |
276 sort -u
279 ##################################################
281 action="$1"
282 shift
284 case "$action" in
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
298 usage
299 esac