我正在尝试编写一个简单的脚本来重新启动WebSphere应用程序服务器。
以下是我的剧本:
ManagedProcessList=AdminControl.queryNames('WebSphere:type=Server,*')
for i in range(len(ManagedProcessList)) :
serverStatus=AdminControl.getAttribute(ManagedProcessList[i],
'state')
serverName=ManagedProcessList[i].split(',')[0].split('=')[1]
nodeName=ManagedProcessList[i].split(',')[3].split('=')[1]
if serverStatus == "STARTED":
if nodeName in ("WC_node") and serverName in ("server1"):
print
"restarting",serverName,"on",nodeName,"because it is
currently",serverStatus
AdminControl.stopServer(serverName,nodeName)
AdminControl.startServer(serverName,nodeName)
else:
print "Not restarting",serverName,"on",nodeName,"because
it is currently",serverStatus
它返回以下错误。
WASX7015E: Exception running command:
wsadmin>execfile('/home/raja/serverstat.py')
"execfile('/home/raja/serverstat.py')"; exception information:
com.ibm.ws.scripting.ScriptingException: WASX7025E: Error found in
String "WebSphere:W"; cannot create ObjectName.
命令输出如下所示:
wsadmin>print AdminControl.queryNames('WebSphere:type=Server,*')
WebSphere:name=server1,process=server1,platform=proxy,node=WC_node,j2eeType=J2EEServer,version=7.0.0.41,type=Server,mbeanIdentifier=cells/WC_cell/nodes/WC_node/servers/server1/server.xml#Server_1183144161046,cell=WC_cell,spec=1.0,processType=UnManagedProcess
wsadmin>
答案 0 :(得分:0)
更新脚本,如下所示。
变化。
1.使用 splitlines 方法将“AdminControl.queryNames”的结果转换为第1行中的列表
2.在第9行的IF条件语句中使用'=='运算符来检查nodename和servername
ManagedProcessList=AdminControl.queryNames('WebSphere:type=Server,*').splitlines()
for i in range(len(ManagedProcessList)) :
serverStatus=AdminControl.getAttribute(ManagedProcessList[i], 'state')
serverName=ManagedProcessList[i].split(',')[0].split('=')[1]
nodeName=ManagedProcessList[i].split(',')[3].split('=')[1]
if serverStatus == "STARTED":
if nodeName == "WC_node" and serverName == "server1":
print "restarting",serverName,"on",nodeName,"because it is currently",serverStatus
AdminControl.stopServer(serverName,nodeName)
AdminControl.startServer(serverName,nodeName)
else:
print "Not restarting",serverName,"on",nodeName,"because it is currently",serverStatus