Automating application updates on Weblogic 10

One of the things a developer always does is finding new ways to not do something by automating the process. Being responsible for 4 different application, I often have to install a new version in the integration environment, which is a Unix based Weblogic 10.3 instance. This usually takes just 5 minutes, but if you look at this chart, I can actually save 5-21 hours of my time by not doing this !
XKCD: Is It Worth the Time ?

//edit 2013-12-29: Another chart to prove my point:

Geeks and repetitive tasks


So, that’s why I wrote a small script that would:

  1. Undeploy an existing version of our application
  2. Download a given version of the application from the DSL
  3. Install this version on Weblogic
  4. Start it

The script can be fully parametrized (see inline comments) and you’ll need a configuration file for your application (a sample is available at the bottom of this post)

The script:

# P_W999 - 2013 - This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
# This script comes as-is, with no guarantees or warranties and it is used at own risk.
# v0.1 - 2013-12-13
# * Initial release
# If you haven't done yet, make your userconfig and userkey file with the following command:
# java weblogic.Admin -username devuser -password xxxxxxxxxxx -userconfigfile USER_CONFIG -userkeyfile USER_KEY STOREUSERCONFIG
# -username and -password are values the values that will be encrypted and are NOT checked or used to connect to Weblogic itself.
# Script Usage:
# ./ arg0 arg1
# arg0: the configuration file for your application (path must be relative to $configPath)
# arg1: the version to install
# Script example:
# ./ myApp 1.2.5-SNAPSHOT
# Exit values are:
# 0: OK
# 1: Error
# 2: Arrived at EOF which shouldn't happen

# Path to the file
# The administration URL. Usually your server's /console address
# Where the user config file is stored
# Where the user key file is stored
# Where to find the configuration files
# Where the application EAR must be downloaded (I rely on wget instead of the non-structured upload command of Weblogic)

if [ "$1" = "" ] ; then
	echo "** First param was empty, must be ini file"
	exit 1
if [ "$2" = "" ] ; then
	echo "** Second param was empty, must be version"
	exit 1

# Prepare
cd $setWLSEnvDir
# Copy to better named variable

# Load config file
if [ -f $configPath/$1 ] ; then
	. $configPath/$1
	echo File not found $configPath/$1
	exit 1
# Verify that config file was loaded
if [ "$configFile" != "$1" ] ; then
	echo Expected $1 as config but got $configFile instead
	exit 1
echo "**********************************************************"
echo Group = $groupId
echo App = $appName
echo Version = $newVersion
echo Config = $configFile

# See if must undeploy an earlier version (might be risky, choose your names wisely)
# This command is pretty slow ...
appToUndeploy=$(java weblogic.Deployer -adminurl $adminUrl -userconfigfile $userConfigFile -userkeyfile $userKeyFile -listapps | grep $appName)

if [ $appToUndeploy != "" ] ; then
    echo "** Application found on server, undeploying " $appToUndeploy
	java weblogic.Deployer -adminurl $adminUrl -userconfigfile $userConfigFile -userkeyfile $userKeyFile -undeploy -name $appToUndeploy
	if [ $? -eq 1 ] ; then
		echo "** Auto un-deployment failed"
		exit 1

# Go to upload folder
cd $uploadFolder
# Make a folder with the groupId of the application
if [ ! -d $groupId ] ; then
	mkdir $groupId

cd $groupId

# Remove older version already in directory
if [ -f $appName-$newVersion.ear ] ; then
	echo "** Removing " $appName-$newVersion.ear
	rm $appName-$newVersion.ear

# Download that EAR
wget $downloadUrl/$newVersion/$appName-$newVersion.ear
echo "** Deploying application to server on " $target
if [ -f $appName-$newVersion.ear ] ; then
	# Deploy
	java weblogic.Deployer -adminurl $adminUrl -userconfigfile $userConfigFile -userkeyfile $userKeyFile -deploy -name $groupId.$appName-$newVersion -source $uploadFolder/$groupId/$appName-$newVersion.ear -targets $target

	if [ $? -eq 1 ] ; then
		echo "** Auto deployment failed"
		exit 1
	# Start
	java weblogic.Deployer -adminurl $adminUrl -userconfigfile $userConfigFile -userkeyfile $userKeyFile -start -name $groupId.$appName-$newVersion
	exit 0
	echo "** Freshly downloaded file not found"
	exit 1
exit 2

And a simple configuration file named ‘myapp.ini’, to be placed next to the script:

#The DSL base URL. It'll be suffixed with $newVersion/$appName-$newVersion.ear
#Deployment target for this application
#The groupId of your application (will be used in deployment name)
#The name of your application
#The name of this configuration file. This is to make sure the correct config file is loaded

Given that you already installed your application as MyApplication-1.5.0, you can easily upgrade it to 1.5.2 by calling:

./ myapp.ini 1.5.2

Once finished (~50 seconds later), the application will be installed as com.mycompany.myapp.MyApplication-1.5.2


One thought on “Automating application updates on Weblogic 10

  1. Can you please help on the below points …. Please email me your bash script for the below steps

    1. Take a back up of existing war file to archieve folder.
    2. Place a new war file copying from external server.
    3. Stop the application and untarget server for that specific appliaction.
    4. Delete the application and force shutdown the Managed servers.
    5 Deploy the new war file and target the servers
    6 Start the managed servers accordingly….

    Thanks in Advance….

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s