Script to start weblogic server
Starting a weblogic server is very easy using the Oracle provided default scripts to manage lifecycle. There are many articles on the life cycle management of weblogic servers are written in techpaste.com. For example:
wlst script example to manage weblogic server – TechPaste
wlst script example to start, stop and run as service – TechPaste
WLST script to deploy applications in Weblogic – TechPaste
I am again writing one more script as the requirement was to start weblogic server and monitor its status to make sure its up and running before executing other scripts to start the other managed servers and do deployments, etc. So below script is made keeping this requirement of checking the status of weblogic server before exiting or reporting something has failed during start weblogic server process. Please find the startsrv.sh script below:
#!/bin/sh #-x DOMAIN_HOME=$1 MANAGE_SERVER_NAME=$2 ADMIN_URL=$3 USER_NAME=$4 PASSWORD=$5 WL_JAR_LOC=$6 if [[ $# -lt 6 ]] ; then echo "Wrong number of arguments..." echo "Usage:" echo echo "./scriptfile.sh Domain_Home_Loc Server_Name Admin_Server_t3URL UserName Password weblogic.jar_location"; echo exit 0 fi export TFILE=`echo /tmp/nohup.$$.tmp` status=`java -cp ${WL_JAR_LOC} weblogic.Admin -url ${ADMIN_URL} GETSTATE ${MANAGE_SERVER_NAME} -username ${USER_NAME} -password ${PASSWORD} | awk '{print $6}'` if [[ "$status" == "SHUTDOWN" ]]; then nohup ${DOMAIN_HOME}/bin/startManagedWebLogic.sh ${MANAGE_SERVER_NAME} ${ADMIN_URL} -Dweblogic.management.username=${USER_NAME} -Dweblogic.management.password=${PASSWORD} > ${TFILE} 2>&1 & elif [[ "$status" == "RUNNING" ]]; then echo -e "`date` :No Need To Start The Server ${MANAGE_SERVER_NAME} Again."; echo -e "`date` :Server ${MANAGE_SERVER_NAME} is already in RUNNING state."; exit 0; else echo -e "`date` :Server ${MANAGE_SERVER_NAME} is in $status state.Not able to start"; exit 0; fi; if [ "$?" != 0 ]; then echo "`date` :Command Failed To Execute Properly"; exit 1; fi #while true; do export a="0"; while [ $a -lt 60 ]; do status=`java -cp ${WL_JAR_LOC} weblogic.Admin -url ${ADMIN_URL} GETSTATE ${MANAGE_SERVER_NAME} -username ${USER_NAME} -password ${PASSWORD} | awk '{print $6}'` if [ "$status" == "RUNNING" ]; then echo "`date` :Server Started in RUNNING mode..."; rm -f ${TFILE}; exit 0; else echo "`date` :Server State : ${status}..."; a=`expr $a + 1` fi sleep 5s; done echo "`date` :Some Issue Encountered While Starting The Server Please Investigate Log ${TFILE}."; exit 1;
The above script takes below arguments to successfully run. You can hard code the values if you don’t want it to be generic and want to use the script for a specific environment only.
./startsrv.sh /opt/Middleware/user_projects/domains/my_domain My_Server1 t3://techpasteadmin:7001 weblogic weblogic123 /opt/Middleware/wlserver_10.3/server/lib/weblogic.jar
Sample Outputs:
1. Usage:
2. Run Output:
The above script assumes you have the AdminServer up and running with t3 protocol already and running the script from the servers machine itself.
In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.
thank you very much for this script
can we make a loop to start Adminserver and all managed servers?