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


Start Application using wsadmin script

Below Script Helps you to Start Application.

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

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

give file name as StartApp.py 
=========================================================================
import sys
from time import sleep

def startAppOnServer(appName, serverName):
   appready = AdminApp.isAppReady(appName)
   print appready
   if appready == 'false':
                sleep(40)
                appready = AdminApp.isAppReady(appName)
                print appready
   else:
                print "starting 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 starting the applicaiton "
                        AdminControl.invoke(appManager, 'startApplication', appName)
                appstate = AdminControl.completeObjectName("type=Application,name="+appName+",*")
                if appstate != "":
                        print ""+ appName +" started "

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


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




output of Above Script will be as follows
=========================================================================

$./wsadmin.sh -f /tmp/StartApp.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 Start or not
Application is availabe to start
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
starting the application DefaultApp on gbr_testserver1
DefaultApp started

Sunday 8 April 2018

creating dmgr profile using silent mode



creating dmgr Profile

/tmp$ cat > dmgr_creation_response_File_txt
create
profileName=qat_dm
templatePath=/data/was855_qat/WebSphere/AppServer/profileTemplates/management
profilePath=/data/was855_qat/WebSphere/qat_dm
nodeName=node0151_qat_dm
dmgrHost=dmgrhost0150.machine.group
cellName=qat_cell
enableAdminSecurity=true
startingPort=30001
adminUserName=wasadm
adminPassword=wasadm
cellID=qat
omitAction=defaultAppDeployAndConfig



bin$ ./manageprofiles.sh -response /tmp/dmgr_creation_response_File_txt

if Appserver Got Deleted then restoring it

if Appserver gor deleted accidentally then

copy some Appserver directory to deleted Appserver location

then check

$   grep cell_name setupCmdLine.sh 

$ perl -p -i -e  's/oldcellname/newcellname/g'  setupCmdLine.sh



now after running above command it will replace all copied cell name with deleted cell name.
 here old cell name is copied other cell name  and new cell name is deleted cell name.


now check again check with below you will get all cell name with deleted cell name

$   grep cell_name setupCmdLine.sh 


Note: Ensure Perl is available on server before going for above



Generating Session cookie with TimeStamp

Application servers > server_name. Under Web Container Settings, click Web container transport chains > chain_name > HTTP Inbound Channel > Custom Properties > New

v0CookieDateRFC1123compat = true

Note: v0CookieDateRFC1123compat = false     by default.

By default, the value for the V0 Set-Cookie header Expires attribute is specified in the two digit year format. Set the v0CookieDateRFC1123compat property to true if you need to use the older RFC1123, which requires a four digit year format value for the V0 Set-Cookie Expires attribute.