WSadmin Scripts

  • Published on
    10-Nov-2014

  • View
    93

  • Download
    0

Embed Size (px)

Transcript

<p>IBM Washington Systems Center</p> <p>WebSphere Scripting: WSADMIN, jacl, jython</p> <p>LeeWinTai tai@us.ibm.com</p> <p>Advanced Technical Support</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>OurAgenda</p> <p>WSADMIN basics Scripting with WSADMIN</p> <p>JACL Jython</p> <p>Script examples</p> <p>2</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>WSADMINConceptsWSADMINisnotakeyboardrecordingmechanism!</p> <p>WSADMINisascriptinginterfaceusedatthecommandline. Windows,Linux,USS WSADMINcan: Install/uninstallapplications Stop/startservers Createnewservers</p> <p>3</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>InteractivevsInlineCommandsInteractivecommandsTelnet or OMVS</p> <p>Entercommand Usefulforquickadministrativetasks Entercommand4 IBM Washington Systems Center</p> <p>Receiveoutput</p> <p> stopserver install/uninstallapplications2005-09-23 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>InteractivevsInlineCommandsInlinecommandsTelnet or OMVS</p> <p>Usectoindicate inlinecommand Command</p> <p>BBOWIAPPjobusesinlinecommandtoinstalltheadministrativeconsole</p> <p>5</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>UsingwsadminFromYourWorkstationwsadmin.batWindows wsadmin.shUnixandLinuxSOAP port</p> <p>Deployment Manager</p> <p>wsadmin.shhostport</p> <p>Isglobalsecurityturnedon? NoNoworries</p> <p>SOAP port</p> <p>YesCAcertificate mustbeon clientskeyring Provideuserid andpassword</p> <p>Application Server</p> <p>6</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>CanWeUseWSADMINIftheServerisDown?Itdepends!</p> <p>wsadmininlocalmode Manipulates configurationdata</p> <p>wsadmin.shconntypenone</p> <p>HFS</p> <p>Theserverdoesnothavetobeup</p> <p>Obviously,thisdoesnotworkfromyourworkstation...7 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>CanWeUseWSADMINiftheServerisDown?Itdepends!</p> <p>wsadmininremotemodewsadmin.shconntypesoap wsadmin.shconntypermi</p> <p>Connectsto server</p> <p>!</p> <p>Manipulates Itisnotrecommendedtouseremotemode andtheadminconsolesimultaneously configurationdata</p> <p>HFS</p> <p>8</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>UsingWSADMINWithGlobalSecurityOnwsadmin.shconntypesoapuserpassword</p> <p>soap.client.props securityEnabled=true</p> <p>sas.client.props securityEnabled=true</p> <p>ImportserversCAcertificateontoclientkeyringusingikeyman.(sh|bat) ShouldnotbenecessaryifexecutingwsadminfromUSS9 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>IsThisaSecurityExposure?wsadmin.shconntypesoapuserpassword</p> <p>Hmm..Icoulduse pstodisplay runningprocesses Grr...Disgruntledemployee</p> <p>Specifyuseridand password</p> <p>soap.client.props</p> <p>sas.client.props</p> <p>10</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>AreThereMultipleWSADMINs?</p> <p>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.</p> <p>11</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>UsingWSADMINObjectsWSADMINusesfourobjects:AdminApp manipulate applications AdminControl manipulate objects (e.g., servers)</p> <p>AdminConfig manipulate configuration data</p> <p>Help self-explanatory</p> <p>12</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>WhatCanIDoWiththeAdminAppObject?install uninstall edit list</p> <p>AdminApphelplisting:</p> <p>13</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>AdminAppInstallinganApplicationQ:Whatoptions?$AdminApp install </p> <p>A:$AdminAppoptions</p> <p>Notalloptionsarerequired forinstallation</p> <p>Remember to save and synchronize after installation: Details to come...14 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>AdminAppInstallationOptions$AdminApp options Use this to find options specific to the ear file</p> <p>Whatisthe syntaxforthese options? Works$AdminApp taskInfo This works for only for some options. $AdminApp taskInfo MapModulesToServers</p> <p>Doesntwork$AdminApp taskInfo preCompileJSPs15 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>AdminAppInstallationOptions$AdminApp taskInfo MapModulesToServerswsadmin&gt;$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=server116 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>AdminAppUninstallinganApplicationWow,thatwaseasy!</p> <p>$AdminAppuninstallmyapp</p> <p>Youmustusetheapplicationname, nottheearfilenameSaving is not necessary after uninstallation</p> <p>ADMA5106I: Application myapp uninstalled successfully.17 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>AdminConfigUsedtocreate,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</p> <p>. . "defaultVirtualHostNameString" "enableServletCachingboolean" . .</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>AdminConfigWhichWebContainer?$AdminConfig show Show attributes of a given config objectwsadmin&gt;$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"</p> <p>$AdminConfig list Lists all config objects of a given typewsadmin&gt;$AdminConfig list WebContainer (cells/h6cell/nodes/h6dmgrnd/servers/dmgr|server.xml#WebContainer_1) (cells/h6cell/nodes/h6nodea/servers/h6sr01a|server.xml#WebContainer_1112019030113) (cells/h6cell/nodes/h6nodea/servers/h6sr01b|server.xml#WebContainer_1118253253830) (cells/h6cell/nodes/h6nodea/servers/h6sr02a|server.xml#WebContainer_1112020441556) (cells/h6cell/nodes/h6nodea/servers/h6sr03a|server.xml#WebContainer_1112139804785)</p> <p>$AdminConfig modify Change specified attributes of a given config objectwsadmin&gt;$AdminConfig modify (cells/h6cell/nodes/h6nodea/servers/h6sr03a|server.xml#WebContainer_1112139804785) {{ enableServletCaching true }}</p> <p>19</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>AdminControlSave changes Start / stop servers Initiate synchronization</p> <p>$AdminControlsave</p> <p>$AdminControlstartServerh6sr03a</p> <p>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".</p> <p>$AdminControlstartServerh6sr03ah6nodea $AdminControlstopServerh6sr03aWASX7015E: 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]</p> <p>20</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>AdminControlNodeSynchronizationset var [$AdminControl completeObjectName type=NodeSync,node=h6nodea,*] $AdminControl invoke $var sync</p> <p>WebSphere:platform=common,cell=h6cell,version=6.0.2.1,name=nodeSync, mbeanIdentifier=nodeSync,type=NodeSync,node=h6nodea,process=nodeagent</p> <p>Thismustbedoneforeachnodethatyouwantsynchronized.</p> <p>21</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>ExternalScriptsJaclandJythonBenefitsofusinganexternalscript </p> <p>WASexpectsscriptstobeinASCII Usescript.encodingpropertyfor WSADMIN UseASCIIfileeditoronz/OS EditonyourPCandFTPtoHFS</p> <p>passinginparameters controlflow errorcheckingandhandling</p> <p>UsefoptiontotellWSADMINtouseanexternalscript:$ ./wsadmin.sh -f install.jacl</p> <p>JaclImplementationoftheTclinterpreterwritteninJava DefaultscriptinglanguageexpectedbyWAS</p> <p>JythonImplementationofPythonwritteninJava22 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>CommandLineParametersJaclTakingparametersfromthecommandline 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</p> <p>if right number, go here</p> <p>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 variables2005-09-23</p> <p>nuset serverName to first argument set nodeName to second argument etc.</p> <p>0] 1] 2] 3] 4]</p> <p>23</p> <p>IBM Washington Systems Center</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>CommandLineParametersJythonlen number of items in a list sys.argv list of arguments</p> <p>print writes to stdout</p> <p>check for correct number of arguments</p> <p>if wrong number, go here</p> <p>if right number, go here</p> <p>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</p> <p>set serverName to first argument set nodeName to second argument etc.</p> <p>24</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>VerifyingtheNodeExistsllength returns number of items in a list</p> <p>Jac</p> <p>lprint error message if node is not found</p> <p>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</p> <p>check length of result</p> <p>Jy</p> <p>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</p> <p>th onprint error message if node is not found</p> <p>25</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>VerifyingtheServerExistsDetermineifthegivenserverisavailableset runningServer [$AdminControl completeObjectName type=server,node=$nodeName,process=$serverName,* if {[llength $runningServer] == 0 } { puts Error: Server not running... return }</p> <p>Jac l</p> <p>completeObjectName returns object name</p> <p>serverName passed in as an argument</p> <p>runningServer = AdminControl.completeObjectName("type=Server,node="+nodeName+",process="+serverName+",*") if len(runningServer) == 0: puts Error: Server not running... return</p> <p>Jy</p> <p>th on</p> <p>26</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>CheckExistingApplicationsChecktoseeiftheapplicationisalreadyontheserver...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</p> <p>set foundApp false foreach app [$AdminApp list] { if { $app == $appName } { set foundApp true } Jac } l compare app to appName</p> <p>app set to each item in the list</p> <p>for..in loops over each item in list</p> <p>foundApp = false for app in AdminApp.list().split(): if (app == appName): Jy foundApp = true</p> <p>th on</p> <p>27</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>InstallingandRemovinganApplication$AdminApp uninstall $appName</p> <p>Jac l</p> <p>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</p> <p>uninstall self-explanatory</p> <p>appName passed in as an argument</p> <p>save commit unsaved changes</p> <p>AdminApp.uninstall(appName)</p> <p>options = [-server + serverName options = options + -node + nodeName options = options + -appname + appName + ] AdminApp.install(app,options) Jy AdminConfig.save()</p> <p>th on</p> <p>28</p> <p>IBM Washington Systems Center</p> <p>2005-09-23</p> <p> 2005 IBM Corporation</p> <p>WebSphere Scripting: WSADMIN, JACL, Jython</p> <p>CreatingaNewServerJacl</p> <p>nodeName passed in as an argument set name [list name $serverName] set server [$AdminConfig create Server $nodeName name $name] create Server self-explanatory</p> <p>NestedOptions</p> <p> someoptionshavetheirownoptions e.g.,addressoptionincludehostandportoptions usenestedlistsorconcatenationset http and https transports set hostlist [list host {}] set portlist [list port 9080] set addresslist [list $hostlist $portlist]</p> <p>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 $webcontain...</p>