#!/bin/sh
#
#	Copyright (c) 2004-2015 Brocade Communications Systems, Inc.
#	All rights reserved.
#
#	Description:
#		This script will be invoked as part of HASM-1002 log to cleanup
#		DCM database on standby GOS alone of TOR switches and the standby
#		GOS will be rebooted.

REBOOT_LOG="/var/log/reboot.log"
state=`cat /proc/device-tree/chosen/status 2> /dev/null`
echo "Invoke FFDC HASM-1002 at `/bin/date +%D-%T`" >> $REBOOT_LOG

if [ "$state" == "standby" ]; then
	if [ -x '/fabos/sbin/cfgcleanup' ]; then
		/fabos/sbin/cfgcleanup
	fi
	if /sbin/chkconfig swdd; then
		echo "Invoke GOS reboot on standby" >> $REBOOT_LOG
		/sbin/hainfo RebootReason "Auto reboot recovery"
		sync; sleep 3; sync; sleep 3; sync
		/sbin/reboot -f
	fi
else
	if /sbin/chkconfig swdd; then
		echo "Invoke node reboot" >> $REBOOT_LOG
		/sbin/hainfo RebootReason "Auto reboot recovery"
		sync; sleep 3; sync; sleep 3; sync
		/usr/bin/reboot
	fi
fi
