WAS Restart Script

This Script start and stop the WebSphere Services

You can see the usage by just running the ./was_restart.sh

was_restart.sh

ACTION=$1
WAS_PROFILE_PATH=$2
WAS_DMGR_PROFILE=$3
WAS_APP_PROFILE=$4
WAS_USER=$5
WAS_PASSWORD=$6
HOSTNAME=$7
SOAP_PORT=$8

usage() {
     echo -e "***************************************************************************************"
     echo -e "USAGE: ./was_restart.sh <ACTION> <WAS_PROFILE_PATH> <WAS_DMGR_PROFILE> <WAS_APP_PROFILE> <WAS_USER> <WAS_PASSWORD> <HOSTNAME> <SOAP_PORT>**********"
     echo -e "***************************************************************************************"
     echo -e "WARN: USAGE: <ACTION> must be one of the following options:                            "
     echo -e ""
     echo -e "start - starts All the WAS profiles exists in the server                               "
     echo -e "stop  - stops All the WAS profiles exists in the server                                "
     echo -e "***************************************************************************************"
     exit 1
}

STARTEDSERVER=""
STOPPEDSERVER=""
STARTEDNODE=""
STOPPEDNODE=""
STARTEDDMGR=""
STOPPEDDMGR=""

get_info(){
     PROFILE_NAME=$1
     STARTEDSERVER=`${WAS_PROFILE_PATH}/${PROFILE_NAME}/bin/serverStatus.sh -all -username ${WAS_USER} -password ${WAS_PASSWORD}|grep 'Server'|grep -v 'cannot' |awk -F"\"" '{print $2}'`
     STOPPEDSERVER=`${WAS_PROFILE_PATH}/${PROFILE_NAME}/bin/serverStatus.sh -all -username ${WAS_USER} -password ${WAS_PASSWORD}|grep 'Server'|grep 'cannot'|awk -F"\"" '{print $2}'`

     STARTEDNODE=`${WAS_PROFILE_PATH}/${PROFILE_NAME}/bin/serverStatus.sh -all -username ${WAS_USER} -password ${WAS_PASSWORD}|grep 'nodeagent'|grep 'STARTED'|awk -F"\"" '{print $2}'`
     STOPPEDNODE=`${WAS_PROFILE_PATH}/${PROFILE_NAME}/bin/serverStatus.sh -all -username ${WAS_USER} -password ${WAS_PASSWORD}|grep 'nodeagent'|grep 'cannot'|awk -F"\"" '{print $2}'`

     STARTEDDMGR=`${WAS_PROFILE_PATH}/${PROFILE_NAME}/bin/serverStatus.sh -all -username ${WAS_USER} -password ${WAS_PASSWORD}|grep 'STARTED'|awk -F"\"" '{print $2}'`
    STOPPEDDMGR=`${WAS_PROFILE_PATH}/${PROFILE_NAME}/bin/serverStatus.sh -all -username ${WAS_USER} -password ${WAS_PASSWORD}|grep 'cannot'|awk -F"\"" '{print $2}'`

}

start_server(){
     PROFILENAME=$1
     get_info $PROFILENAME
     STOPSERVER=$(echo $STOPPEDSERVER | tr " " "\n")
     if [ ! -z "${STOPPEDSERVER}" ]; then
          for stopped in ${STOPSERVER};
          do
               echo "starting ${stopped}....."
               ${WAS_PROFILE_PATH}/${PROFILENAME}/bin/startServer.sh ${stopped}
          done
     else
          echo "Server ${STARTEDSERVER} already started ......."
     fi
}

