Example: Migrating - Pinging running servers for the current state
The purpose of this task is to determine if a server is running. The following examples demonstrate how to ping running servers in WebSphere Application Server V4.0 and V6.x:
- wscp V4.0
set servers [ApplicationServer list] foreach server $servers { set result ApplicationServer show $server -attribute {CurrentState} puts "state for server $server: $result" }- wsadmin V6.x
In the WAS V6.x configuration and control commands are separate.
set servers [$AdminConfig list Server] foreach server $servers { set objName [$AdminConfig getObjectName $server] if {[llength $objName] == 0} { puts "server $server is not running" } else { set result [$AdminControl getAttribute $objName state] puts "state for server $server: $result" } }# get line separator import java.lang.System as sys lineSeparator = sys.getProperty('line.separator') servers = AdminConfig.list('Server').split(lineSeparator) for server in servers: objName = AdminConfig.getObjectName(server).split(lineSeparator) if len(objName) == 0: print "server " + server + " is not running\n" else: result = AdminControl.getAttribute(objName, 'state') print "state for server " + server + ": " + result + "\n"The first line of this example obtains a list of all servers defined in the configuration. We can interrogate this data to determine the running servers. If the server is not running, nothing is returned from the getObjectName command on the AdminConfig object. If the server is running, ask for its state attribute. If the Mbean is there, the server is running and the state is STARTED. It is possible, however, for the state to be something other than STARTED, for example, STOPPING.