Required a Python script for check if the WebLogic admin server is 'Running' or Not recursively
To execute this you have 2 options
1. Executing forever
2. timeout, interval as aruguments
If it isn't keep checking forever or as long as is passed on the command- line with the -t parameter. The wait between checks can be modified with the -i parameter on the command line.
There could be your environemnt also need such options for a Python script. This script will be a example for such requirements.
Script Logic
Hey Smart WLAs what do you think the solution for the above problem statement?? Got any idea? I know you guys are very intelligents!! hope you got idea about getting options at command-line. Yes, it is possible for our WLST Script too, getopt is a python capability which allows us to accept the command line arguments with options -t, -i. Of-course my buddy struggle to find this clues on the Google almost took 2 days.
- To read the command line values as dictionary and split as key, value pair and compare the key with desired options then performing the script according to user choice.
- If the user failed to enter the options at commandline exception handling with usage funcation.
- WLST connect to admin server regular function.
- Using sleep method for stopping the WLST execution for some time interval. Repeating this process till given timeout or run this above steps for forever.
#!/usr/bin/python # Author : Raghunath # Save Script as : checkAdmin.py import time import getopt import sys # ========= connecting to Admin server ================== def connectAdmin(): r=1 try: # Update the following line as per your environment connect(url='t3://AdminHost:AdminPort') print "*** Connected sucessesfully ***" r=0 sys.exit(r) except: return r def usage(): print "Usage:" print "checkAdmin.py [-t timeout] [-i interval]" print "exit with 0 if find Admin Server" print "exit with 1 if do not find Admin Server" print "if no timeout is given, look for Admin Server until it is found" # ===== Default settings =================== Timeout = 0 Interval = 25000 forever = 1 #====== Main program =============================== try: opts, args = getopt.getopt( sys.argv[1:], "t:i", ["Timeout","Interval"] ) except getopt.GetoptError, err: print str(err) usage() sys.exit(2) #===== Handling get options =============== for opt, arg in opts: if opt == "-t": Timeout = arg forever = 0 elif opt == "-i": Interval = arg while (forever == 1) or (Timeout > 0): if connectsave() == 1: print 'Now, Sleeping 15 sec *************' java.lang.Thread.sleep( Interval ) print 'Waking up after 15 sec ...' print 'done'
To run the above script you can make a small shell script as follows:
# checkAdmin.sh
. $WL_HOME/server/bin/setWLSEnv.sh
java weblogic.WLST checkAdmin.py "$@"
Run this shell script as :
$ checkAdmin.sh -t 100 -i 20
or you call directly python script as follows
$ java weblogic.WLST checkAdmin.py -t 100 -i 20
Note that indentation is must for every Python script, please double check before you run the script.
Write back for any issues ariases when you execute the script in your environment.
Referneces:
# email functionality base on http://docs.python.org/library/email-examples.html