WebSphere – Restart enterprise applications usign Jython Script

My jython script : restartApp.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
appName = sys.argv[0]
nodeName = 'w9Node'
serverName = 'WebSphere_Portal'
 
try:
   appMgr = AdminControl.queryNames('type=ApplicationManager,node='+nodeName+',process='+serverName+',*')
   appDetails = AdminControl.completeObjectName('type=Application,name='+appName+',*')
   print ''
 
  if len(appDetails) > 0:
    print '['+appName+'] is started lets stop'
    AdminControl.invoke(appMgr, 'stopApplication', appName)
 
except:
  print("Ignoring error - %s" % sys.exc_info())
 
print 'lets start ['+appName+']'
    AdminControl.invoke(appMgr, 'startApplication', appName)

Restart multiple app using jhyton script invoked by dos script :

1
2
3
4
5
6
7
8
9
10
11
12
@echo off
 
set baseCommand=C:\ibm\portal\AppServer\bin\wsadmin.bat -conntype SOAP -host localhost -port 10033 -user <youruser> -password <yourpassword> -lang jython -f restartApp.py
set cellName=wp9Celldev
 
set appName=app001-ear 
set "MYCOMMAND=%baseCommand% %appName% %cellName%"
call %MYCOMMAND%
 
set appName=app002-ear 
set "MYCOMMAND=%baseCommand% %appName% %cellName%"
call %MYCOMMAND%