Showing posts with label wsadmin scripts. Show all posts
Showing posts with label wsadmin scripts. Show all posts

Thursday, April 1, 2010

Stop and uninstall an application using wsadmin

Before the application can be unsinstalled it must be stopped.
Steps:

1. Open wsadmin (with jython)
1.1 Go to "WebSphere_Profile_Root"/bin
1.2 Execute
wsadmin.sh(.bat) -lang jython
1.3 Enter UserID/Password (if promted)

2. Define needed cell and node variables
2. Execute
cell=AdminConfig.list('Cell')
cellname=AdminConfig.showAttribute(cell,'name')
nodes=AdminConfig.list('Node',cell)
nodename=AdminConfig.showAttribute(nodes,'name')
-----------------------------------
(Alternative:
e.g.: nodename=NAME_OF_NODE)

3. Define application manager variable
3.1 Execut
appManager=AdminControl.queryNames
('type=ApplicationManager,cell='+cellname+',
node='+nodename+',process=<APP_SERVER_NAME>,*')
3.2 To print out variable execute
print appManager
4. Assign application to variable
4.1 Execute
app=AdminControl.queryNames
('type=Application,cell='+cellname+',node='+nodename+',
process=<APP_SERVER_NAME>,J2EEName=<NAME_OF_APPLICATION>,*')
4.2 To print out variable execute
print app
5. Define application name to variable
5.1 Execute
appName=AdminControl.getAttributes(app,'name')
5.2 To print out variable execute
print appName
6. Stop application
6.1 Execute
AdminControl.invoke(appManager,'stopApplication', appName)
7. Uninstall application
7.1 Execute
AdminApp.uninstall(appName)
8. Save changes
8.1 Execute
AdminConfig.save()


Hint:
It is easier to use administrative console :-)
<APP_SERVER_NAME> = Name of server (JVM) where the application is deployed
<NAME_OF_APPLICATION> = Name of the application (not the ear-files name)

Install and start an application using wsadmin

opy the application ear-file to <WAS_PROFILE_ROOT>/installableApps

1. Open wsadmin (with jython)
1.1 Go to "WebSphere_Profile_Root"/bin
1.2 Execute
wsadmin.sh(.bat) -lang jython
1.3 Enter UserID/Password (if promted)

2. Define needed cell and node variables
2. Execute
cell=AdminConfig.list('Cell')
cellname=AdminConfig.showAttribute(cell,'name')
nodes=AdminConfig.list('Node',cell)
nodename=AdminConfig.showAttribute(nodes,'name')
-----------------------------------
(Alternative:
e.g.: nodename=NAME_OF_NODE)


3. Install application
3.1 Execute
AdminApp.install('../installableApps/<NAME_OF_EAR_FILE>',['-appname <NAME_OF_APPLICATION>'])

4. Save changes
4.1 Execute
AdminConfig.save()

5. Define application manager variable
5.1 Execute
appManager=AdminControl.queryNames
('type=ApplicationManager,cell='+cellname+',
node='+nodename+',process=,*')
5.2 To print out variable execute
print appManager
6. Assign application to variable
6.1 Execute
app=AdminControl.queryNames
('type=Application,cell='+cellname+',node='+nodename+',
process=,J2EEName=,*')
6.2 To print out variable execute
print app
7. Define application name to variable
7.1 Execute
appName=AdminControl.getAttributes(app,'name')
7.2 To print out variable execute
print appName
8. Start application
8.1 Execute
AdminControl.invoke(appManager, 'startApplication',appName)


Hint:
It is easier to use administrative console :-)
<APP_SERVER_NAME>= Name of server (JVM) where the application is deployed
<NAME_OF_APPLICATION> = Name of the application (not the ear-files name)

Sunday, March 21, 2010

Modifying the starting weight of applications using scripting (jython)

1. Update the starting weight of an Enterprise Application:
 
AdminConfig.modify
(AdminConfig.showAttribute
(AdminConfig.getid("/Deployment:myApps/"),
"deployedObject"),[['startingWeight','20']])

Note: Valid range for 'startingWeight': 0 and 2147483647

2. Update the class loader mode of an Enterprise Application:
 
AdminConfig.modify
(AdminConfig.showAttribute(AdminConfig.showAttribute
(AdminConfig.getid('/Deployment:myApps/'),'deployedObject'),
'classloader'),[['mode','PARENT_LAST']])

Note: Valid values for 'mode' : PARENT_FIRST, PARENT_LAST

3. Update the WAR class loader policy of an Enterprise Application:
 
AdminConfig.modify
(AdminConfig.showAttribute
(AdminConfig.getid('/Deployment:myApps/'),
'deployedObject'),[['warClassLoaderPolicy','SINGLE']])

Note: Valid values for 'warClassLoaderPolicy':
SINGLE (Application), MULTIPLE (Module;default)

4. Update the starting weight of individual modules (Web or EJB) within an EAR -->

def modifyModStartingWeight(appName, modStWeight, modName):
    global AdminConfig
    try:
        refParam = "/Deployment:" + appName + "/"
        depRef = AdminConfig.getid(refParam)
        depObjectRef = AdminConfig.showAttribute(depRef, 'deployedObject')
        modules = AdminConfig.showAttribute(depObjectRef, 'modules')
        arrayModules = modules[1:len(modules)-1].split(" ")
        for module in arrayModules:
        tmpStr = AdminConfig.showAttribute(module,'uri')
                if tmpStr == modName:
                        AdminConfig.modify(module, [['startingWeight', modStWeight]])
                        print "New starting weight for " +
AdminConfig.showAttribute(module,'uri') + "is " +
AdminConfig.showAttribute(module,'startingWeight')
        try:
            AdminConfig.save()
        except:print "AdminConfig.save() caught exception. \n"
    except: print "AdminConfig.modify(" + appName + ") caught 

###########################################################################

Friday, March 12, 2010

wsadmin rotate jvm log files

Simple, working, rotates logs at 10mb saving max 5 files.

# rotateWasLogEPRN.py
# Setup WAS Log file rotations
# for yourserver
# 9/10/2008
# Mike Huffsteder - WTA
#
# Implement:
# ./wsadmin.sh -lang jython -f $FILE_LOCATION/rotateWasLogEPRN.py >> $TO_LOG_FILE
#
# You can add this as you have other scripts in the deployment script
# if you need help please let me know.
#
#

print "Changing the SystemOut & SystemErr log file rotation settings"
var1 = AdminConfig.getid('/Cell:yourcell/Node:yournode/Server:yourserver/')

log = AdminConfig.showAttribute(var1, 'outputStreamRedirect')
log2 = AdminConfig.showAttribute(var1, 'errorStreamRedirect')

AdminConfig.modify(log, '[[rolloverSize 10] [maxNumberOfBackupFiles 5]]')
AdminConfig.modify(log2,'[[rolloverSize 10] [maxNumberOfBackupFiles 5]]')

AdminConfig.save()

print "New SystemOut settings 9-10-08"
AdminConfig.show(log).split("\n")
print "New SystemErr settings 9-10-08"
AdminConfig.show(log2).split("\n")

Thursday, February 18, 2010

Dissable security

To disable global security either edit the security.xml file or use the wsadmin tool.




$WAS_HOME\config\cells\cellname\security.xml



Using WAS command-line client wsadmin (run with was user or root privileges):

1. Open a connection to local WAS in offline mode

wsadmin -conntype NONE



2. Turn off global security

wsadmin> securityoff



3. Save

wsadmin> $AdminConfig save

How to increase the heap size from wsadmin

How to increase the heap size from wsadmin

AdminTask.setJVMInitialHeapSize( ‘[ -nodeName ' + n + ' -serverName ' + s + ' -initialHeapSize ' + str( 384 ) + ' ]‘ )


AdminTask.setJVMMaxHeapSize( ‘[ -nodeName ' + n + ' -serverName ' + s + ' -maximumHeapSize ' + str( 944 ) + ' ]‘ )

# or you could set a bunch of JVM properties in one call

AdminTask.setJVMProperties( ‘[ -nodeName ' + n + ' -serverName ' + s + ' -initialHeapSize ' + str( 384 ) + ' -maximumHeapSize ' + str( 944 ) + ' -verboseModeGarbageCollection true ' + ' ]‘ )