Categories

[Weblogic] How to automate tasks

You are here:
< All Topics

Hello everybody,

today we’re going to talk about how you can automate weblogic tasks, like stop, start and update deployments.

In this article we suppose to use a weblogic cluster with a single deployment.

Let’s start!

ENVIRONMENT

  • Oracle Weblogic 11g/12c
  • Red Hat 7

1 – Creating directory and configuration file

First of all, we’re going to create a a directory with a talking name (for example, cluster name or ear name) where we’re going to put all the scripts.

$ mkdir ${CLUSTER_NAME}

Then, we’re going to write configuration file, where we’re going to write cluster’s name, ear’s name and location and admin info.

$ vi conf.sh
#!/bin/bash
CLUSTER='' #cluster name
SET_DOMAIN_ENV='' #the path of setDomainEnv.sh
ADMIN_URL='' #url of admin server
USER='' #a user that can perform stop, start and deploy
PASSWORD='' #the user's password
APP_NAME= #deployment's name on weblogic
EARDIR= #ear path
SERVERNUM= #number of servers

It’s useful to define an EARDIR because, for example, it could be a network fs where you dev team stores the new ear to deploy.

2 – Script for stop

So, now we can define a stop script that writes a log file.

$ vi stop.sh
#!/bin/bash
BASEDIR=$(dirname "$0")
source $BASEDIR/conf.sh
LOG=$BASEDIR/stop.log
>$LOG
source ${SET_DOMAIN_ENV}
java weblogic.WLST << EOF >> ${LOG}
connect("${USER}","${PASSWORD}","${ADMIN_URL}")
progress=shutdown('${CLUSTER}',"Cluster",force='true',block='true')
state("${CLUSTER}","Cluster")
exit()
EOF

shutdown_server=$(grep SHUT ${LOG} | wc -l)

if [ ${shutdown_server} -eq ${SERVERNUM} ]
then
        exit 0
else
        exit 255
fi

So, in this way, you’re going to shutdown your servers and give a return code, that can be useful if your going to launch it from scheduler or orchestrator (Autosys or HPOO)

3 – Script for deploy

Now we can define a deploy script.

$ vi deploy.sh
#!/bin/bash
BASEDIR=$(dirname "$0")
source $BASEDIR/conf.sh
LOG=$BASEDIR/deploy.log
source ${SET_DOMAIN_ENV}
x=0

towait='tail -n 1 /tmp/queue_v12'
echo $$ >> /tmp/queue_v12

while [ kill -0 $towait > /dev/null 2>&1 ] && [ $x -lt 60 ]
do
    sleep 10
    x=$(($x+1))
done

>${LOG}

java weblogic.Deployer -adminurl ${ADMIN_URL} -user ${USER} -password ${PASSWORD} -redeploy -name ${APP_NAME} -source "${EARHOMEDIR}${APP_NAME}.ear" >> ${LOG}

EXIT_CODE=$?

So, here we’re going to create a queue for concurrent deployment tasks that waits for 600 seconds or that the tasks before you has finished. The we use weblogic.Deployer for updating the ear and get the return code for the same reason explained before.

4 – Script for start

Finally, we can define the script for starting the application.

$ vi start.sh
#!/bin/bash
BASEDIR=$(dirname "$0")
source $BASEDIR/conf.sh
LOG=$BASEDIR/start.log
>$LOG
source ${SET_DOMAIN_ENV}
java weblogic.WLST << EOF >> ${LOG}
connect("${USER}","${PASSWORD}","${ADMIN_URL}")
progress=start('${CLUSTER}',"Cluster")
state("${CLUSTER}","Cluster")
exit()
EOF

running_server=$(grep RUNNING ${LOG} | wc -l)

if [ ${running_server} -eq ${SERVERNUM} ]
then
        exit 0
else
        exit 255
fi

It’s very similar to stop.sh!

So now you can schedule your own stop & start task, or you can create your flow of stop, redeploy and start!

Regards

Table of Contents