简体   繁体   English

如何使用wsadmin Jython脚本确定应用程序是否正在运行?

[英]How do I determine if an application is running using wsadmin Jython script?

我可以获得一个已安装的应用程序列表,但如何使用Jython获取状态?

I dont think there is any direct method to get the application running status, You can get the object from the AdminControl using the following code 我不认为有任何直接的方法来获取应用程序运行状态,您可以使用以下代码从AdminControl获取对象

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

If serverstatus returns null, then the application is not running, if the application is running then the details of the applications would be printed. 如果serverstatus返回null,则应用程序未运行,如果应用程序正在运行,则将打印应用程序的详细信息。

Here is what I use based on Snehan's answer. 以下是我根据Snehan的回答使用的内容。

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()

Sample output 样本输出

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

The following IBM documentation should help: 以下IBM文档应该有所帮助:

To summarize, if the application is running on an application server, an Application MBean will be registered. 总而言之,如果应用程序在应用程序服务器上运行,则将注册Application MBean In order to determine if the application is running, you can query for the presence of these MBeans. 为了确定应用程序是否正在运行,您可以查询是否存在这些MBean。

There is some more modification required in Matthieu, Cormier's script. 在Cormier的剧本Matthieu中还需要进行一些修改。

Here we go. 开始了。

It will work in any line separator. 它适用于任何行分隔符。 Generally AdminApp.list() will use "\\" as the line seperator 通常, 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM