Recently I was working on the automated script to start and stop the nodemanager, AdminServer and all managed server (ESS, SOA, OSB, WSM) in a domain. So in this post I am going to share my work, it may be possible that these scripts may not be suited for your environment but yes It must give you a basic idea of how to start and stop nodemanager automatically.
Start scripts for nodemanager
Well the basic logic that I used to start the nodemanager is
tfile="nodemanage.$$.out"
status= ps -eaf | grep "weblogic.NodeManager" | grep -v grep| wc -l
date=date
echo $status
echo "Node Manager Directory: " $1
if [[ "$status" -eq 0 ]]; then
echo $date " :Starting Weblogic NodeManager..."
echo $1
nohup $1 > $tfile 2>&1 &
else
echo $date " :NodeManager is already RUNNING.."
fi
if [ "$?" != 0 ]; then
echo "Command Failed To Execute Properly"
exit 1;
fi
export a=0;
while [ $a -lt 10 ]; do
echo $tfile
count=$(cat $tfile | grep "socket listener started on port" | wc -l)
echo "The value of count is ${count}"
if [[ "$count" -gt 0 ]]; then
echo "NodeManager Started..."
rm -f $tfile
exit 0
else
echo "Waiting For NodeManager To Start..."
echo $a
((a++))
fi
sleep 5s
done
echo "Please check ${tfile} log file for more issues"
exit 1
Save the above script in .sh file e.g. startNode.sh. Now to run this script you have to pass the location of the nodemanager i.e.
nohup ./StartNode.sh $DOMAIN_HOME/bin/startNodeManager.sh > nodemanage.out &
Stop script for nodemanager
To stop the nodemanager find the process id of nodemanager instance and kill that process id, here is the script below:
node1=$(ps -ef | grep weblogic.nodemanager | grep config=/u01 | awk '{printf $2}')
kill -9 $node1
Save the above code in the .sh file e.g. stopNode.sh and execute the script as below:
nohup sh StopNode.sh &
In the next post I am going to share the start and stop script for weblogic AdminServer and Managed server.
Start scripts for nodemanager
Well the basic logic that I used to start the nodemanager is
- check if nodemanager is running or not
- start the nodemanager and take the output in a temporary file.
- while the nodemanager is starting keep looking for the string "socket listener started on port" in a temporary file.
- if the matching string is found that means node manager is started and exit().
tfile="nodemanage.$$.out"
status= ps -eaf | grep "weblogic.NodeManager" | grep -v grep| wc -l
date=date
echo $status
echo "Node Manager Directory: " $1
if [[ "$status" -eq 0 ]]; then
echo $date " :Starting Weblogic NodeManager..."
echo $1
nohup $1 > $tfile 2>&1 &
else
echo $date " :NodeManager is already RUNNING.."
fi
if [ "$?" != 0 ]; then
echo "Command Failed To Execute Properly"
exit 1;
fi
export a=0;
while [ $a -lt 10 ]; do
echo $tfile
count=$(cat $tfile | grep "socket listener started on port" | wc -l)
echo "The value of count is ${count}"
if [[ "$count" -gt 0 ]]; then
echo "NodeManager Started..."
rm -f $tfile
exit 0
else
echo "Waiting For NodeManager To Start..."
echo $a
((a++))
fi
sleep 5s
done
echo "Please check ${tfile} log file for more issues"
exit 1
Save the above script in .sh file e.g. startNode.sh. Now to run this script you have to pass the location of the nodemanager i.e.
nohup ./StartNode.sh $DOMAIN_HOME/bin/startNodeManager.sh > nodemanage.out &
Stop script for nodemanager
To stop the nodemanager find the process id of nodemanager instance and kill that process id, here is the script below:
node1=$(ps -ef | grep weblogic.nodemanager | grep config=/u01 | awk '{printf $2}')
kill -9 $node1
Save the above code in the .sh file e.g. stopNode.sh and execute the script as below:
nohup sh StopNode.sh &
In the next post I am going to share the start and stop script for weblogic AdminServer and Managed server.
No comments:
Post a Comment