Bouncing an application is a common Java EE development task. On a Weblogic server, we can take advantage of WLST (Weblogic scripting tool) to automate it.
.
WLST Python Script
Create a python script, bounce-app.py, as follows:
#--------------------------------------
# Review and modify me
#--------------------------------------
url = 't3://localhost:7001'
username = 'weblogic'
username = 'weblogic'
password = 'weblogic1'
applicationName = 'sampleApp'
# Connecting to the weblogic server
try:
connect(username, password)
except:
print("Failed to connect to the Weblogoic server!")
print("Verify whether the server is up and the credential is correct.")
exit()
else:
print("Connnected to the Weblogoic server...")
# Bounce the application
try:
stopApplication(applicationName)
startApplication(applicationName)
except:
print("Failed to bounce the application")
else:
print("\n\nBounced the application successfully!")
# Closing down
disconnect()
exit()
Command Line Invocation
The WLLST script can be invoked as follows on a Windows machine:
%WL_HOME%\common\bin\wlst.cmd bounce-server.py
On a linux machine, wlst.sh should be used.
To invoke the script from a Windows BAT file:
@echo off
REM =====================================================
REM To bounce the Weblogic application using bounce-app.py
REM =====================================================
SET WL_HOME=C:\programs\Middleware\wlserver_10.3
SET scriptLocation=%~dp0%bounce-app.py
"%WL_HOME%\common\bin\wlst.cmd" %scriptLocation%
Reference