source: gpfs_3.1_ker2.6.20/lpp/mmfs/bin/mmshutdown @ 16

Last change on this file since 16 was 16, checked in by rock, 16 years ago
  • Property svn:executable set to *
File size: 9.9 KB
Line 
1#!/bin/ksh
2# IBM_PROLOG_BEGIN_TAG
3# This is an automatically generated prolog.
4
5
6
7# Licensed Materials - Property of IBM
8
9# (C) COPYRIGHT International Business Machines Corp. 1999,2006
10# All Rights Reserved
11
12# US Government Users Restricted Rights - Use, duplication or
13# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
14
15# IBM_PROLOG_END_TAG
16# @(#)13 1.3.3.20 src/avs/fs/mmfs/ts/admin/mmshutdown.sh, mmfs, avs_rgpfs24, rgpfs240610b 1/23/06 02:25:22
17##############################################################################
18#
19#  GPFS filesystems on the specified nodes will be unmounted and then
20#  the GPFS daemons on the specified nodes will be shut down.
21#
22#  Usage:
23#
24#    mmshutdown [ -t unmountTimeout ]
25#               [-a | -N {Node[,Node...] | NodeFile | NodeClass}]
26#
27#  where:
28#
29#    -t timeout    Will timeout the unmount command after this amount of time
30#                  and shut the GPFS daemons down anyway.
31#
32#    -a            Stop the daemon on all nodes in the GPFS cluster.
33#
34#    -N Node,Node,...  Specify the nodes to be shut down.
35#    -N NodeFile       NodeClass may be one of several possible node classes
36#    -N NodeClass      (e.g., quorumnodes, managernodes, nsdnodes, etc.)
37#
38#
39#  If not explicitly specified otherwise, the daemon is shut down on the local
40#  node only.
41#
42#
43#  Obsolete options:
44#
45#    -C NodesetId  Start the daemon on all nodes in the specified nodeset.
46#                  Assumed to be the same as -a.
47#
48#    -W NodeFile   Start the daemon on all nodes whose reliable hostnames
49#                  are listed one per line in NodeFilename.
50#                  Cannot be specified with -a, -N, -w, or -n.
51#
52#    -w nodenames  Start the daemon on all nodes whose reliable hostnames
53#                  are in the comma-separated nodenames list.
54#                  Cannot be specified with -a, -N or -W.
55#                  If both -w and -n are specified, the lists are combined.
56#
57#    -n nodenums   Start the daemon on all nodes whose node numbers are
58#                  in the comma-separated nodenums list.
59#                  Cannot be specified with -a, -N, or -W.
60#                  If both -w and -n are specified, the lists are combined.
61#
62##############################################################################
63
64# Include global declarations and service routines.
65. /usr/lpp/mmfs/bin/mmglobfuncs
66. /usr/lpp/mmfs/bin/mmsdrfsdef
67
68sourceFile="mmshutdown.sh"
69[[ -n $DEBUG || -n $DEBUGmmshutdown ]] && set -x
70$mmTRACE_ENTER "$*"
71
72
73# Local variables
74usageMsg=246
75typeset -i maxTimeout=900
76typeset -i timeout=0
77typeset -i nodes=0
78rc=0
79
80
81#######################
82# Mainline processing
83#######################
84
85
86##################################
87# Process each of the arguments.
88##################################
89[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \
90  syntaxError "help" $usageMsg
91
92while getopts :aC:n:N:t:W:w: OPT
93do
94  case $OPT in
95
96    a) [[ -n $aflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
97       aflag="-$OPT"
98       [[ -n $Cflag || -n $Wflag || -n $wflag || -n $nflag || -n $Nflag ]] &&  \
99         syntaxError "invalidCombination"  \
100           $usageMsg $aflag $Cflag $Wflag $wflag $nflag $Nflag
101       callGpfsInit=yes
102       ;;
103
104    C) # syntaxError "obsoleteOption" $usageMsg "-$OPT"
105       [[ -n $Cflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
106       Cflag="-$OPT"
107       nodesetId="$OPTARG"
108       [[ -n $aflag || -n $Wflag || -n $wflag || -n $nflag || -n $Nflag ]] &&  \
109         syntaxError "invalidCombination"  \
110           $usageMsg $Cflag $aflag $Wflag $wflag $nflag $Nflag
111       callGpfsInit=yes
112       ;;
113
114    n) [[ -n $nflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
115       nflag="-$OPT"
116       nodenums="$OPTARG"
117       [[ -n $Cflag || -n $Wflag || -n $aflag || -n $Nflag ]] &&  \
118         syntaxError "invalidCombination"  \
119           $usageMsg $nflag $Cflag $Wflag $aflag $Nflag
120       callGpfsInit=yes
121       ;;
122
123    N) [[ -n $Nflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
124       Nflag="-$OPT"
125       nodenames="$OPTARG"
126       [[ -n $Cflag || -n $Wflag || -n $aflag || -n $nflag || -n $wflag ]] &&  \
127         syntaxError "invalidCombination"  \
128           $usageMsg $Nflag $Cflag $Wflag $aflag $nflag $wflag
129       callGpfsInit=yes
130       ;;
131
132    t) [[ -n $tflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
133       tflag="-$OPT"
134       timeout=$(checkIntRange $tflag $OPTARG)
135       [[ $? -ne 0 ]] && cleanupAndExit
136       ;;
137
138    W) [[ -n $Wflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
139       Wflag="-$OPT"
140       Wcoll="$OPTARG"
141       [[ -n $Cflag || -n $aflag || -n $wflag || -n $nflag || -n $Nflag ]] &&  \
142         syntaxError "invalidCombination"  \
143           $usageMsg $Wflag $Cflag $aflag $wflag $nflag $Nflag
144       ;;
145
146    w) [[ -n $wflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
147       wflag="-$OPT"
148       nodenames="$OPTARG"
149       [[ -n $Cflag || -n $Wflag || -n $aflag || -n $Nflag ]] &&  \
150         syntaxError "invalidCombination"  \
151           $usageMsg $wflag $Cflag $Wflag $aflag $Nflag
152       ;;
153
154    :) syntaxError "missingValue" $usageMsg $OPTARG
155       ;;
156
157    +[aCnNtwW])
158       syntaxError "invalidOption" $usageMsg "$OPT"
159       ;;
160
161    *) syntaxError "invalidOption" $usageMsg $OPTARG
162       ;;
163
164  esac
165done  # end of while getopts :aC:n:N:t:W:w: OPT do
166
167shift OPTIND-1
168[[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1
169
170# Rather than fail, convert the obsolete -C option to -a.
171[[ -n $Cflag ]] && aflag="-a"
172
173
174###########################################################################
175# Set up trap exception handling and call the gpfsInit function if needed.
176# It will ensure that the local copy of the mmsdrfs and the rest of the
177# GPFS system files are up-to-date.  There is no need to lock the sdr.
178# Note: There is no need to call gpfsInit if we are trying to quickly
179#       shut down the daemon on the local node only.
180###########################################################################
181trap pretrap2 HUP INT QUIT KILL
182if [[ -n $callGpfsInit ]]
183then
184  gpfsInitOutput=$(gpfsInit nolock)
185  setGlobalVar $? $gpfsInitOutput
186fi
187
188
189#######################################################
190# Create a file containing all of the specified nodes.
191#######################################################
192if [[ -n $aflag ]]
193then
194  # Get a list of the nodes.
195  getNodeList $REL_HOSTNAME_Field $GLOBAL_ID $mmsdrfsFile > $nodefile
196
197elif [[ -n $Nflag ]]
198then
199  # Convert the passed data into a file containing admin node names.
200  createVerifiedNodefile $nodenames $REL_HOSTNAME_Field no $nodefile
201  [[ $? -ne 0 ]] && cleanupAndExit
202
203elif [[ -n $Wflag ]]
204then
205  # Verify the input file is readable.
206  if [[ ! -f $Wcoll || ! -r $Wcoll ]]
207  then
208    printErrorMsg 43 $mmcmd $Wcoll
209    cleanupAndExit
210  fi
211
212  # Filter out comment lines and localhost entries.
213  $grep -v -e "localhost" -e "^#" "$Wcoll" > $tmpfile
214
215  # Convert any entries in the node file into admin node names.
216  if [[ -s $tmpfile ]]
217  then
218    createVerifiedNodefile $tmpfile $REL_HOSTNAME_Field no $nodefile
219    [[ $? -ne 0 ]] && cleanupAndExit
220  else
221    # No node names were specified.
222    printErrorMsg 328 $mmcmd $Wcoll
223    cleanupAndExit
224  fi
225
226else
227  # Either no option was specified, or we have some combination of -w and -n.
228
229  # Convert the node names list (if any) into a file.
230  $rm -f $tmpfile
231  if [[ -n $nodenames ]]
232  then
233    for i in $(print $nodenames | $tr "," " ")
234    do
235      print -- "$i" >> $tmpfile
236    done
237  fi
238
239  # Append the node number list (if any) to the node file.
240  if [[ -n $nodenums ]]
241  then
242    for i in $(print $nodenums | $tr "," " ")
243    do
244      print -- "$i" >> $tmpfile
245    done
246  fi
247
248  # Convert the entries in the node file into admin node names.
249  if [[ -s $tmpfile ]]
250  then
251    createVerifiedNodefile $tmpfile $REL_HOSTNAME_Field no $nodefile
252    [[ $? -ne 0 ]] && cleanupAndExit
253  fi
254
255fi  # end of if [[ -n $aflag ]]
256
257# Determine the number of nodes that are affected by the command.
258[[ -s $nodefile ]] && nodes=$($cat $nodefile | $wc -l)
259
260# If a timeout value was not set, estimate one.
261if [[ $timeout = 0 ]]
262then
263  (( timeout = 60 + 3 * nodes ))
264  [[ $nodes -gt 500 ]] &&  \
265    (( maxTimeout = maxTimeout + nodes / 500 * 300 ))
266  [[ $timeout -gt $maxTimeout ]] && timeout=$maxTimeout
267fi
268
269# Ensure we have the proper credentials.
270[[ $getCredCalled = no ]] && getCred
271
272
273################################
274# Unmount the GPFS filesystems.
275################################
276
277# Starting force unmount ...
278printInfoMsg 241 "$(date)" $mmcmd
279
280if [[ ! -s $nodefile ]]
281then
282  # Unmount the gpfs file systems on the local node only.
283  $mmremote unmountFileSystems all -f  &
284  pid=$!
285else
286  # Unmount the gpfs file systems on a number of nodes.
287  $mmcommon onall $nodefile $unreachedNodes unmountFileSystems all -f  &
288  pid=$!
289fi
290
291# Wait until the unmount command finishes or the timeout expires.
292waited=0
293mincount=0
294retrydelay=5
295while [[ $waited -lt $timeout ]]
296do
297  $sleep $retrydelay
298  (( waited = waited + retrydelay ))
299  (( mincount = mincount + retrydelay ))
300
301  if ! kill -0 $pid 2>/dev/null
302  then
303    # unmount finished.
304    waited=-1
305    break
306  fi
307
308  if [[ $mincount -ge 60 ]]
309  then
310    (( togo = timeout - waited ))
311    mincount=0
312    printInfoMsg 242 "$(date)" $mmcmd $waited $togo
313  fi
314done  # while [[ $waited -lt $timeout ]]
315
316# Inform the user if the unmount did not finish.
317[[ $waited -gt 0 ]] &&  \
318  printInfoMsg 243 "$(date)" $mmcmd $waited
319
320
321##############################
322# Shut down the GPFS daemons.
323##############################
324printInfoMsg 244 "$(date)" $mmcmd
325
326if [[ ! -s $nodefile ]]
327then
328  # Shut down GPFS on the local node only.
329  $mmremote shutdownDaemon
330  rc=$?
331else
332  # Shut down GPFS on a number of nodes.
333  $mmcommon onall $nodefile $unreachedNodes shutdownDaemon
334  rc=$?
335fi
336
337# If any nodes could not be reached, tell the user which ones.
338if [[ -s $unreachedNodes ]]
339then
340  # The following nodes could not be reached: . . .
341  printErrorMsg 270 $mmcmd
342  $cat $unreachedNodes 1>&2
343fi
344
345# All finished.
346printInfoMsg 245 "$(date)" $mmcmd
347
348cleanupAndExit $rc
349
Note: See TracBrowser for help on using the repository browser.