我可以获得已安装应用程序的列表,但是我如何使用Jython获得状态?
我认为没有任何直接的方法来获取应用程序的运行状态,您可以使用以下代码从AdminControl获取对象
serverstatus = AdminControl.completeObjectName('type=Application,name='your_application_name',*')
print serverstatus
如果serverstatus
返回null,则应用程序未运行,如果应用程序正在运行,则将打印应用程序的详细信息
以下是我根据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, 'rn')
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
============================
以下IBM文档应该有所帮助:
-
WAS InfoCenter:使用wsadmin脚本查询应用程序状态
-
IBM技术说明:使用wsadmin脚本列出企业应用程序状态
总而言之,如果应用程序在应用服务器上运行,那么将注册一个Application
MBean。为了确定应用程序是否正在运行,您可以查询这些mbean的存在。
Matthieu, Cormier的脚本需要更多的修改。
开始了。
它可以在任何行分隔符中工作。通常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()