2011-11-18 44 views

回答

11

我不认为有任何直接的方法来获取应用程序的运行状态,可以使用下面的代码

serverstatus = AdminControl.completeObjectName('type=Application,name='your_application_name',*') 
print serverstatus 

如果serverstatus返回null,则应用程序没有运行得到的AdminControl对象,如果应用程序正在运行,则会打印应用程序的详细信息。

+0

工作过,谢谢。 – blank

+0

你可以添加其他参数,如'服务器= WPS00'或类似的东西吗? – Pred

+0

回答了我自己的问题。您在搜索字符串中包含“process = WPS00”,它将查看特定的AppServers。 – Pred

4

这是我根据斯内汉的答案使用的。

import string 

def getAppStatus(appName): 
    # If objectName is blank, then the application is not running. 
    objectName = AdminControl.completeObjectName('type=Application,name=' + appName + ',*') 
    if objectName == "": 
     appStatus = 'Stopped' 
    else: 
     appStatus = 'Running' 
    return appStatus 

def appStatusInfo(): 
    appsString = AdminApp.list() 
    appList = string.split(appsString, '\r\n') 

    print '============================' 
    print ' Status | Application ' 
    print '============================' 

    # Print apps and their status 
    for x in appList: 
     print getAppStatus(x) + ' | ' + x 

    print '============================' 



appStatusInfo() 

样本输出

============================ 
Status | Application 
============================ 
Running | DefaultApplication 
Running | IBMUTC 
Stopped | some-ear 
Running | another-ear 
============================ 
+0

因此,我的Web控制台表示应用程序处于部分启动状态,但是当我使用wsadmin脚本时,它会返回其安装的所有AppServers,而不是实际显示NULL或空白返回。这是否应该发生? – Pred

+0

如何运行此文件?我收到错误 NameError:名称'AdminApp'未定义 –

1

有一些在马蒂厄,科米尔的脚本需要更多的修改。

我们走吧。

它可以在任何行分隔符中工作。一般来说AdminApp.list()将使用“\”作为分隔符行

import string 

def getAppStatus(appName): 
    # If objectName is blank, then the application is not running. 
    objectName = AdminControl.completeObjectName('type=Application,name='+ appName+',*') 
    if objectName == "": 
     appStatus = 'Stopped' 
    else: 
     appStatus = 'Running' 
    return appStatus 

def appStatusInfo(): 
    Apps=AdminApp.list().split(java.lang.System.getProperty("line.separator")) 

    print '============================' 
    print ' Status | Application ' 
    print '============================' 

    # Print apps and their status 
    for x in Apps: 
     print "X value", x 
     print getAppStatus(x) + ' | ' + x 

    print '============================' 



appStatusInfo() 
相关问题