考虑下面的代码。这使用集群并搜索每个服务器,但可以根据您的情况进行修改。您可以修改第一个块以仅在一个应用程序中查找服务器。
# Get a list of all valid servers
cell=AdminConfig.list('Cell')
cellName=AdminConfig.showAttribute(cell, 'name')
clusterID=AdminConfig.getid('/ServerCluster:<My Cluster>/')
clusterList=AdminConfig.list('ClusterMember', clusterID)
servers=clusterList.split("\n")
# For each server check if its running using completeObjectName
# If it returns null its a valid server name, the server just isn't running
# If it returns info its running.
for serverID in servers:
serverName=AdminConfig.showAttribute(serverID, 'memberName')
nodeName=AdminConfig.showAttribute(serverID, 'nodeName')
aServer=AdminControl.completeObjectName('cell=' + cellName + ',node=' + nodeName + ',name=' + serverName + ',type=Server,*')
if (aServer != ""):
aState=AdminControl.getAttribute(aServer, 'state')
else:
aState="STOPPED"
# Since this server is not running write code here to start it.
print "Server", serverName, "is in a", aSt