stop_server(){
     PROFILENAME=$1
     get_info $PROFILENAME
     STARTSERVER=$(echo $STARTEDSERVER | tr " " "\n")
     if [ ! -z "${STARTEDSERVER}" ]; then
          for started in ${STARTSERVER};
          do
               echo "stopping ${started}....."
               ${WAS_PROFILE_PATH}/${PROFILENAME}/bin/stopServer.sh ${started} -username ${WAS_USER} -password ${WAS_PASSWORD}
          done
     else
          echo "Application Servers already stopped ......"
     fi
}
start_node(){
     PROFILENAME=$1
     get_info $PROFILENAME
     if [ ! -z "${STOPPEDNODE}" ]; then
      echo "Syncing Node........."
      sync_node "${WAS_PROFILE_PATH}/${PROFILENAME}" 2>&1
               echo "starting nodeagent....."
               ${WAS_PROFILE_PATH}/${PROFILENAME}/bin/startNode.sh
     else
          echo "NodeAgent already started ......."
     fi
}
stop_node(){
     PROFILENAME=$1
     get_info $PROFILENAME
     if [ ! -z "${STARTEDNODE}" ]; then
               echo "stopping nodeagent....."
               ${WAS_PROFILE_PATH}/${PROFILENAME}/bin/stopNode.sh -username ${WAS_USER} -password ${WAS_PASSWORD}
               rm -rf ${WAS_PROFILE_PATH}/${PROFILENAME}/wstemp ${WAS_PROFILE_PATH}/${PROFILENAME}/temp ${WAS_PROFILE_PATH}/${PROFILENAME}/config/temp
     else
          echo "NodeAgent already stopped ......"
     fi
}

start_dmgr(){
     PROFILENAME=$1
     get_info $PROFILENAME
     if [ ! -z "${STOPPEDDMGR}" ]; then
               echo "starting Deployment Manager....."
               ${WAS_PROFILE_PATH}/${PROFILENAME}/bin/startManager.sh
     else
          echo "Deployment Manager already started ......."
     fi
}

stop_dmgr(){
     PROFILENAME=$1
     get_info $PROFILENAME
     if [ ! -z "${STARTEDDMGR}" ]; then
               echo "stopping deployment manager....."
               ${WAS_PROFILE_PATH}/${PROFILENAME}/bin/stopManager.sh -username ${WAS_USER} -password ${WAS_PASSWORD}
               rm -rf ${WAS_PROFILE_PATH}/${PROFILENAME}/wstemp ${WAS_PROFILE_PATH}/${PROFILENAME}/temp ${WAS_PROFILE_PATH}/${PROFILENAME}/config/temp
     else
          echo "Deployment Manager already stopped ......"
     fi
}

sync_node(){
PROFILEPATH=$1
${PROFILEPATH}/bin/syncNode.sh ${HOSTNAME} ${SOAP_PORT} -username ${WAS_USER} -password ${WAS_PASSWORD}
}

############################
### MAIN TASKS START HERE###
############################

echo "***** ********************************************************************"
echo "***** WEBSPHERE MAINTAINANCE TASK: $1 for Environment ****************************"
echo "***** START TIME: "`date  '+[ %d/%m/%Y ] %H:%M:%S'`
echo "***** ********************************************************************"
if [ $# -eq 8 ]
then
      case "${ACTION}" in
      start)
               if [ -d ${WAS_PROFILE_PATH}/${WAS_DMGR_PROFILE} ]; then
start_dmgr "${WAS_DMGR_PROFILE}" 2>&1
      start_node "${WAS_APP_PROFILE}" 2>&1
                start_server "${WAS_APP_PROFILE}" 2>&1
else
echo "Dmgr Profile does not exist in the current server. Starting the Node"
sleep 160
start_node "${WAS_APP_PROFILE}" 2>&1
                        start_server "${WAS_APP_PROFILE}" 2>&1
fi
                ;;
      stop)
if [ -d ${WAS_PROFILE_PATH}/${WAS_DMGR_PROFILE} ]; then
                stop_server "${WAS_APP_PROFILE}" 2>&1
      stop_node "${WAS_APP_PROFILE}" 2>&1
                stop_dmgr "${WAS_DMGR_PROFILE}" 2>&1
else
echo "Dmgr Profile does not exists in the current server. Stopping the Node"
stop_server "${WAS_APP_PROFILE}" 2>&1
                        stop_node "${WAS_APP_PROFILE}" 2>&1
fi
                ;;
      *)
               usage
               ;;
       esac
else
usage
fi

echo "***** ********************************************************************"
echo "***** END TIME: "`date  '+[ %d/%m/%Y ] %H:%M:%S'`
echo "***** ********************************************************************"





Comments

Popular posts from this blog

Jenkins Dynmaic Parameter - List All Branches in a Git Repository

JMSWMQ2013: The security authentication was not valid that was supplied for QueueManager 'XYZ' with connection mode 'Client' and host name 'x.x.x.x(1415)'. Please check if the supplied username and password are correct on the QueueManager to which you are connecting.