Restart Admin

#!/bin/sh
#written by Andrew Stringer, 29/03/2011
#Restart RGS C/S Admin Platform and check for admin server running first.
#If admin is not running, abort restart.
#This is intended to be run from cron for overnight application restarts.

#/wworks/rgs/weblogic/prod/bin/run_weblogic.bash -d admin -s managed -a $1
#ssh -q -l wworks ${SERVER} ${BINPATH}/weblogic.platform.admin state

BINPATH=/wworks/rgs/weblogic/prod/bin
#turn on debugging, -x starts, +x stops
set +x

TMPLOG=/tmp/admin-managed-restart-$$
DAY=`date +%b" "%d" "%Y`
HOSTNAME=` hostname -s`

# Check user is wworks
if [ "$USER" = "wworks" ]; then
        ADMINSRV=ok
else
        echo "Sorry, this script needs to be run as the wworks user"
        exit 1
fi

#Write out first part of email
echo "admin.managed restart on ${HOSTNAME}" > ${TMPLOG}
echo "=============================================" >> ${TMPLOG}
echo "" >> ${TMPLOG}
echo "From  admin.managed-restart.sh" >> ${TMPLOG}
echo "" >> ${TMPLOG};


#Check Admin.admin server is running before restarting admin.managed
ssh -q -l wworks zz-yyy-app01 ${BINPATH}/run_weblogic.bash -d admin -s admin -a state | grep RUNNING  2>&1 >/dev/null
ADMINRESULT=$?

#echo "Admin ssh result is ${ADMINRESULT}."

if [ "${ADMINRESULT}" -eq 0 ]; then
        #echo "Admin.admin server appears to be running, proceeding with Managed restarts."
        ${BINPATH}/run_weblogic.bash -d admin -s managed -a restart 2>&1 >/dev/null
else
        #echo "Admin.admin server on app01 does not appear to be running, aborting Managed restarts."
        echo "Admin server on app01 does not appear to be running, aborting Admin.Managed restarts." >> ${TMPLOG}
        /bin/mailx -s "${HOSTNAME} admin.managed restart Aborted!" ww-noc@domain.com < ${TMPLOG}

        #Tidy litter in to bin
        rm ${TMPLOG}
        exit 1
fi

#Check if weblogic managed admin is running
sleep 120
${BINPATH}/run_weblogic.bash -d admin -s managed -a state | grep RUNNING   >/tmp/$$
MANAGEDRESULT=$?

#echo "Managed result is ${MANAGEDRESULT}."

if [ "${MANAGEDRESULT}" -eq 0 ];then
        #State is ok
        MANAAGED=OK
else
        echo "" > ${TMPLOG}
        echo "Admin.Managed may not have have restarted ok, " >> ${TMPLOG}
        echo "" > ${TMPLOG}
        cat /tmp/$$ >> ${TMPLOG}
        /bin/mailx -s "${HOSTNAME} admin.managed may not have restarted ok." xx-noc@zzz.com < ${TMPLOG}
fi

#Normal exit
#Tidy litter in to bin
rm ${TMPLOG}
rm /tmp/$$
exit 0

rb/restartadmin.txt · Last modified: 15/08/2018 23:49 by andrew