Wednesday, April 1, 2015

WebLogic Wrapper Scripts

Administrators with automation skill would perform than many admins. Requirement makes you to write automation scripts. I was working on Oracle Virtual Box, which is running SSH service. Hence I am able to connected thru PUTTy to the ubuntu Guest Linux server. By making Static IP configuration on the additional network adapter this was happen to possible.

 Everything going good! when I ran the WebLogic server from the PuTTY. It is working until when it is connected and alive. Once I went for break/Lunch the Windows system went to sleep then WebLogic server stopped due to PuTTY session inactive. To avoid this we can use the Wrapper start scripts.

 Idea behind the wrapper script/ psuedo code

  1. Using the startWebLogic.sh script in background using &
  2. use the nohup -- no hungup to run the process even the PuTTY inactive or closed
  3. The log file generated by starting WebLogic server redirected to a separate file.
  4. The Standard error file also merged with standard output log 
  5. Display the tail command after doing the above
  6. Additionally you can add back up of old WebLogic file with a time stamp this can be applicable in Production environments.
Startup Wrapper Scripts

Start WebLogic Admin Server with wrapper script

Here is the nohup usage sample:
$ nohup /domain/path/startscript.sh &

No hangup

The nohup UNIX command only writes to nohup.out if the output is otherwise to the terminal. If you redirect the output of the command somewhere else - including /path/redirect or some casees you can use /dev/null - that's where it goes instead.

nohup startWebLogic.sh >/path/redirect 2>&1   # doesn't create nohup.out

In modern bash and zsh (but not ksh) SHELLs you can shorten that to >&/path/redirect.

You can also use as follows:

nohup startWebLogic.sh >/path/redirect 2>&1&


Applying the above ideas into the wrapper scripts you can write a sample startAdmin.sh script in your WebLogic Domain.

New thoughts implemented that is logs path would be automatically created by the script now. I had this for long time but today 01-April-2015 came to improved version as 0.2 as published now!
#!/bin/bash
# Purpose : WebLogic AdminServer wrapper script which redirects logs to admin.out
# Author : Pavan Devarakonda  ver 0.2
# Category  : WebLogic Best Practices
# Override  : Yes, You can modify LOGDIR, LOGPATH values 

clear
DOMAIN_HOME=${PWD}
LOGDIR=$DOMAIN_HOME/logs
LOGPATH=$LOGDIR/admin.out
export PATH=$PATH:$DOMAIN_HOME

if [ -d $LOGDIR ]; 
 nohup bash -c "$DOMAIN_HOME/startWebLogic.sh 2>&1 >>$LOGPATH" &
 echo .
 echo "Starting admin server..."
 echo "tail -f $LOGPATH"
 exit 0
else
 echo "Log path doesn't exists... creating directory now!!"
 mkdir -p $LOGDIR
 ./$0
fi 

Similarly you can write the wrapper codes for WebLogic Managed servers, NodeManager start scripts, so that your keep running your WebLogic related services without any hangs :)

 ii. Customized start managed server script

The above wrapper scripts there must inclusion of domain name recommended for non-production or multiple domains running on the same machines. There is a need to specify speparate standard output file path, if it is pre-production or Performance load testing environment you must also include GC logs path. Some of the WebLogic managed servers must include PRE_CLASSPATH that need to be processed before weblogic.jar in the CLASSPATH and some of the library jar files must be processed after the weblogic.jar, set them in a separate directories pre and post. Add them to CLASSPATH and it must be exported before startWebLogic.sh or startManagedWebLogic.sh called.

The following start wrapper script saved as "startms.sh" assuming that you might need few instance specific properties need to refer in startWebLogic.sh script. 


#==================================================
# The managed server name as argument for this script
# File : startms.sh 
 
# Usage: ./startms.sh mymanaged01  
#====================================================
INSTANCE=$1
export INSTANCE # not mandatory 
SOURCE=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
cp $INST_HOME/$INSTANCE/logs/$INSTANCE.out $INST_HOME/$INSTANCE/logs/$INSTANCE.out.bkp
nohup $SOURCE/startManagedWebLogic.sh $INSTANCE >$INST_HOME/$INSTANCE/logs/$INSTANCE.out 2>&1 &
echo tail -f $INST_HOME/$INSTANCE/logs/$INSTANCE.out

Here $INST_HOME is defined in the user profile script.

These customized start scripts for admin server and managed servers. In the script make a copy of the last server instance log to instance.out_bkp. Some times due to some panic situations servers might crashed, after monitoring you found that it happen so restarting server should not loss that lost logs. If you maintain the backup of logs file automatically before starting the instance, then you are saved with that backup log file for further analysis about that crash.

