如何卸载已经停止的应用程序

时间:2019-03-07 21:39:06

标签: websphere wsadmin

问题在于,如果应用程序“停止”,则将不会返回任何内容。但是无论如何我还是要卸载它。我不知道应用程序的名称,我要在服务器上安装所有应用程序,然后将其全部卸载。

  

apps = AdminControl.queryNames('type = Application,node ='+ nodeName +',process ='+ serverName +',*')。split()

这是我的代码。

serverObj = AdminControl.completeObjectName('type=Server,node=%s,name=%s,*' % (nodeName, serverName))
serverID = AdminConfig.getid('/Node:%s/Server:%s/' % (nodeName, serverName))

if serverID == "": 
    print "Can't find the server, exiting..."
    sys.exit(1)
else:
    cellName = AdminControl.getAttribute(serverObj, 'cellName')

#Uninstall Apps
apps = AdminControl.queryNames('type=Application,node=' + nodeName + ',process=' + serverName + ',*').split()
appManager=AdminControl.queryNames('type=ApplicationManager,node=' + nodeName + ',process=,*')
if len(apps) > 0:
    for app in apps:
        appName = AdminControl.getAttribute(app, 'name')
        AdminControl.invoke(appManager,'stopApplication', appName)
        print "Uninstalling application: " + appName
        AdminApp.uninstall(appName)
else:
    print "No applications to uninstall"

2 个答案:

答案 0 :(得分:1)

您可以使用以下代码段卸载目标服务器上部署的所有应用程序:

#Get the list of all Apps deployed in target server
installedApps=AdminApp.list("WebSphere:cell=%s,node=%s,server=%s" % (cellName, nodeName, serverName))

#Check if there are any installed Apps on the server
if len (installedApps) > 0:
    #if there are installed Apps, iterate through the list and uninstall Apps one by one
    for app in installedApps.splitlines():
        print "uninstalling "+ app +" ...."
        AdminApp.uninstall(app)
    #Save the changes
    AdminConfig.save()
else:
    #if there are no installed Apps, do nothing
    print "No applications to uninstall"

答案 1 :(得分:0)

您可以使用AdminApp.list()获取目标作用域的应用程序列表。因此对于服务器范围:

AdminApp.list("WebSphere:cell=yourCellName,node=yourNodeName,servers=yourServerName”)

使用该信息,然后可以使用AdminApp.uninstall()卸载应用程序,例如:

AdminApp.uninstall('NameOfApp')