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 2006 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 #  script to talk to reboot/restart daemon and check when
  28 #  server is alive again for NFSv4 client recovery tests
  29 #
  30 
  31 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  32 
  33 NAME=`basename $0`
  34 
  35 if (( $# != 1 ))
  36 then
  37         print -u2 "Usage: $0 <reboot|reset-nfsd>"
  38         exit 1
  39 fi
  40 
  41 COMMAND=$1
  42 
  43 case $COMMAND in
  44         reboot) touch $MNTPTR/$NOTICEDIR/reboot
  45                 # Ping until down
  46                 COUNTER=1
  47                 while /usr/sbin/ping $SERVER 5 >/dev/null 2>&1
  48                 do
  49                     echo $SERVER is still alive
  50                     if (( COUNTER == $REBOOTIMER ))
  51                     then
  52                         echo $SERVER did not reboot within $REBOOTIMER seconds
  53                         exit 1
  54                     else
  55                         sleep 1
  56                         (( COUNTER += 1 ))
  57                     fi
  58                 done
  59 
  60                 echo $SERVER is now DEAD
  61 
  62                 # Ping until up
  63                 if /usr/sbin/ping $SERVER $REBOOTIMER >/dev/null 2>&1
  64                 then
  65                     echo $SERVER is now ALIVE
  66                     exit 0
  67                 else
  68                     echo $SERVER never came back up after $REBOOTIMER seconds
  69                     exit 1
  70                 fi
  71                 ;;
  72 
  73         reset-nfsd) touch $MNTPTR/$NOTICEDIR/reset-nfsd
  74                 sleep 10
  75                 loop=0
  76 
  77                 touch $TMPDIR/isserverup.out.$$
  78                 while (( loop < 10 ))
  79                 do
  80                 rsh -n $SERVER pgrep nfsd > $TMPDIR/isserverup.out.$$
  81 
  82                 if [ -s $TMPDIR/isserverup.out.$$ ]
  83                 then
  84                         echo nfsd started
  85                         exit 0
  86                 else
  87                         echo nfsd not started
  88                 fi
  89                 ((loop += 1)) 
  90                 done
  91                     # make sure nfsd is running
  92                 ;;
  93 *) print -u2 "Invalid command: $COMMAND"
  94 esac
  95 
  96 exit 0