Here in the above script, most of the UNIX/Linux environments it would work fine. Your script could use "nohup" that means no hung up when the remote machine is accessed with tools like SSH/PuTTY.

Some older environments (before WebLogic 12c) using JRockit as Java vendor. Better you include the following lines in the wrapper scripts will run in JRockit JVM.

JAVA_VENDOR="BEA"
export JAVA_VENDOR



If you create this script in development/QA environment same script can be used for UAT/PRE-Production or Production because keeping it more portable and flexible with SDIR (source directory path).

Keep writing us your comments for betterment in this blog.

Sunday, December 21, 2014

JMS MessageBridgeRuntime monitoring

We were in the developing a orchestration application platform which requires multiple JMS Messaging bridges. We have configured near 10 Bridges to different external systems. When maanaged servers each one host a bridge it will be doubles the count that we cannot monitor on single screen in the  admin console. On the Weblogic Admin Console we can monitor the Bridge status using Bridges -> Monitoring tab.For testing we had started single managed server and checked the Bridge monitoring status.

 It could be either 'Forwarding Messages' or 'Fail to connect Source' or 'Fail to connect to Target'. The actual tragedy starts when it comes to production environment, where we have multiple managedservers in the cluster. Usually Bridges status matters when it connects to third party messaging providers such as MQ Series or something else. Assume that, there are 10 Bridges deployed to 10 managed servers on the WebLogic Console becomes very slow when you use 'Monitoring' tab to show 100 result rows from the JMX. Alternative is we must develop a Python script or something else. Searched in search engines but no luck, OTN forums have same discussions but using python there is no output or MessagingBridgeRuntime is not there on the MBean tree. This is due to bug in WebLogic 9.2 ver to WebLogic 10.3.6. It is fixed in WebLogic 12c. So previous version need to update the patch. Alternative to patch you can use weblogic.Admin utility. The following scripting trick works well to show below output.

Fetching RUNNING managed server list

The weblogic.Admin command can give you the CLUSTERSTATE which will give the all the managed servers status(such as RUNNING, SHUTDOWN, UNKNOWN, ADMIN, FAILED etc.,) in that cluster. To give more robustness to the script, extract the that running list of managed servers. So that we can get all live server bridges status. using our 'awk' seizer we can pick the managed server names which 'grep' RUNNING state.

managdserver=`java weblogic.Admin -url t3://$admURL -username weblogic -password $admpasswd  CLUSTERSTATE | grep managed |grep RUNN|awk -F'-' '{print $1}'`
Now the script

#!/bin/ksh
#================================================
# This is MessageBridge Monitoring script
# Updated by: Pavan Devarakonda
#================================================
admpasswd=Secret
admURL= hostname.company.com
domain=mydomain

echo "Starting at:"
date # For trace the time spending for this monitoring script
managdservers=`java weblogic.Admin -url t3://$admURL -username weblogic -password $admpasswd  CLUSTERSTATE | grep managed |grep RUNN|awk -F'-' '{print $1}'`

for mserver in managdservers
do
 echo "Managed Server :" $mserver
 for bridge in `grep MessagingBridge mydomain.properties| cut -d'=' -f2`
 do
  echo " "
  java weblogic.Admin -url t3://$admURL -username weblogic -password $admpasswd GET -pretty -type MessagingBridgeRuntime -mbean $domain:ServerRuntime=$mserver,Name=$bridge,Type=MessagingBridgeRuntime,Location=$mserver -property Description -property Name -property State | grep -v MBeanName
  
 done
done
echo "Bridge Status completed "
date
You must create a properties from your domain as follows:
mydomain.properties
#===================
srvr_target1=ms1_mydomain
srvr_target2=ms2_mydomain
srvr_target3=ms3_mydomain

bridge1=MQMessagingBridge1
bridge2=JMSMessagingBridge2

How to execute this script?

To execute this script you must have weblogic.jar in the CLASSPATH and java must be in the PATH that is JAVA_HOME/bin must be appended in your PATH environment variable. To execute the above Kron shell script
$ ./bridgeMonitor.ksh

To know more on Bridges and how to configure with simple python script. you can find on WLSTbyExample blog link




Technorati claim code QK7QN6U9ZST6

Blurb about this blog

Blurb about this blog

Essential Middleware Administration takes in-depth look at the fundamental relationship between Middleware and Operating Environment such as Solaris or Linux, HP-UX. Scope of this blog is associated with beginner or an experienced Middleware Team members, Middleware developer, Middleware Architects, you will be able to apply any of these automation scripts which are takeaways, because they are generalized it is like ready to use. Most of the experimented scripts are implemented in production environments.
You have any ideas for Contributing to a Middleware Admin? mail to me wlatechtrainer@gmail.com
QK7QN6U9ZST6