Starting listener ports using scripting

These steps demonstrate how to start a listener port on an application server using scripting.

Before you begin

Before starting this task, the wsadmin tool must be running. See the topic about starting the wsadmin scripting client using wsadmin scripting for more information.

About this task

Perform the following steps to start a listener port on an application server. The following example returns a list of listener port MBeans:

Procedure

  1. Identify the listener port MBeans for the application server and assign it to the lPorts variable.
    • Using Jacl:
      set lPorts [$AdminControl queryNames type=ListenerPort,
      cell=mycell,node=mynode,process=server1,*]
    • Using Jython:
      lPorts = AdminControl.queryNames('type=ListenerPort,
      cell=mycell,node=mynode,process=server1,*')
      print lPorts
    Example output:
    WebSphere:cell=mycell,name=ListenerPort,mbeanIdentifier=server.xml#
    ListenerPort_1,type=ListenerPort,node=mynode,process=server1
    WebSphere:cell=mycell,name=listenerPort,mbeanIdentifier=ListenerPort,
    type=server.xml#ListenerPort_2,node=mynode,process=server1
  2. Start the listener port if it is not started. For example:
    • Using Jacl:
      foreach lPort $lPorts {
           set state [$AdminControl getAttribute $lport started]
           if {$state == "false"} {
              $AdminControl invoke $lPort start
           }
        }
    • Using Jython:
      # get line separator 
      import  java
      lineSeparator = java.lang.System.getProperty('line.separator')
      
      lPortsArray = lPorts.split(lineSeparator)
      for lPort in lPortsArray:
      	state = AdminControl.getAttribute(lPort, 'started')
      	if state == 'false':
      		AdminControl.invoke(lPort, 'start')

    These pieces of Jacl and Jython code loop through the listener port MBeans. For each listener port MBean, get the attribute value for the started attribute. If the attribute value is set to false, then start the listener port by invoking the start operation on the MBean.