Shell script to start nodemanager weblogic

Oracle Weblogic Server

Below shell script can be used to start the weblogic nodemanager. This script can be scheduled in cron tab to start nodemanager weblogic servers. It takes one input i.e weblogic installation home location to start the nodemanager.

Incase the nodemanager is already running it will not start the nodemanager again. This script was made available as part of life cycle automation task. you can search this website for more automation scripts like this.

#!/bin/bash
#-x
#Usage:
#scriptfile /opt/Middleware
WL_INSTALL_HOME=$1
TFILE="/tmp/nohup.$$.tmp"
status=`ps -eaf | grep "weblogic.NodeManager" | grep -v grep | awk -F' ' '{ print $2 }' | wc -l`
if [ "${status}" == 0 ]; then
echo "`date` :Starting Weblogic NodeManager...";
nohup ${WL_INSTALL_HOME}/wlserver_10.3/server/bin/startNodeManager.sh > ${TFILE} 2>&1 &
else
echo "`date` :NodeManager is already RUNNING..";
exit 0;
fi
if [ "$?" != 0 ]; then
echo "Command Failed To Execute Properly";
exit 1;
fi
#while true; do
export a="0";
while [ $a -lt 60 ]; do
count=`cat ${TFILE} | grep "socket listener started on port" | wc -l`
if [ "${count}" -gt 0 ]; then
echo "NodeManager Started...";
rm -f ${TFILE}
exit 0;
else
echo "Waiting For NodeManager To Start...";
a=`expr $a + 1`
fi
sleep 5s;
done
echo "Some Issue Happened While Starting The NodeManager Please Investigate Log File ${TFILE}";
exit 1;

Output incase nodemanager is already running.

# ./node.sh /opt/Middleware/
Wed Feb 25 02:18:23 CST 2015 :NodeManager is already RUNNING..

Output of script when node manager is down:

# ./node.sh /opt/Middleware/
Wed Feb 25 02:19:39 CST 2015 :Starting Weblogic NodeManager...
Waiting For NodeManager To Start...
Waiting For NodeManager To Start...
NodeManager Started...

Similarly for stopping nodemanager weblogic you can use below script:

This script does not take any argument and kills any running weblogic.NodeManager process.

#!/bin/sh
status=`ps -eaf | grep "weblogic.NodeManager" | grep -v grep | awk -F' ' '{ print $2 }' | wc -l`
if [ "${status}" -gt 0 ]; then
kill -9 `ps -eaf | grep "weblogic.NodeManager" | grep -v grep | awk -F' ' '{ print $2 }'`
else
echo "`date` :Node Manager Seems To Be already in stopped state.";
echo "`date` :Skipping To Stop The NodeManager Again.";
exit 0;
fi;
if [ "$?" == 0 ]; then
echo "`date` :Node Manager Successfully killed.";
exit 0;
else
echo "`date` :Node Manager Failed To Stop.";
exit 1;
fi;

Note: All above scripts are tested in environments which contains single weblogic server nodemanager, incase you have multiple node managers in the same machine then you have to update the script with narrowed down grep statements.
you can get more weblogic scripts here

In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.

1 Response

  1. Sandeep says:

    Thanks for the nice scripts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.