1 #! /usr/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 #
  29 #  script to talk to reboot/restart daemon and check when
  30 #  server is alive again for NFSv4 client recovery tests
  31 #
  32 
  33 . ${STF_SUITE}/include/nfsgen.kshlib
  34 
  35 NAME=$(basename $0)
  36 
  37 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  38 
  39 if (( $# != 1 ))
  40 then
  41         print -u2 "Usage: $0 <reboot|reset-nfsd>"
  42         exit $STF_FAIL
  43 fi
  44 
  45 function resetNfsdOnServer
  46 {
  47         [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
  48                 && set -x
  49 
  50         RUN_CHECK rm -f $MNTDIR/$NOTICEDIR/DONE_* || return $STF_FAIL
  51         RUN_CHECK touch $MNTDIR/$NOTICEDIR/reset-nfsd || return $STF_FAIL
  52         resultfile=$MNTDIR/$NOTICEDIR/DONE_reset
  53         sleep 15
  54 
  55         # check nfsd on SERVER restarted
  56         maxtry=5
  57         i=1
  58         while (( $i <= $maxtry )); do
  59                 if [[ -f $resultfile ]]; then
  60                         grep "started" $resultfile
  61                         if (( $? != 0 )); then
  62                                 cat $resultfile
  63                                 echo "nfsd not started"
  64                                 return $STF_FAIL
  65                         else
  66                                 echo "nfsd started"
  67                                 return $STF_PASS
  68                         fi
  69                 else
  70                         i=$(($i+1))
  71                         sleep 5
  72                 fi
  73         done
  74 
  75         echo "nfsd not started"
  76         return $STF_FAIL
  77 }
  78 
  79 COMMAND=$1
  80 
  81 case $COMMAND in
  82         reboot) touch $MNTDIR/$NOTICEDIR/reboot
  83                 # Ping until down
  84                 wait_now $REBOOTIMER "! ping $rhost 5 > /dev/null 2>&1"
  85                 if (( $? != 0 )); then
  86                         echo "$SERVER did not reboot within $REBOOTIMER seconds"
  87                         exit $STF_FAIL
  88                 fi
  89 
  90                 echo $SERVER is now DEAD
  91 
  92                 # Ping until up
  93                 if /usr/sbin/ping $SERVER $REBOOTIMER >/dev/null 2>&1
  94                 then
  95                     echo $SERVER is now ALIVE
  96                     wait_now 600 "ls $MNTDIR/shr_r.success > /dev/null 2>&1"
  97                     if (( $? != 0 )); then
  98                         echo "SERVER($SERVER) didn't export $SHRDIR whithin 10 mins"
  99                         cat $MNTDIR/share_restore.log
 100                         rm -f $MNTDIR/shr_r.success $MNTDIR/shr_r.error $MNTDIR/share_restore.log
 101                         exit $STF_FAIL
 102                     else
 103                         echo "check SHRDIR:$SHRDIR restore success"
 104                         rm -f $MNTDIR/shr_r.success $MNTDIR/shr_r.error $MNTDIR/share_restore.log
 105                         exit $STF_PASS
 106                     fi
 107                 else
 108                     echo $SERVER never came back up after $REBOOTIMER seconds
 109                     exit $STF_FAIL
 110                 fi
 111                 ;;
 112 
 113         reset-nfsd) 
 114                 resetNfsdOnServer
 115                 exit $?
 116                 ;;
 117                 
 118 *) print -u2 "Invalid command: $COMMAND"
 119 esac
 120 
 121 exit $STF_FAIL