source: gpfs_3.1_ker2.6.20/lpp/mmfs/bin/runmmfs @ 111

Last change on this file since 111 was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 13.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. 2000,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# @(#)19 1.32 src/avs/fs/mmfs/ts/admin/runmmfs.sh, mmfs, avs_rgpfs24, rgpfs240610b 10/26/05 19:20:55
17#######################################################################
18#
19# runmmfs is used to start up the GPFS daemon.
20#
21#  Usage: 
22#    runmmfs [options]
23#
24#  where   
25#    options    if specified, passed through to the mmfsenv script.
26#
27#######################################################################
28
29
30#------------------------------------------------------------------------
31# Collect options, if any, to be passed on to mmfsenv.
32#------------------------------------------------------------------------
33mmfsenvOpt=$@
34
35#------------------------------------------------------------------------
36# Decide where to look for the commands.  The normal install directory
37# is /usr/lpp/mmfs/bin.  This can be changed by setting the MMFSDIR
38# environment variable to something other than /usr/lpp/mmfs.
39# If MMFSDIR is not used, before assuming the default install directory,
40# we will check if the mmfs binaries are in the same place where this
41# script resides.  This is a development aid for running out of a build tree.
42#------------------------------------------------------------------------
43if [[ -n $MMFSDIR ]]
44then
45  mmcmdDir="${MMFSDIR}/bin"
46else
47  if [[ -z ${0%%/*} ]]
48  then
49    fullname="$0"
50  else
51    fullname="${PWD%/}/$0"
52  fi
53  progDir=${fullname%/*}
54
55  if [[ -f ${progDir}/mmfs ]]
56  then
57    mmcmdDir="$progDir"
58  else
59    mmcmdDir="/usr/lpp/mmfs/bin"
60  fi
61fi
62
63# Determine the values of mmcmdSubdir and mmcmdSuffix.
64set -f ; set -- $(/bin/uname -a) ; set +f
65osName=$1
66osVersion=$4
67set --
68if [[ -f ${mmcmdDir}/mmfs || $osName != AIX || $osVersion < 5 ]]
69then
70  mmcmdSubdir=""
71  mmcmdSuffix=""
72
73else
74  # Must be running on top of AIX 5.
75  # Determine whether the current kernel is 64-bit.
76  kernelMode=$(${mmcmdDir}/mmkerninfo)
77  if [[ $kernelMode = 64 ]]
78  then
79    mmcmdSubdir="aix64"
80    mmcmdSuffix="64"
81  else
82    mmcmdSubdir="aix32"
83    mmcmdSuffix=""
84  fi
85fi 
86
87# Include global declarations and service routines.
88. ${mmcmdDir}/mmglobfuncs
89. ${mmcmdDir}/mmsdrfsdef
90. ${mmcmdDir}/mmfsfuncs
91
92commandPath=set
93
94sourceFile="runmmfs.sh"
95[[ -n $DEBUG || -n $DEBUGrunmmfs ]] && set -x
96$mmTRACE_ENTER "$*"
97
98
99#------------------------------------------------------------------------
100# Function to catch stop signals issued while we are in this script.
101# The daemon, once started, is responsible for signal handling.
102#------------------------------------------------------------------------
103function sigcatch
104{
105  print "$(date) ${mmcmd}: Received a stop request; exiting"
106  $mmTRACE_EXIT "rc=1  stop request"
107  exit 1
108}
109
110#------------------------------------------------------------------------
111# Set the default sleep backoff to 7 seconds.  This ensures that the
112# first three attempts to start will not occur within 20 seconds.
113#------------------------------------------------------------------------
114(( backoff = 7 ))
115
116#------------------------------------------------------------------------
117# If running under the control of the startup daemon (daemonize command),
118# set up the console output (standout and standerr) files.
119#------------------------------------------------------------------------
120foreground=true
121waittime=20
122
123# DAEMONIZE is set by daemonize command when it execs us
124if [[ -n $DAEMONIZE ]]; then
125
126  #--------------------------------------------------------------
127  # If we were started by daemonize then we are responsible for
128  # restarting mmfsd.  The rerunmmfs file enables that function
129  #--------------------------------------------------------------
130  $touch $rerunmmfsFile
131
132  foreground=false
133
134  #------------------------------------------------------
135  # Find the setting of the logDir mmfs.cfg parameter.
136  # It can be used to override the default log location.
137  #------------------------------------------------------
138  if [[ -f $mmfscfg ]]
139  then
140    logDir=$($awk '$1 == "logDir" {value = $2} END {print value}' $mmfscfg)
141    [[ -n $logDir ]] && rasDir="${logDir}/"
142  fi
143
144  standin="/dev/console"
145  standout="${rasDir}mmfs.log"
146  standerr="${rasDir}mmfs.log"
147  signorm=31
148  sigforce=15
149fi
150   
151#---------------------------------------------------------------------
152# Set the stop request signal handlers.
153# Use the "waittime" value to set the respawn backoff.
154#---------------------------------------------------------------------
155trap sigcatch $signorm $sigforce
156(( backoff = (waittime / 3) + 1 ))
157 
158#------------------------------------------------------------------
159# If we were started by daemonize, then this script may be responsible
160# for respawning mmfsd after a death ($rerunmmfsFile is present).
161#------------------------------------------------------------------
162while true
163do
164   # Move the respawnlog file, if any.
165   $mv "$respawnlog" "$respawnlog2" 2>/dev/null
166
167   if [[ -n $DAEMONIZE ]]; then
168      exec 0<$standin
169      exec 1>$standout
170      exec 2>$standerr
171
172      cd ${mmcmdDir}
173   fi
174
175   print -- "$(date) $mmcmd starting"
176
177   if [[ $foreground = false ]]
178   then 
179      #---------------------------------------------------------------------
180      # Clean out console log files not accessed in the last 11 days.
181      #---------------------------------------------------------------------
182      savepwd="$PWD"
183      if [[ -f "$standout" ]]; then
184         dir="${standout%/*}"
185         base="${standout##*/}"
186         print "Removing old $standout.* files:"
187         if cd "$dir"; then
188            $find . -type f -name "${base}"'.*' -atime +10 -mtime +10 -exec $rm {} \; -print
189         fi
190      fi
191
192      if [[ "$standout" != "$standerr" && -f "$standerr" ]]; then
193         dir="${standerr%/*}"
194         base="${standerr##*/}"
195         print "Removing old $standerr.* files:"
196         if cd "$dir"; then
197            $find . -type f -name "${base}"'.*' -atime +10 -mtime +10 -exec $rm {} \; -print
198         fi
199      fi
200      cd "$savepwd"
201
202      #---------------------------------------------------------------------
203      # Standard out and standard error are opened in non-append mode.  If
204      # standard out and standard error are directed at files, rename the
205      # files, so that on the next restart these files are not overwritten.
206      # Also, re-open the files in append mode.
207      #---------------------------------------------------------------------
208      suffix="$($date +%Y.%m.%d.%H.%M.%S).$($hostname -s)"
209      changeprevious=1
210      if [[ -f "$respawnlog2" ]]; then
211         # When respawning, use previous log file to prevent the directory
212         # from filling up with lots of nearly identical files.
213         if [[ -L "${standout}.latest" ]]; then
214            latest=$($ls -l "${standout}.latest")
215            latest=${latest##*-\> }
216            prefix=$(basename ${standout})
217            latest=${latest#${prefix}.}
218            [[ -n "$latest" ]] && suffix="$latest"
219            changeprevious=0
220         fi
221      fi
222
223      if [[ -f "$standout" ]]; then
224         $cat "$standout" >> "${standout}.${suffix}"
225         $chmod 644 "${standout}.${suffix}"
226         exec 1>>"${standout}.${suffix}"
227         [[ "$standout" = "$standerr" ]] && exec 2>&1
228         $rm "$standout"
229
230         # Create a symbolic link with suffix "latest" to the current log
231         # and suffix "previous" to the previous log.
232         if [[ $changeprevious = 1 ]]; then
233            if [[ -L "${standout}.previous" ]]; then
234               $rm -f "${standout}.previous"
235            else
236               $mv -f "${standout}.previous" "${standout}.previous.save"
237            fi
238            [[ ! -r  "${standout}.previous" ]] && [[ -L "${standout}.latest" ]] && \
239              $mv -f "${standout}.latest" "${standout}.previous"
240         fi
241
242         [[ ! -r  "${standout}.latest" ]] && \
243           $ln -sf $(basename "${standout}.${suffix}") "${standout}.latest"
244         [[ ! -f "${mmsdrfsDir}mmfslog" ]] && \
245           $ln -sf "${standout}.latest" "${mmsdrfsDir}mmfslog"
246      fi
247
248      if [[ "$standout" != "$standerr" && -f "$standerr" ]]; then
249         $cat "$standerr" >> "${standerr}.${suffix}"
250         $chmod 644 "${standerr}.${suffix}"
251         exec 2>>"${standerr}.${suffix}"
252         $rm "$standerr"
253      fi
254   fi  # end of if [[ $foreground = false ]]
255
256   #-------------------------------------------------------------------------
257   # To prevent start/crash loops, this script creates/modifies a file
258   # that keeps a record of how often the MMFS daemon has been respawned
259   # and the daemon has not come up completely due to external influences.
260   # This file is removed by the daemon.
261   #
262   # If the file does not exist, create it with values "0 ${backoff}"; where
263   # the backoff is the initial sleep (default 7 seconds), designed so that
264   # the first three respawns will not occur within 20 seconds.
265   #
266   # If the file already exists, and the sleep we're about to take is less
267   # than 56 seconds, double the time for the next sleep.  If the upcoming
268   # sleep is greater than or equal to 56 seconds but less than 336 seconds,
269   # add another 56 seconds to the next sleep.  If the upcoming sleep is
270   # 336 seconds or more, the next sleep will be the same.  The count of the
271   # number of times we've slept waiting to respawn is always incremented
272   # by one.
273   #
274   # Note: file respawnlog isn't restored until just before an "exit" or
275   # "exec"; until then file respawnlog2 is used.  This helps to prevent
276   # the persistence of the respawn log between stop and start commands.
277   #-------------------------------------------------------------------------
278   if [[ -s "$respawnlog2" ]]; then
279      read count waitPeriod < "$respawnlog2"
280      if [[ $count != +([0-9]) || $waitPeriod != +([0-9]) ]]; then
281        (( count = 1 ))
282        (( waitPeriod = backoff ))
283      else
284        (( count += 1 ))
285      fi
286      if (( waitPeriod < 56 )); then
287         (( newWaitPeriod = waitPeriod * 2 ))
288      elif (( waitPeriod < 336 )); then
289         (( newWaitPeriod = waitPeriod + 56 ))
290      else
291         (( newWaitPeriod = waitPeriod ))
292      fi
293      print ${count} ${newWaitPeriod} > "$respawnlog2"
294      print "$(date) ${mmcmd}: respawn ${count} waiting ${waitPeriod} seconds before restarting mmfsd"
295
296      #---------------------------------------------------------------------
297      # Run the sleep in the background and then wait for it.  This lets
298      # the parent script get signals exactly when they're delivered.
299      # A side effect is that the sleep itself is protected from the signals,
300      # and will continue to run, but a "sleep" process consumes almost no
301      # resources, and will eventually wakeup and exit.
302      #---------------------------------------------------------------------
303      $sleep ${waitPeriod} &
304      wait
305
306   else
307      # file does not exist yet, create it.
308      (( newWaitPeriod = backoff ))
309      print 0 ${newWaitPeriod} > "$respawnlog2"
310
311   fi  # end of if [[ -s "$respawnlog2" ]]
312
313   #------------------------------------------------------
314   # Perform standard initialization.
315   # If something goes wrong, do not bring the daemon up.
316   #------------------------------------------------------
317   $mmfsenv $mmfsenvOpt
318   mmfsenvrc=$?
319   sourceFile="runmmfs.sh"  # restore value after in-line call to mmfsenv
320
321   #---------------------------------------------------------------------------
322   # Now check the return status from "mmfsenv"; if it's bad, restore the
323   # respawnlog file just before the exit and delete any old respawnlog2 files.
324   # If the error is in setting up the kernel extension, give up all together.
325   #---------------------------------------------------------------------------
326   if [[ $mmfsenvrc -eq $MM_KExtFailure ]]; then
327      print "$(date) ${mmcmd}: error in loading or unloading the mmfs kernel extension"
328      print "$(date) ${mmcmd}: stopping GPFS"
329
330      $rm -f "${respawnlog}"* $rerunmmfsFile
331      $mmTRACE_EXIT "rc=$mmfsenvrc  mmfsenv error"
332      exit $mmfsenvrc
333
334   elif [[ $mmfsenvrc != 0 ]]; then
335      print "$(date) ${mmcmd}: error preparing environment for mmfsd"
336      print "$(date) ${mmcmd}: will try again in ${newWaitPeriod} seconds"
337      $mv -f "$respawnlog2" "$respawnlog"
338      $rm -f "${respawnlog}".*
339      $mmTRACE_EXIT "rc=$mmfsenvrc  mmfsenv error"
340
341      # If the rerunmmfsFile is present, go back to the top
342      # of the loop for another iteration.  Otherwise we exit.
343      [[ -n $DAEMONIZE && -f "$rerunmmfsFile" ]] && continue
344
345      $rm -f $rerunmmfsFile
346      exit $mmfsenvrc
347   fi
348
349   #-----------------------------------------------------
350   # Start the MMFS daemon.
351   # Restore the respawnlog file just before the "exec".
352   #-----------------------------------------------------
353   ulimit -d unlimited
354   ulimit -m unlimited
355   ulimit -f unlimited
356   ulimit -t unlimited
357   ulimit -n 1000000   # virtually unlimited while still an acceptable value
358   ulimit -c 1024      # keep core files small
359
360   # Start tracing if the environment variable is set.
361   [[ -n "$MMTRACE" ]] && $mmtrace
362
363   if [[ -n "$MMFSCONFIG" ]]; then
364      MMARGS="-d $MMFSCONFIG"
365   else
366      MMARGS=""
367   fi
368   $mmTRACE "---> Starting GPFS daemon from runmmfs."
369   $mv -f "$respawnlog2" "$respawnlog"
370   $rm -f "${respawnlog}".*
371
372   # If we are spawned by daemonize and $rerunmmfsFile exists,
373   # then we'll be responsible for restarting GPFS.
374   if [[ -n $DAEMONIZE ]]; then
375     $mmfsd $MMARGS
376     rc=$?
377
378     # If rc is 101 (i.e., this daemon discovered a previously-running
379     # incarnation of mmfsd), just get out and do not erase $rerunmmfsFile,
380     # since it belongs to the other instance.
381     [[ $rc = 101 ]] && exit $rc
382
383     # Continue to the beginning of the loop for restart of mmfsd.
384     [[ -f "$rerunmmfsFile" ]] && continue
385     exit
386   fi
387   
388   exec $mmfsd $MMARGS
389
390done
391
Note: See TracBrowser for help on using the repository browser.