Script to start WebLogic domain server at Machine Start in distributed environment .
I had a requirement to configure weblogic server to start at the server reboot on linux machine , i.e. to configure weblogic server as a daemon process. In my case the weblogic domain was distributed over two different physical machines .
Challenges :
- In Weblogic Domain Admin Server should be started First.
- After the Admin Server has come to RUNNING state, then we can start the Managed Server of the local Machine and Remote Machine.
Steps :
- Here I will mention the steps I followed to write the shell script to complete the above mentioned task. I will post the code snippet and the task they fulfill and in the end I will provide the complete
First task is to start the Weblogic Admin Server using the startWeblogic.sh file from $DOMAIN_HOME/bin dir.
My code snippet to check for the domain dir, then check for any nohup.out file existing or not and then finally start the server .
domain=/Middleware/user_projects/domains/BASE_DOMAIN
# Clear the nohup file that is existing
echo ${domain}/bin
cd ${domain}/bin
if [ `pwd` == ${domain}/bin ]
then
if [ -f nohup.out ]
then
rm -f nohup.out
fi
fi
# Start the Weblogic Admin Server.
echo " Starting Weblogic Admin Server "
nohup ./startWebLogic.sh &
Now we have to get the status of the Admin Server and wait till the Server comes in RUNNING State. For that I will use the weblogic.Admin GETSTAT command with below snippet .
CLASSPATH="/opt/Middleware1032/wlserver_10.3/server/lib/weblogic.jar${CLASSPATH}"
export CLASSPATH
status=`java weblogic.Admin -adminurl t3://host1.com:7231 -username weblogic -password weblogic123 GETSTATE AdminServer | awk '{print$6}'`
printf "Admin Server is Starting "
count=1
while [ "$status" != "RUNNING" ]
do
printf "."
status=`java weblogic.Admin -adminurl t3://host1.com:7231 -username weblogic -password weblogic123 GETSTATE AdminServer | awk '{print$6}'`
count=$count+1
if [ $count -gt 100 ];
then
echo " There is some problem with admin server "
exit 0
fi
done
After Admin Server has come to RUNNING state we will start the Managed Server of local machine.
if [ "$status" == "RUNNING" ];
then
echo "Admin Server is running "
echo "Starting Managed Server "
cd ${domain}/servers/MS1/bin
if [ `pwd` == ${domain}/servers/MS1/bin ]
then
if [ -f nohup.out ]
then
rm -f nohup.out
fi
fi
./startMS1.sh
echo " Managed Server is Starting "
echo " do : tail -f $pwd/nohup.out to check the status of Server "
fi
Once Managed Server of local machine is started we will start the Managed Server of Remote Machine with below snippet.
# starting Managed Server on remote machine
#
MACHINE2=host2.com
if ping -c 1 -w 10 $MACHINE2
then
echo "This machine is up and reachable"
echo " Checking MS2 server PID "
# Getting PID of MS2 on MACHINE2
PID=`ssh weblogic@host2.com \`\`ps -ef |grep -v grep |grep weblogic.Name=MS2 | awk '{print\$2}'\`\``
echo $PID
if [ -z "$PID" ]
then
echo " MS2 Server not running "
echo " Starting MS2 Server "
ssh weblogic@host2.com '/flexcube/user_projects/domains/BASE_DOMAIN/servers/MS2/bin/startRelease1.sh ;/flexcube/user_projects/domains/BASE_DOMAIN/servers/MS2/bin/nohup.out'
else
#CLASSPATH="/oracle/app/Middleware1032/wlserver_10.3/server/lib/weblogic.jar${CLASSPATH}"
#export CLASSPATH
MS2_status=`java weblogic.Admin -adminurl t3://host2.com:7231 -username weblogic -password weblogic123 GETSTATE MS2 | awk '{print$6}'`
if [ "$MS2_status" = "RUNNING" ]
then
echo " MS2 is already Running "
echo " exiting from script"
exit 0
else
echo " MS2 PID=$PID exist and current state of server is $MS2_status"
fi
fi
fi
The complete script startBASE_DOMAIN.sh is available here :
One additional script has been used , startMS1.sh is available here :
${domain}/servers/MS1/bin . The additional script can be found at below location.
Configuring the Above script in init.d directory.
In Linux : /etc/init.d
In AIX : /etc/rc.d/init.d
Create a file weblogic.sh with the below contents :
#!/bin/sh
# Start the weblogic domains
su - weblogic -c "/opt /Middleware1032/wlserver_10.3/server/bin/startNodeManager.sh"
su - weblogic -c "/opt/user_projects/domains/scripts/startup/startBASE_DOMAIN.sh"
Now create soft link in /etc/rc.d/rc5.d with any name starting with S98 as given below:
Linux
ln –s /etc/init.d/weblogic.sh S98weblogicstart
AIX
ln –s /etc/rc.d/init.d/weblogic.sh S98weblogicstart
startBASE_DOMAIN.sh
#!/bin/sh
# To Start BASE_DOMAIN Domain while server start
# Written by Sandeep Singh
#
umask 037
domain=/flexcube/user_projects/domains/BASE_DOMAIN
# Clear the nohup file that is existing
echo ${domain}/bin
cd ${domain}/bin
if [ `pwd` == ${domain}/bin ]
then
if [ -f nohup.out ]
then
rm -f nohup.out
fi
fi
# Start the Weblogic Admin Server.
echo " Starting Weblogic Admin Server "
nohup ./startWebLogic.sh &
CLASSPATH="/opt/app/Middleware1032/wlserver_10.3/server/lib/weblogic.jar${CLASSPATH}"
export CLASSPATH
status=`java weblogic.Admin -adminurl t3://host1.com:7231 -username weblogic -password weblogic123 GETSTATE AdminServer | awk '{print$6}'`
printf "Admin Server is Starting "
count=1
while [ "$status" != "RUNNING" ]
do
printf "."
status=`java weblogic.Admin -adminurl t3://host1.com:7231 -username weblogic -password weblogic123 GETSTATE AdminServer | awk '{print$6}'`
count=$count+1
if [ $count -gt 40 ];
then
echo " There is some problem with admin server "
exit 0
fi
done
if [ "$status" == "RUNNING" ];
then
echo "Admin Server is running "
echo "Starting Managed Server "
cd ${domain}/servers/MS1/bin
if [ `pwd` == ${domain}/servers/MS1/bin ]
then
if [ -f nohup.out ]
then
rm -f nohup.out
fi
fi
./startMS1.sh
echo " Managed Server is Starting "
echo " do : tail -f $pwd/nohup.out to check the status of Server "
fi
# Starting Managed Server on remote machine
#
MACHINE2=host2.com
if ping -c 1 -w 10 $MACHINE2
then
echo "This machine is up and reachable"
echo " Checking MS2 server PID "
# Getting PID of MS2 on MACHINE2
PID=`ssh weblogic@host2.com \`\`ps -ef |grep -v grep |grep weblogic.Name=MS2 | awk '{print\$2}'\`\``
echo $PID
if [ -z "$PID" ]
then
echo " MS2 Server not running "
echo " Starting MS2 Server "
ssh weblogic@host2.com '/flexcube/user_projects/domains/BASE_DOMAIN/servers/MS2/bin/startMS2.sh >/flexcube/user_projects/domains/BASE_DOMAIN/servers/MS2/bin/nohup.out &'
else
#CLASSPATH="/opt/app/Middleware1032/wlserver_10.3/server/lib/weblogic.jar${CLASSPATH}"
#export CLASSPATH
MS2_status=`java weblogic.Admin -adminurl t3://host1.com:7231 -username weblogic -password weblogic123 GETSTATE MS2 | awk '{print$6}'`
if [ "$MS2_status" = "RUNNING" ]
then
echo " MS2 is already Running "
echo " exiting from script"
exit 0
else
echo " MS2 PID=$PID exist and current state of server is $MS2_status"
fi
fi
fi
startMS1.sh
#!/bin/sh
# Purpose : Starting the SOA SERVER1 of DOMAIN : BASE_DOMAIN
#
# WARNING: This file is created by the Configuration Wizard.
# Any changes to this script may be lost when adding extensions to this configuration.
export HOME=/flexcube/user_projects/domains/BASE_DOMAIN
export SR=MS1
nohup ${HOME}/bin/startManagedWebLogic.sh ${SR} http://host1.com:7231 &
1 comment:
Why not just use nodemanger instead? Just install nodemanager as a service and simply configure it to start/restart the servers. None of this checking if the servers are up or not, or scripting required.
Patrick.
Post a Comment