Sunday 20 May 2018

Stop Application using wsadmin script



Below Script Helps you to Stop Application.

Run below script from Deployment Manager Bin
$pwd
/opt/IBM/WebSphere/AppServer/profiles/Dmgr01/bin
$./wsadmin -f /tmp/StopApp.py DefaultApp gbr_testserver1

Note :Here DefaultApp is Application Name , gbr_testserver1 is server Name

give file name as StopApp.py 
=========================================================================

import sys
from time import sleep

def stopAppOnServer(appName, serverName):
   appready = AdminApp.isAppReady(appName)
   print appready
   if appready == 'false':
                sleep(40)
                appready = AdminApp.isAppReady(appName)
                print appready
   else:
                print "stoping the application "+appName+" on "+serverName+" "
                appManager = AdminControl.queryNames("type=ApplicationManager,process="+ serverName +",*")
                if appManager == "":
                        print "Please make sure whether Application Server is up and running before stoping the applicaiton "   
                AdminControl.invoke(appManager, 'stopApplication', appName)
                appstate = AdminControl.completeObjectName("type=Application,name="+appName+",*")
                if appstate == "":
                        print ""+ appName +" stopped "

# ----------------------------------------------------------------------------------------------------------------------------
# This function verifies whether Application is already Available to Stop or not.
# -----------------------------------------------------------------------------------------------------------------------------
def appexist():
   print " checking for the "+appName+" applicaiton whether it is Available to Stop or not"
   apps = AdminApp.list().split(lineSeparator)
   for applist in apps:
    if applist == appName:
        print "Application is availabe to stop"
        AdminConfig.save()
    else:
        print " ------------------------------------------------"
        print " "+appName+" doesn't exists now so it will not be stopped  "


#----------------------------------------------------------------------------------------
#Main codes start here....
# ----------------------------------------------------------------------------------------
if (len(sys.argv) !=2):
        print " Please enter correct arguments "
        print " ex: StopApp.py sample server1"
else:
        appName = sys.argv[0]
        serverName = sys.argv[1]
        print "Application Name : " +appName
        print "Server Name : " +serverName
        appexist()
        stopAppOnServer(appName, serverName)



Output of Above script will be as follows
=========================================================================

./wsadmin.sh -f /tmp/StopApp.py DefaultApp gbr_testserver1
WASX7209I: Connected to process "dmgr" on node localhostCellManager01 using SOAP connector;  The type of process is: DeploymentManager
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv variable: "[DefaultApp, gbr_testserver1]"
Application Name : DefaultApp
Server Name : gbr_testserver1
 checking for the DefaultApp applicaiton whether it is Available to Stop or not
Application is availabe to stop
ADMA5071I: Distribution status check started for application DefaultApp.
WebSphere:cell=localhostCell01,node=localhostNode01,distribution=true,expansion=notprocessing
ADMA5011I: The cleanup of the temp directory for application DefaultApp is complete.
ADMA5072I: Distribution status check completed for application DefaultApp.
true
stoping the application DefaultApp on gbr_testserver1
DefaultApp stopped


No comments:

Post a Comment