#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2005,2007 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 

# "@(#)95   1.4   src/csm/hw/hs/restartHDWR_SVR, csm.hardware, csm_rfish, rfishs001b 4/20/05 18:18:27"

# disable this restart func right now because HMC people against 
# dynamically change between cluster mode and standalone mode

exit 0

#this scritp will be called because of reg_peer_event
#The peer domain is defined on the local hmc (ERRM_RSRC_TYPE=1 ERRM_VALUE=2)
#The peer domain is started on the local hmc (ERRM_RSRC_TYPE=0 ERRM_VALUE=1)
#The peer domain is stopped on the local hmc (ERRM_RSRC_TYPE=0 ERRM_VALUE=2)
#The peer domain is removed on the local hmc (ERRM_RSRC_TYPE2) ( with -u turn on in reg_peer_event)

echo `date` >> /var/hsc/log/reg_peer_event.out
if [[ $ERRM_RSRC_TYPE != 0 ]]
then 
    echo Not the started or stopped event >> /var/hsc/log/reg_peer_event.out 
fi

echo ERRM_VALUE is $ERRM_VALUE >> /var/hsc/log/reg_peer_event.out 

if [[ $ERRM_VALUE != 1 || $ERRM_VALUE != 2 ]]
then 
    echo Unknown ERRM_VALUE >> /var/hsc/log/reg_peer_event.out 
fi

echo "attempting to restart hdwr_svr."
/usr/bin/stopsrc -s hdwr_svr

#
# Make sure hdwr_svr has stopped. It will most likely stop within 20
# seconds, if not sooner.
#
subsys_checked=0
hdwr_svr_stopped=`LC_ALL=C /usr/bin/lssrc -s hdwr_svr | /bin/grep inoperative`
rc=$?

while [[ $rc != 0 && $subsys_checked -lt 20 ]]
do
    ((subsys_checked=$subsys_checked+1))
    sleep 1
    hdwr_svr_stopped=`LC_ALL=C /usr/bin/lssrc -s hdwr_svr | /bin/grep inoperative`
    rc=$?
done

if [[ $subsys_checked = 20 ]]
  then

  if [[ -n `LC_ALL=C /usr/bin/lssrc -s hdwr_svr | /bin/grep active` ]]
  then
     echo "Unable to stop hwsagent, forcing hdwr_svr to terminate."
     # Kill hdwr_svr daemon if still running
     ps_result=`/bin/ps -ef | /bin/grep hdwr_svr | /bin/grep opt | /bin/awk {'print $2'}`
     kill -9 $ps_result
  fi

  #
  # Make sure hdwr_svr has stopped. It will most likely stop within 20
  # seconds, if not sooner.
  #
  subsys_checked=0
  hdwr_svr_stopped=`LC_ALL=C /usr/bin/lssrc -s hdwr_svr | /bin/grep inoperative`
  rc=$?

  while [[ $rc != 0 && $subsys_checked -lt 20 ]]
  do
      ((subsys_checked=$subsys_checked+1))
      sleep 1
      hdwr_svr_stopped=`LC_ALL=C /usr/bin/lssrc -s hdwr_svr | /bin/grep inoperative`
      rc=$?
  done

  if [[ $subsys_checked = 20 ]]
    then
    echo "Unable to stop hdwr_svr subsystem."
  fi
  exit 1
else 
  # Start hdwr_svr subsystem
  #
  /usr/bin/startsrc -s hdwr_svr
  rc=$?
  if [ $rc != 0 ]
  then
      echo "Unable to start hdwr_svr subsystem."
  fi

fi
