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 # ident "@(#)nfs4red.ksh        1.1     09/04/27 SMI"
  28 #
  29 
  30 NAME=$(basename $0)
  31 
  32 SetDebugMode
  33 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
  34        && set -x
  35 
  36 id | grep "0(root)" > /dev/null 2>&1
  37 if (( $? != 0 )); then
  38         echo "$NAME: This script require root permission to run."
  39         exit 99
  40 fi
  41 
  42 ENVFILE=ENV_from_client
  43 STF_TMPDIR=Tmpdir_from_client
  44 
  45 # source the environment/config file from client to be consistent
  46 . $STF_TMPDIR/$ENVFILE
  47 
  48 NOTICEDIR=$SHRDIR/._Notice__Dir_.
  49 
  50 [[ ! -d $NOTICEDIR ]] && mkdir -m 0777 -p $NOTICEDIR || chmod 0777 $NOTICEDIR
  51 
  52 fmri=svc:/network/nfs/server:default
  53 timeout=10
  54 
  55 # call recov_setserver -r
  56 rm -f ${STF_TMPDIR}/share_restore.log $SHRDIR/shr_r.error $SHRDIR/shr_r.success
  57 /usr/bin/ksh ${STF_TMPDIR}/recov_setserver -r > ${STF_TMPDIR}/share_restore.log 2>&1
  58 if (( $? != 0 )); then
  59         share >> ${STF_TMPDIR}/share_restore.log 2>&1
  60         touch $SHRDIR/shr_r.error
  61         chmod 0777 $SHRDIR/shr_r.error
  62 else
  63         touch $SHRDIR/shr_r.success
  64         chmod 0777 $SHRDIR/shr_r.success
  65 fi
  66 
  67 while :; do
  68         sleep 2
  69         action=$(ls -d $NOTICEDIR/re* 2>/dev/null | nawk -F\/ '{print $NF}')
  70 
  71         case $action in
  72           reset-nfsd)
  73                 echo "Restarting the 'nfsd' in $(uname -n) ..."
  74                 rm -f $NOTICEDIR/DONE_reset
  75                 svcadm disable ${fmri}
  76 
  77                 pkill -x -u 0 nfsd
  78                 sleep 1
  79 
  80                 svcadm enable ${fmri}
  81                 timer=${timeout}
  82                 sleep 2
  83                 /usr/bin/ksh ${STF_TMPDIR}/recov_setserver -r > ${STF_TMPDIR}/share_restore.log 2>&1
  84                 if (( $? != 0 )); then
  85                         echo "failed to re-share" > $NOTICEDIR/DONE_reset
  86                 fi
  87                 i=1
  88                 while (( $i <= $timer )); do
  89                         pgrep nfsd > /dev/null 2>&1
  90                         if (( $? == 0 )); then
  91                                 i="OK"
  92                                 break
  93                         fi
  94                         i=$(($i+1))
  95                         sleep 1
  96                 done
  97                 if [[ "$i" == "OK" ]]; then
  98                         echo "ReSet NFSD($(pgrep nfsd)) started" > $NOTICEDIR/DONE_reset
  99                 else
 100                         echo "ReSet nfsd STF_FAILed" > $NOTICEDIR/DONE_reset
 101                 fi
 102                 ;;
 103           reboot)
 104                 echo "Rebooting $(uname -n), please wait ..."
 105                 rm -f $NOTICEDIR/DONE_reboot
 106                 rm -f $NOTICEDIR/re*
 107                 sync; sync; reboot 
 108                 ;;
 109           requit)
 110                 rm -f $NOTICEDIR/re*
 111                 break;;
 112           *)
 113                 continue;;
 114 
 115         esac
 116         rm -f $NOTICEDIR/re*
 117 done
 118 exit 0