WSadmin Scripts
WSadmin Scripts
LeeWinTai [email protected]
2005-09-23
OurAgenda
JACL Jython
Script examples
2005-09-23
WSADMINConcepts
WSADMINisnotakeyboardrecordingmechanism!
2005-09-23
InteractivevsInlineCommands
Interactivecommands
Telnet or OMVS
Receiveoutput
stopserver install/uninstallapplications
2005-09-23 2005 IBM Corporation
InteractivevsInlineCommands
Inlinecommands
Telnet or OMVS
BBOWIAPPjobusesinlinecommandtoinstalltheadministrativeconsole
2005-09-23
UsingwsadminFromYourWorkstation
wsadmin.batWindows wsadmin.shUnixandLinux
SOAP port
Deployment Manager
wsadmin.shhost<host>port<port>
Isglobalsecurityturnedon? No
Noworries
SOAP port
Yes
CAcertificate mustbeon clientskeyring Provideuserid andpassword
Application Server
2005-09-23
CanWeUseWSADMINIftheServerisDown?
Itdepends!
wsadmin.shconntypenone
HFS
Theserverdoesnothavetobeup
Obviously,thisdoesnotworkfromyourworkstation...
7 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation
CanWeUseWSADMINiftheServerisDown?
Itdepends!
wsadmininremotemode
wsadmin.shconntypesoap wsadmin.shconntypermi
Connectsto server
HFS
2005-09-23
UsingWSADMINWithGlobalSecurityOn
wsadmin.shconntypesoapuser<user>password<pw>
soap.client.props securityEnabled=true
sas.client.props securityEnabled=true
ImportserversCAcertificateontoclientkeyringusingikeyman.(sh|bat) ShouldnotbenecessaryifexecutingwsadminfromUSS
9 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation
IsThisaSecurityExposure?
wsadmin.shconntypesoapuser<user>password<pw>
Specifyuseridand password
soap.client.props
sas.client.props
10
2005-09-23
AreThereMultipleWSADMINs?
OnlyifinanND $dmgr/profiles/default/bin/wsadmin.sh $appserver/profiles/default/bin/wsadmin.sh environment Oneforeach applicationserver Each of these are a managed process to which WSADMIN can connect.
11
2005-09-23
UsingWSADMINObjects
WSADMINusesfourobjects:
AdminApp manipulate applications AdminControl manipulate objects (e.g., servers)
Help self-explanatory
12
2005-09-23
WhatCanIDoWiththeAdminAppObject?
install uninstall edit list
AdminApphelplisting:
13
2005-09-23
AdminAppInstallinganApplication
Q:Whatoptions?
$AdminApp install <filename> <options>
A:$AdminAppoptions
Notalloptionsarerequired forinstallation
AdminAppInstallationOptions
$AdminApp options <earfile> Use this to find options specific to the ear file
Doesntwork
$AdminApp taskInfo <earfile> preCompileJSPs
15 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation
AdminAppInstallationOptions
$AdminApp taskInfo <earfile> MapModulesToServers
wsadmin>$AdminApptaskInfo/u/tai/SuperSnoop.earMapModulesToServers MapModulesToServers:Selectingservers Specifytargetssuchasapplicationserversorclustersofapplicationserverswhereyouwanttoinstall themodulescontainedinyourapplication.Modulescanbeinstalledonthesameapplicationserverordispersed amongseveralapplicationservers.Also,specifytheWebserversastargetsthatwillserveasroutersforrequests tothisapplication.Thepluginconfigurationfile(plugincfg.xml)foreachWebserverisgeneratedbasedonthe applicationswhichareroutedthroughit. WASX7348I:EachelementoftheMapModulesToServerstaskconsistsofthefollowing3fields:"Module","URI","Server". Ofthesefields,thefollowingmaybeassignedvalues:"Server" andthefollowingarerequired:"Server" Thecurrentcontentsofthetaskafterrunningdefaultbindingsare: Module:SuperSnoopWeb URI:SuperSnoopWeb.war,WEBINF/web.xml Server:WebSphere:cell=wsc1.washington.ibm.com,node=wsc1.washington.ibm.com,server=server1
16 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation
AdminAppUninstallinganApplication
Wow,thatwaseasy!
$AdminAppuninstallmyapp
Youmustusetheapplicationname, nottheearfilename
Saving is not necessary after uninstallation
AdminConfig
Usedtocreate,remove,ormodifyconfigobjectsvirtualhosts,servers,etc. LetstakealookattheWebContainerobject
$AdminConfig attributes WebContainer Use this to find a list of all types $AdminConfig types Use this to find a list of all types
. . WSGWInstance WSGWProxyService WSGWTargetService WebContainer WebContainerInboundChannel WebModuleConfig WebModuleDeployment WebModuleRef . .
18 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation
. . "defaultVirtualHostNameString" "enableServletCachingboolean" . .
AdminConfigWhichWebContainer?
$AdminConfig show <object> Show attributes of a given config object
wsadmin>$AdminConfig show WebContainer WASX7015E: Exception running command: "$AdminConfig show WebContainer"; exception information: com.ibm.ws.scripting.ScriptingException: WASX7077E: Incomplete config id: need closing parenthesis in "WebContainer"
$AdminConfig modify <object> <attributes> Change specified attributes of a given config object
wsadmin>$AdminConfig modify (cells/h6cell/nodes/h6nodea/servers/h6sr03a|server.xml#WebContainer_1112139804785) {{ enableServletCaching true }}
19
2005-09-23
AdminControl
Save changes Start / stop servers Initiate synchronization
$AdminControlsave
$AdminControlstartServerh6sr03a
WASX7015E: Exception running command: "$AdminControl startServer h6sr03a"; exception information: com.ibm.ws.scripting.ScriptingException: WASX7344E: Node name is required when the client is connected to process type "DeploymentManager".
$AdminControlstartServerh6sr03ah6nodea $AdminControlstopServerh6sr03a
WASX7015E: Exception running command: "$AdminControl startServer h6sr03a h6nodea"; exception information: com.ibm.websphere.management.exception.ConnectorException org.apache.soap.SOAPException: [SOAPException: faultCode=SOAP-ENV:Client; msg=Read timed out; targetException=java.net.SocketTimeoutException: Read timed out]
20
2005-09-23
AdminControlNodeSynchronization
set var [$AdminControl completeObjectName type=NodeSync,node=h6nodea,*] $AdminControl invoke $var sync
WebSphere:platform=common,cell=h6cell,version=6.0.2.1,name=nodeSync, mbeanIdentifier=nodeSync,type=NodeSync,node=h6nodea,process=nodeagent
Thismustbedoneforeachnodethatyouwantsynchronized.
21
2005-09-23
ExternalScriptsJaclandJython
Benefitsofusinganexternalscript
UsefoptiontotellWSADMINtouseanexternalscript:
$ ./wsadmin.sh -f install.jacl
Jacl
ImplementationoftheTclinterpreterwritteninJava DefaultscriptinglanguageexpectedbyWAS
Jython
ImplementationofPythonwritteninJava
22 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation
CommandLineParametersJacl
Takingparametersfromthecommandline Usethisscriptformultipleservers,nodes,applications,etc.
puts writes to stdout (by default) if wrong number, go here argc the number of arguments check for correct number of arguments lindex retrieve list element argv list of arguments
if { !($argc == 5) } { puts You don't have the correct puts Usage: ... } else { set serverName [lindex $argv set nodeName [lindex $argv set cellName [lindex $argv set application [lindex $argv set appName [lindex $argv }
set read / write variables
2005-09-23
nu
set serverName to first argument set nodeName to second argument etc.
0] 1] 2] 3] 4]
23
CommandLineParametersJython
len number of items in a list sys.argv list of arguments
if (len(sys.argv) != 5): print You don't have the correct nu print Usage: ... } else { serverName = sys.argv[0] nodeName = sys.argv[1] cellName = sys.argv[2] application = sys.argv[3] appName = sys.argv[4] }
getopt not available
24
2005-09-23
VerifyingtheNodeExists
llength returns number of items in a list
Jac
l
print error message if node is not found
set node [$AdminConfig getid /Node:$nodeName/] if {[llength $node] == 0} { puts "Error -- node not found for name $nodeName" return } getid returns configid of an object nodeName passed in as an argument
Jy
node = AdminConfig.getid("/Node:" + nodeName + "/") print "ex1: checking for existence of node " + nodeName if len(node) == 0: print "Error -- node not found for name " + nodeName return
th on
print error message if node is not found
25
2005-09-23
VerifyingtheServerExists
Determineifthegivenserverisavailable
set runningServer [$AdminControl completeObjectName type=server,node=$nodeName,process=$serverName,* if {[llength $runningServer] == 0 } { puts Error: Server not running... return }
Jac l
Jy
th on
26
2005-09-23
CheckExistingApplications
Checktoseeiftheapplicationisalreadyontheserver...
foreach loops over each item in list AdminApp list returns list of all install applications foundApp set to true if app exists; false otherwise AdminApp list returns list of all install applications split splits string into list of strings
set foundApp false foreach app [$AdminApp list] { if { $app == $appName } { set foundApp true } Jac } l compare app to appName
th on
27
2005-09-23
InstallingandRemovinganApplication
$AdminApp uninstall $appName
Jac l
set options [list -server $serverName] lappend options -node $nodeName -appname $appName $AdminApp install $app $options $AdminConfig save lappend append list elements install self-explanatory app ear file we are deploying
uninstall self-explanatory
AdminApp.uninstall(appName)
options = [-server + serverName options = options + -node + nodeName options = options + -appname + appName + ] AdminApp.install(app,options) Jy AdminConfig.save()
th on
28
2005-09-23
CreatingaNewServerJacl
nodeName passed in as an argument set name [list name $serverName] set server [$AdminConfig create Server $nodeName name $name] create Server self-explanatory
NestedOptions
set http [list [list sslEnabled false] [list address [list [list host {}] [list port 9080]]]] set https [list [list sslEnabled true] [list address [list [list host {}] [list port 9081]]] [list sslConfig DefaultSSLSettings]] set transports [list transports:HTTPTransport [list $http $https]] set webcontainer [$AdminConfig list WebContainer $server] $AdminConfig modify $webcontainer [list $transports]
CreatingaNewServerJython
name = [["name", serverName]] server = AdminConfig.create(Server, node, name)
http = [["sslEnabled", "false"], ["address", [["host", ""], ["port", 9080]]]] https = [["sslEnabled", "true"], ["address", [["host", ""], ["port", 9081]]], ["sslConfig", "DefaultSSLSettings"]] transports = [["transports:HTTPTransport", [http, https]]] webcontainer = AdminConfig.list("WebContainer", server) AdminConfig.modify(webcontainer,transports)
30
2005-09-23
SynchronizationOfAllNodes
list get a list of all nodes
set node_ids [$AdminConfig list Node] foreach node $node_ids { set nodename [$AdminConfig showAttribute $node name] set nodesync [$AdminControl completeObjectName type=NodeSync,node=$nodename,*] if { !($nodesync=="") } then { $AdminControl invoke $nodesync sync } }
Jac l
Check for empty string because we dont to sync the dmgrs node list get a list of all nodes
Use for loop to cycle through all nodes split split list into elements
node_ids = AdminConfig.list("Node").split() for node in node_ids: nodename = AdminConfig.showAttribute(node,"name") nodesync = AdminControl.completeObjectName("type=NodeSync,node=" + nodename + ",*") if nodesync != "": AdminControl.invoke(nodesync,"sync")
Jy
th on
31
2005-09-23
Questions?
32
2005-09-23