Start and stop WebLogic Server using scripts

You can use scripts to facilitate the management of WebLogic Server and reduce the manual tasks you have to do.
Examples of these scripts are scripts to automate start and stop of Admin and Managed Servers of WebLogic Server.

In this post I will provide the scripts I use and you can download them here: scripts.zip

These are the scripts that I use to start WebLogic Server in my Linux VM.
One of them is a Shell script to start Node Manager and AdminServer, and the other is a Python script to start SOA, OSB and BAM Managed Servers.

Shell script:

echo "############################"
echo "# All Servers are STARTING #"
echo "############################"
export FMW_HOME=/u01/app/fmw
export DOMAIN_HOME=/u01/app/fmw/user_projects/domains/fmw_domain

nohup $DOMAIN_HOME/bin/startNodeManager.sh > $DOMAIN_HOME/nodemanager/logs/nodemanager.out &

nohup $DOMAIN_HOME/bin/startWebLogic.sh > $DOMAIN_HOME/servers/AdminServer/logs/AdminServer.out &

SERVER=127.0.0.1 PORT=7001
while !(: < /dev/tcp/$SERVER/$PORT) 2>/dev/null
do
    echo "** Waiting for Admin Server to Start **"
    sleep 30
done

. $FMW_HOME/wlserver/server/bin/setWLSEnv.sh
. $DOMAIN_HOME/bin/setDomainEnv.sh
. $DOMAIN_HOME/bin/setStartupEnv.sh

/u01/app/jdk/bin/java weblogic.WLST /u01/app/utils/scripts/allServersStart.py

echo "###########################"
echo "# All Servers are RUNNING #"
echo "###########################"

tail -f $DOMAIN_HOME/nodemanager/logs/nodemanager.out $DOMAIN_HOME/servers/AdminServer/logs/AdminServer.out

start-and-stop-weblogic-server-using-scripts1

Python script:

while True:
 try:
  connect(adminServerName="AdminServer")
  break

 except:
  sleep(60)

print "** Starting SOA Server **"
start(name="SOA_server", block="true")

print "** Starting OSB Server **"
start(name="SOA_osbserver", block="true")

print "** Starting BAM Server **"
start(name="SOA_bamserver", block="true")

exit()

start-and-stop-weblogic-server-using-scripts2

And these are the scripts that I use to stop WebLogic Server in my Linux VM.
One of them is a Shell script to stop Node Manager and AdminServer, and the other is a Python script to stop SOA, OSB and BAM Managed Servers.

Shell script:

echo "############################"
echo "# All Servers are STOPPING #"
echo "############################"
export FMW_HOME=/u01/app/fmw
export DOMAIN_HOME=/u01/app/fmw/user_projects/domains/fmw_domain

. $FMW_HOME/wlserver/server/bin/setWLSEnv.sh
. $DOMAIN_HOME/bin/setDomainEnv.sh
. $DOMAIN_HOME/bin/setStartupEnv.sh

/u01/app/jdk/bin/java weblogic.WLST /u01/app/utils/scripts/allServersStop.py

nohup $DOMAIN_HOME/bin/stopWebLogic.sh > $DOMAIN_HOME/servers/AdminServer/logs/AdminServer.out

nohup $DOMAIN_HOME/bin/stopNodeManager.sh > $DOMAIN_HOME/nodemanager/logs/nodemanager.out

start-and-stop-weblogic-server-using-scripts3

Python script:

connect(adminServerName="AdminServer")

exitonerror=false

# Stop all managed Servers
shutdown('SOA_server', 'Server', force="true")
shutdown('SOA_osbserver', 'Server', force="true")
shutdown('SOA_bamserver', 'Server', force="true")

exit()

start-and-stop-weblogic-server-using-scripts4

Enjoy!

Author: Waslley Souza

Consultor Oracle com foco em tecnologias Oracle Fusion Middleware e SOA. Certificado Oracle WebCenter Portal, Oracle ADF e Java.

2 thoughts on “Start and stop WebLogic Server using scripts”

  1. Hi Waslley,

    I got the below exception while using stop-all servers script, can you please check and advise ?

    Connecting to t3://localhost:7001 with userid weblogic …
    This Exception occurred at Wed Apr 11 13:07:47 EDT 2018.
    javax.naming.CommunicationException: Failed to initialize JNDI context, tried 2 time or times totally, the interval of each time is 0ms.
    t3://localhost:7001: Destination 127.0.0.1, 7001 unreachable.; nested exception is:
    java.net.ConnectException: Connection refused (Connection refused); No available router to destination.; nested exception is:
    java.rmi.ConnectException: No available router to destination. [Root exception is java.net.ConnectException: t3://localhost:7001: Destination 127.0.0.1, 7001 unreachable.; nested exception is:
    java.net.ConnectException: Connection refused (Connection refused); No available router to destination.; nested exception is:
    java.rmi.ConnectException: No available router to destination.]
    Problem invoking WLST – Traceback (innermost last):
    File “/orabpm/app/scripts/Test_ServerRestart/allServersStop.py”, line 1, in ?
    File “”, line 19, in connect
    File “”, line 553, in raiseWLSTException
    WLSTException: Error occurred while performing connect : Error getting the initial context. There is no server running at t3://localhost:7001 : Failed to initialize JNDI context, tried 2 time or times totally, the interval of each time is 0ms.
    t3://localhost:7001: Destination 127.0.0.1, 7001 unreachable.; nested exception is:
    java.net.ConnectException: Connection refused (Connection refused); No available router to destination.; nested exception is:
    java.rmi.ConnectException: No available router to destination.
    Use dumpStack() to view the full stacktrace :

    nohup: ignoring input and redirecting stderr to stdout
    nohup: ignoring input and redirecting stderr to stdout

Leave a Reply

Your email address will not be published. Required fields are marked *