Sunday, March 25, 2012

Check Nodemanager status using simple Shell script

Hi, 


Here I like to explain about, checking the node manager status using a simple shell script.

Function of this shell script:
           If you execute this shell script, it will check whether Node Manager is running or not on your machine, using WLST, we can do the same using "ps" command, but we are trying to use the WLST commands.

Shell script will call a python script (checkNM.py), it will call WLST and try to connect with Node manager and it will check the status.

You can customize this script by updating the following variables, 
1. weblogic home.
2. Nodemanager IP
3. Nodemanager Port
4. Domain name
5.Domain full path

WLST command to connect with NM:
nmConnect(CONSOLE_USER_NAME, CONSOLE_PASSWORD, NODE_MANAGER_IP, NODE_MANAGER_PORT, DOMAIN_NAME,FULL_PATH_FOR_DOMAIN,'plain') 

To call WLST and execute a python script:
sh ${WL_HOME}/common/bin/wlst.sh ${PYTHON_FILE_NAME}

shell script used to start Node manger:
startNodeManager.sh 

Solaris command used to get the last command status - $?

Shell Script to start Node Manager process:

#!/bin/sh


#***************************************************************
# This script is used to check your server status and node manager status using WLST
# It sets the following variables:
#
# WL_HOME    - The root directory of your WebLogic installation
# PYTHON_FILE_NAME - WLST file name to get server status
#****************************************************************




BEA_HOME="/opt/weblogic-10.3.3"
WL_HOME="${BEA_HOME}/weblogic103"
PYTHON_FILE_NAME="checkNM.py"
NODE_MANAGER_HOME="/ dir0/ dir1/ dir2/nodemanager"
NM_STARTUP_FILE="startNodeManager.sh"


sh ${WL_HOME}/common/bin/wlst.sh ${PYTHON_FILE_NAME}
if [ $? -eq 2 ]         # Test exit status of "cmp" command.
then
  echo "Node manager is not running"
  ls -lrt ${NODE_MANAGER_HOME}/${NM_STARTUP_FILE}
  value=$?
  if [ value -eq 2 ]
then 
echo ${NM_STARTUP_FILE} " File not found in "  ${NODE_MANAGER_HOME}  
  elif [ value -eq 0 ]
then
echo "NM  Home found and starting Node Manager "
nohup ${NODE_MANAGER_HOME}/${NM_STARTUP_FILE} &
if [ $? -eq 0 ]
then
ps -ef | grep weblogic.NodeManager | grep -v grep
if [ $? -eq 0 ]
then
echo "Node manager started properlly"
else
echo "Node manager not started"
fi


else
echo "Not able to start Node Manager"
fi
  else
echo "Some other error - " value
  fi  
else  
  echo "Process completed"
fi


-----------------------------------------------------------------


Python script - checkNM.py:


CONSOLE_USER_NAME="weblogic"
CONSOLE_PASSWORD="weblogic11"
NODE_MANAGER_IP="192.168.1.40"
NODE_MANAGER_PORT="5301"
DOMAIN_NAME=" domainName"
FULL_PATH_FOR_DOMAIN=" / dir0/ dir1/ dir2/domainName"
import sys
try:
nmConnect(CONSOLE_USER_NAME, CONSOLE_PASSWORD, NODE_MANAGER_IP, NODE_MANAGER_PORT, DOMAIN_NAME,FULL_PATH_FOR_DOMAIN,'plain')
connected = 1
except:
    print('Could not connect to the NodeManager.')
NODE_1="ManageServer1"
NODE_2=" ManageServer12"

if connected==1:
server = NODE_1
serverStatus=nmServerStatus(server)
try:
if serverStatus=='RUNNING':
server = NODE_2
serverStatus=nmServerStatus(server)
if serverStatus=='RUNNING':
print('All servers were running - '+server+' -'+serverStatus)
else:
print(server+' - '+serverStatus)
elif serverStatus=='SHUTDOWN':
print(server+' - '+serverStatus)
elif serverStatus=='STARTING':
print('Server startup has been initiated by another process.')
else:
print(server+' - '+serverStatus)
except:
print('Error restarting.')
nmDisconnect()
exit()
else:
exit(exitcode=2)
----------------------------------------------------------------- 

Please try yourself and let me know if you have any questions


5 comments:

  1. Hi Sundar,

    This is really nice script.

    I am a DBA, I am help a weblogic admin to create a script to deploy a war file which is located in remote server.

    Here I want to run OS command between wlst.

    Or Can I run wlst commands like connect('weblogic','******','t3://*****:1****')

    from a shell script with out effecting corresponding os commands.

    Regards,
    Venkat
    Oracle and Informix DBA
    kvbsetti@gmail.com

    ReplyDelete
  2. Yes Venkat, You can execute the weblogic server connection command from a shell script by using shabang line with python path.

    ReplyDelete
  3. Very useful information to check node manager status myself in my shell scripting training.

    ReplyDelete
  4. Very useful information to check node manager status myself in my shell scripting training.

    ReplyDelete
  5. its showing server is shutdown but server state is running state

    ReplyDelete

Followers