{"id":4726,"date":"2015-05-07T12:46:38","date_gmt":"2015-05-07T04:46:38","guid":{"rendered":"http:\/\/rmohan.com\/?p=4726"},"modified":"2015-05-07T16:53:51","modified_gmt":"2015-05-07T08:53:51","slug":"wsadmin-sh","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=4726","title":{"rendered":"WSadmin.sh"},"content":{"rendered":"<h1><a href=\"http:\/\/ravindranpal.blogspot.com\/2014\/03\/websphere-wsadminsh-scripting-basics.html\" data-item-type=\"post\" data-id=\"8122293437497493272\">Websphere WSadmin.sh Scripting basics<\/a><\/h1>\n<p><strong>WSADMIN Scripting basiscs:\u00a0<\/strong><\/p>\n<p><strong>Why to Use Scripting?<\/strong><\/p>\n<ul>\n<li>Making configuration changes using the Websphere administrative console is error prone and dangerous in complex production environments<\/li>\n<li>Routine tasks can be automated, making repetitive tasks more easily done and done consistently<\/li>\n<li>Automated tasks faster to execute.<\/li>\n<li>Common Operational and Configurationally tasks can be performed from scripts and command line<\/li>\n<\/ul>\n<p><strong>\u00a0What can be done using WSADMIN?<\/strong><\/p>\n<p>Few Examples:<\/p>\n<ul>\n<li>Start and stop deployment manager, nodes, application servers, enterprise applications and clusters<\/li>\n<li>Configure virtual hosts, JDBC providers, JMS resources<\/li>\n<li>Create application servers<\/li>\n<li>Create clusters and add members to a cluster<\/li>\n<li>Deploying Applications<\/li>\n<li>Almost all tasks available through administrative Console<\/li>\n<\/ul>\n<p><strong><span style=\"text-decoration: underline;\">Running WSADMIN<\/span><\/strong><\/p>\n<p>WSADMIN tool can be run in 3 different modes<\/p>\n<ol>\n<li>Interactive mode<\/li>\n<\/ol>\n<p>This is the default mode. In this you\u2019ll enter the command, wait for output and then enter the second command. This is useful for quick administrative tasks<\/p>\n<p>$wsadmin.sh<\/p>\n<p>&gt;wsadmin&gt; your Command<\/p>\n<p>Output<\/p>\n<p>&gt;wsadmin<\/p>\n<ol start=\"2\">\n<li>Inline mode<\/li>\n<\/ol>\n<p>You can specify this mode by using \u2013C after wsadmin. Here you will run one command at a time. The command will be specified in line with wsadmin.<\/p>\n<p>$wsadmin.sh \u2013C your_command<\/p>\n<ol start=\"3\">\n<li>Using a File Input<\/li>\n<\/ol>\n<p>A script file can be given as input using \u2013f option along with wsadmin.<\/p>\n<p>$ wsadmin.sh \u2013f your_script_file<\/p>\n<p><strong><span style=\"text-decoration: underline;\">How to use WSADMIN<\/span><\/strong><\/p>\n<p>Wsadmin.sh host\u00a0port<\/p>\n<ul>\n<li>Host name is the name of the machine which has websphere running and port number is either SOAP or RMI port number of the websphere JVM to which you want to connect.<\/li>\n<li>If the Global security is enabled\u2026you will be asked for user name and password or you can specify it inline using \u2013user and \u2013password.<\/li>\n<li>You can specify the language of the script file, the command, or an interactive shell using \u2013Lang. The possible languages include: Jacl and Jython<\/li>\n<li>You can run the profile scripts before executing the actual wsadmin commands by using \u2013profile option.<\/li>\n<li>To specify the profile from which the wsadmin tool will run, you can use \u2013profileName option.<\/li>\n<li>Note: the wsadmin command will be available in bin directory of your DMGR as well as the bin your application server profiles.<\/li>\n<li>You can use either SOAP or RMI to connect to the wsadmin and this can be specifeid using \u2013conntype option.<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\">WSADMIN Syntax and all options<\/span><\/p>\n<p>wsadmin [-c\u00a0] [-p\u00a0] [-profile\u00a0] [-profileName\u00a0] [-f\u00a0] [-javaoption java_option] [-lang language] [-wsadmin_classpath classpath] [-conntype SOAP [-host\u00a0<em>host_name<\/em>] [-port\u00a0<em>port_number<\/em>] [-user\u00a0userid] [-password\u00a0password] | RMI [-host\u00a0<em>host_name<\/em>] [-port<em>port_number<\/em>] [-user\u00a0<em>userid<\/em>] [-password\u00a0<em>password<\/em>] | NONE]<\/p>\n<p><strong><span style=\"text-decoration: underline;\">Example<\/span><\/strong>: wsadmin -lang jython -f test1.py -profile setup.py -conntype SOAP -port\u00a0<em>mymachinesoapportnumber<\/em>\u00a0-host<em>mymachine\u00a0<\/em>-userid\u00a0<em>userid<\/em>\u00a0-password\u00a0<em>password<\/em><\/p>\n<p><strong><span style=\"text-decoration: underline;\">WSADMIN has 5 objects<\/span><\/strong><\/p>\n<ol>\n<li>Help \u2013 The Help object provides general help and dynamic online information about the currently running MBeans. You can use the Help object as an aid in writing and running scripts with the AdminControl object.<\/li>\n<li>AdminConfig \u2013 Use the AdminConfig object to invoke configuration commands and to create or change elements of the WebSphere Application Server configuration<\/li>\n<li>AdminControl \u2013 Use the AdminControl object to invoke operational commands that deal with running objects in the WebSphere Application Server.<\/li>\n<li>AdminApp \u2013 Use the AdminApp object to install, modify, and administer applications.<\/li>\n<li>AdminTask \u2013 Use the AdminTask object to run an administrative command.<\/li>\n<\/ol>\n<p><strong><span style=\"text-decoration: underline;\">Using WSADMIN:<\/span><\/strong><\/p>\n<p><strong><span style=\"text-decoration: underline;\">Deploying Applications<\/span><\/strong><\/p>\n<p>You can install the application in batch mode, using the install command, or you can install the application in interactive mode using the install interactive command. Interactive mode prompts you through a series of tasks to provide information. All the options available to use are listed\u00a0<a href=\"http:\/\/publib.boulder.ibm.com\/infocenter\/wsdoc400\/v6r0\/index.jsp?topic=\/com.ibm.websphere.iseries.doc\/info\/ae\/ae\/rxml_taskoptions.html\">here in the IBM documentation<\/a>.<\/p>\n<p><strong><em><span style=\"text-decoration: underline;\">Note:<\/span><\/em><\/strong><em>\u00a0words in bold are command or options and in italic are your inputs<\/em><\/p>\n<p>To find out the options available to install the EAR file, run:<\/p>\n<p><strong>AdminApp.options()<\/strong><\/p>\n<p><strong><span style=\"text-decoration: underline;\">Installing EAR application:<\/span><\/strong><\/p>\n<p><strong>Using Batch Mode:<\/strong><\/p>\n<p>If you are deploying on single servers\u2026.make sure that server is running before you execute the commands.<\/p>\n<p><strong>AdminApp.install<\/strong>(<em>\u2018\/home\/joseph\/applications\/SampleApp.ear\u2019<\/em>, \u2018<strong>[-server<\/strong>\u00a0<em>test_server1<\/em>]\u2018)<\/p>\n<p>If you are deploying it in network deployment\/ Clusters, you must connect to WSADMIN of deployment manager.<\/p>\n<p><strong>AdminApp.install<\/strong>(\u2018\/<em>home\/joseph\/applications\/SampleApp.ear\u2019<\/em>, \u2018<strong>[-cluster<\/strong>\u00a0<em>sample_cluster<\/em>]\u2018)<\/p>\n<p><strong>Using Interactive Mode<\/strong>:<\/p>\n<p><strong>AdminApp.installInteractive<\/strong>(<em>\u2018\/home\/joseph\/applications\/SampleApp.ear\u2019<\/em>)<\/p>\n<p>now it will take you through a series of questions before finishing the deployment.<\/p>\n<p>After the deployment is done, you need to perform two more steps<\/p>\n<p>step1. Save the changes by issuing<\/p>\n<p><strong><em>AdminConfig.save()<\/em><\/strong><\/p>\n<p>step2. Synchronize the changes across all nodes by using<\/p>\n<p><strong><em>Sync1 = AdminControl.completeObjectName(\u2018type=NodeSync,node=<\/em><\/strong><em>myNodeName<strong>,*\u2019)<\/strong><\/em><\/p>\n<p>and then<\/p>\n<p><strong>AdminControl.invoke(Sync1, \u2018sync\u2019)<\/strong><\/p>\n<p>step2 is required only for network deployment models.<\/p>\n<p><strong><span style=\"text-decoration: underline;\">Starting Applications<\/span><\/strong><\/p>\n<p>This involves two steps.<br \/>\n<strong>step1:<\/strong>\u00a0getting the handler of the application, means .. locating where the application is running. To do this we use a variable and use query names option on admincontrol object<\/p>\n<p>appHandle=\u00a0<strong>AdminControl.queryNames<\/strong>\u2018<strong>cell<\/strong>=SampleCell,<strong>\u00a0node<\/strong>=virt_node1,<strong>type<\/strong>=ApplicationManager,<strong>process<\/strong>=<em>test_server1<\/em>,*\u2019)<br \/>\nprint appHandle<\/p>\n<p>then you will get an output like the one below<\/p>\n<p>WebSphere:cell=SampleCell,name=ApplicationManager,mbeanIdentifier=ApplicationManager,type=ApplicationManager,node=virt_node1,process=test_server1<\/p>\n<p><strong>step2:<\/strong>\u00a0Now we execute the command to start the application<\/p>\n<p><strong>AdminControl.invoke<\/strong>(<em>appHandle<\/em>, \u2018<strong>startApplication\u2019<\/strong>,\u00a0<em>\u2018Dynamic Cache Monitor\u2019<\/em>)<\/p>\n<p>You can do both steps at once by using the below format<\/p>\n<p><strong>AdminControl.invoke(\u2018WebSphere:name=ApplicationManager<\/strong>,<strong>process<\/strong>=<em>test_server1<\/em>,<strong>node<\/strong>=virt_<em>node1<\/em>,<strong>type=ApplicationManager,mbeanIdentifier=ApplicationManager<\/strong>,<strong>cell<\/strong>=<em>SampleCell<\/em>, \u2018<strong>startApplication<\/strong>\u2018, \u2018[&#8220;<em>Dynamic Cache Monitor<\/em>&#8220;]\u2018, \u2018[java.lang.String]\u2018)<\/p>\n<p><strong><span style=\"text-decoration: underline;\">Stopping Application<\/span><\/strong><\/p>\n<p>The steps are same as starting the application except \u2018startApplication\u2019 should be renamed to \u2018stopApplication\u2019<\/p>\n<p>But, if you want to stop all applications running on a server\u2026 after executing step1 of above<br \/>\n<strong>Step2<\/strong>: you need to first get the list of applications<\/p>\n<p># get line separator<br \/>\n<strong>import\u00a0 java.lang.System\u00a0 as sys<br \/>\nlineSeparator = sys.getProperty(\u2018line.separator\u2019)<br \/>\n<\/strong>apps_list =<strong>AdminControl.queryNames<\/strong>(<strong>\u2018cell<\/strong>=<em>SampleCell<\/em>,<strong>node<\/strong>=<em>virt_node1<\/em>,<strong>type=Application<\/strong>,<strong>process<\/strong>=<em>test_server1<\/em>,*\u2019).split(lineSeparator)<br \/>\nprint apps_list<\/p>\n<p><strong>Step3<\/strong>: now we need to create a loop to stop the applications one by one<\/p>\n<p>for app in apps_list:<br \/>\nappName =\u00a0<strong>AdminControl.getAttribute<\/strong>(<em>app<\/em>,\u00a0<em>\u2018name\u2019<\/em>)<br \/>\n<strong>AdminControl.invoke<\/strong>(<em>appHandle<\/em>, \u2018<strong>stopApplication\u2019<\/strong>,\u00a0<em>appName<\/em>)<\/p>\n<p><strong><span style=\"text-decoration: underline;\">Updating Application<\/span><\/strong><\/p>\n<p>We have different options to update applications, like, full update, module update, single file update etc\u2026Similar to the install, we do have both batch mode and interactive mode for updating [update and updateinteractive]. All the options available to use are listed\u00a0<a href=\"http:\/\/publib.boulder.ibm.com\/infocenter\/wsdoc400\/v6r0\/index.jsp?topic=\/com.ibm.websphere.iseries.doc\/info\/ae\/ae\/rxml_taskoptions.html\">here in the IBM documentation<\/a>.<\/p>\n<ul>\n<li><strong>updating entire application<\/strong><\/li>\n<\/ul>\n<p>AdminApp.update(\u2018SampleApp\u2019, \u2018app\u2019, \u2018[-operation update -contents \/home\/joseph\/applications\/SampleAppv2.ear ]\u2018)<\/p>\n<ul>\n<li><strong>Adding a new module to EJB<\/strong><\/li>\n<\/ul>\n<p>AdminApp.update(\u2018SampleApp\u2019, \u2018modulefile\u2019, \u2018[-operation addupdate -contents \/home\/joseph\/applications\/Increment.jar -contenturi Increment.jar -nodeployejb<br \/>\n-BindJndiForEJBNonMessageBinding [[&#8220;Increment Enterprise Java Bean&#8221; Increment Increment.jar,META-INF\/ejb-jar.xml Inc]]]\u2019)<\/p>\n<ul>\n<li><strong>Updating Single file<\/strong><\/li>\n<\/ul>\n<p>AdminApp.update(\u2018SampleApp\u2019, \u2018file\u2019, \u2018[-operation update -contents \/home\/joseph\/applications\/my.xml -contenturi SampleApp\/my.xml]\u2018)<\/p>\n<p><strong><span style=\"text-decoration: underline;\">TIP:<\/span><\/strong>\u00a0Use the\u00a0<strong>taskInfo<\/strong>\u00a0command of the AdminApp object to obtain information about the data that is needed for your application.<\/p>\n<p>for example, you want to know what options you need to supply for mapping modules to servers\u2026use the following taskinfo command<\/p>\n<p>AdminApp taskInfo\u00a0MapModulesToServers<\/p>\n<ul>\n<li><strong>Adding an application server<\/strong><\/li>\n<\/ul>\n<p>There are 3 steps involved in creating a new application server<\/p>\n<p>first we need to get the node on which we want to create the application server. Obtain the configuration ID of the object and assign it to the\u00a0node\u00a0variable<\/p>\n<p>node = AdminConfig.getid(\u2018\/Node:mynode\/\u2019)<\/p>\n<p>Then, create the application server using admintask<\/p>\n<p>AdminTask.createApplicationServer(node, [&#8216;-name&#8217;, &#8216;test1&#8217;, &#8216;-templateName&#8217;, &#8216;default&#8217;])<\/p>\n<p>where test1 is the name of the server you want to create and mynode is the node on which this server will be created.<\/p>\n<p>Then, save the changes using admintask.save ()<\/p>\n<ul>\n<li><strong>create a new cluster<\/strong><\/li>\n<\/ul>\n<p>This involves 3 steps<\/p>\n<p>1A. using existing server<\/p>\n<p>1Aa. Choose the server you want to convert into server and assign it to a variable<\/p>\n<p>server = AdminConfig.getid(\u2018\/Cell:mycell\/Node:mynode\/Server:server1\/\u2019)<\/p>\n<p>1Ab. Convert that existing server into cluster<\/p>\n<p>print AdminConfig.convertToCluster(server, \u2018myCluster1?)<\/p>\n<p>1B. creating new cluster without members<\/p>\n<p>1Ba. Identify the cell configuration ID and assign it to a variable<\/p>\n<p>C1 = AdminConfig.getid(\u2018\/Cell:mycell\/\u2019)<\/p>\n<p>1Bb. Create a new cluster without a cluster member<\/p>\n<p>print AdminConfig.create(\u2018ServerCluster\u2019, C1, \u2018[[name ClusterName]]\u2019)<\/p>\n<ol start=\"2\">\n<li>Adding new members:<\/li>\n<\/ol>\n<p>2a. get the ncluster configuration ID and assign it to a variable<\/p>\n<p>cluster = AdminConfig.getid(\u2018\/ServerCluster:myCluster1\/\u2019)<br \/>\nprint cluster<\/p>\n<p>2b. get the ncluster configuration ID and assign it to a variable<\/p>\n<p>node = AdminConfig.getid(\u2018\/Node:mynode\/\u2019)<br \/>\nprint node<\/p>\n<p>2c. get the ncluster configuration ID and assign it to a variable<\/p>\n<p>serverTemplate = AdminConfig.listTemplates(\u2018Server\u2019)<br \/>\nprint serverTemplate<\/p>\n<p>2d. Create the cluster member<\/p>\n<p>AdminConfig.createClusterMember(cluster, node, [[&#8216;memberName&#8217;, &#8216;clusterMember1&#8217;]])<\/p>\n<ol start=\"3\">\n<li>save the changes and synchronize them.<\/li>\n<\/ol>\n<ul>\n<li><strong>start\/stop application servers<\/strong><\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\">Starting<\/span><\/p>\n<p>print AdminControl.startServer(\u2018server1?, \u2018mynode\u2019)<\/p>\n<p>Output:<\/p>\n<p>WASX7319I: The serverStartupSyncEnabled attribute is set to false.\u00a0 A start will be attempted for server \u201cserver1? but the configuration information for node \u201cmynode\u201d may not be current.<br \/>\nWASX7262I: Start completed for server \u201cserver1? on node \u201cmynode\u201d<\/p>\n<p><span style=\"text-decoration: underline;\">Stopping<\/span><\/p>\n<p>print AdminControl.stopServer(\u2018serverName\u2019, \u2018mynode\u2019)<\/p>\n<p>this command will stop the server named servername on node named mynode. Since we used print, we can see the following output on the console<\/p>\n<p>Output<\/p>\n<p>WASX7337I: Invoked stop for server \u201cserverName\u201d Waiting for stop completion.<br \/>\nWASX7264I: Stop completed for server \u201cserverName\u201d on node \u201cmynode\u201d<\/p>\n<p>Exit codes for stop\/starting of the servers<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"230\"><strong>Server state<\/strong><\/td>\n<td width=\"115\"><strong>Return code<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"230\">Server initialization failed<\/td>\n<td width=\"115\">-1<\/td>\n<\/tr>\n<tr>\n<td width=\"230\">Server initialization timed out<\/td>\n<td width=\"115\">-2<\/td>\n<\/tr>\n<tr>\n<td width=\"230\">Server start in progress<\/td>\n<td width=\"115\">1<\/td>\n<\/tr>\n<tr>\n<td width=\"230\">Server is initializing the applications that are present<\/td>\n<td width=\"115\">2<\/td>\n<\/tr>\n<tr>\n<td width=\"230\">Server initialization is complete (successful)<\/td>\n<td width=\"115\">0<\/td>\n<\/tr>\n<tr>\n<td width=\"230\">Server stop failed<\/td>\n<td width=\"115\">-10<\/td>\n<\/tr>\n<tr>\n<td width=\"230\">Server stop timed out<\/td>\n<td width=\"115\">-11<\/td>\n<\/tr>\n<tr>\n<td width=\"230\">Server stop operation started<\/td>\n<td width=\"115\">1000<\/td>\n<\/tr>\n<tr>\n<td width=\"230\">Server successfully stopped<\/td>\n<td width=\"115\">0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul>\n<li><strong>Checking the status of the servers<\/strong><\/li>\n<\/ul>\n<p>first get the server MBean and assign it to a variable<\/p>\n<p>server = AdminControl.completeObjectName(\u2018cell=mycell,node=mynode,name=server1,type=Server,*\u2019)<\/p>\n<p>Print server<\/p>\n<p>you can see output similar to the below:<\/p>\n<p>WebSphere:cell=mycell,name=server1,mbeanIdentifier=server.xml#Server_1,type=Server,node=mynode,process=server1,processType=ManagedProcess<\/p>\n<p>The execute the following command<\/p>\n<p>print AdminControl.getAttribute(server, \u2018state\u2019)<\/p>\n<p>This will return the state of the server on the command line, something like STARTED\/STOPPED etc.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Websphere WSadmin.sh Scripting basics <\/p>\n<p>WSADMIN Scripting basiscs: <\/p>\n<p>Why to Use Scripting?<\/p>\n<p> Making configuration changes using the Websphere administrative console is error prone and dangerous in complex production environments Routine tasks can be automated, making repetitive tasks more easily done and done consistently Automated tasks faster to execute. Common Operational and Configurationally tasks can be [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4726"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4726"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4726\/revisions"}],"predecessor-version":[{"id":4727,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4726\/revisions\/4727"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}