Этот скрипт останавливает кластер серверов приложений WAS (если в течение заданного интервала времени они не остановились – делает Terminate), и запускает его. Имя кластера нужно задать в качестве аргумента командной строки.
import sys
import java
import time
lineSeparator = java.lang.System.getProperty('line.separator')
# Getting cluster name from command line:
clusterName = sys.argv[1]
cellId = AdminConfig.list('Cell')
cellName = AdminConfig.showAttribute(cellId,'name')
cluster = AdminControl.completeObjectName('cell=' + cellName +',type=Cluster,name=' + clusterName + ',*')
clusterId = AdminConfig.getid('/ServerCluster:' + clusterName + '/')
# stopping cluster
state = AdminControl.getAttribute(cluster, 'state')
print 'Cluster '+clusterName+' in cell '+cellName+' is '+state
print 'Stopping cluster '+clusterName+' in cell '+cellName+'...'
if (state != 'websphere.cluster.partial.stop') & (state != 'websphere.cluster.stopped)':
AdminControl.invoke(cluster, 'stop')
# Wait for it to stop
maxwait = 600
# wait about 10 minutes at most
count = 0
while state != 'websphere.cluster.stopped':
time.sleep(30)
print '.'
state = AdminControl.getAttribute( cluster, 'state' )
count += 1
if count > ( maxwait / 30 ):
break
# if servers hasn't stopped yet - terminate the servers
state = AdminControl.getAttribute(cluster, 'state')
if state == 'websphere.cluster.partial.stop':
clusterMembersList = AdminConfig.list("ClusterMember", clusterId )
clusterMembers = clusterMembersList.split(lineSeparator)
print 'Terminating servers...'
for clusterMember in clusterMembers:
nodeName = AdminConfig.showAttribute( clusterMember, "nodeName" )
serverName = AdminConfig.showAttribute( clusterMember, "memberName" )
print 'Terminating '+serverName+'...'
AdminControl.stopServer(serverName, nodeName, 'terminate')
# starting cluster
if state != 'websphere.cluster.partial.start' and state != 'websphere.cluster.running':
print 'Starting cluster '+clusterName+' in cell '+cellName+'...'
AdminControl.invoke( cluster, 'start' )
# Wait for it to start
maxwait = 300 # wait about 5 minutes at most
count = 0
while state != 'websphere.cluster.running':
time.sleep( 30 )
print '.'
state = AdminControl.getAttribute( cluster, 'state' )
count += 1
if count > ( maxwait / 30 ):
break
import java
import time
lineSeparator = java.lang.System.getProperty('line.separator')
# Getting cluster name from command line:
clusterName = sys.argv[1]
cellId = AdminConfig.list('Cell')
cellName = AdminConfig.showAttribute(cellId,'name')
cluster = AdminControl.completeObjectName('cell=' + cellName +',type=Cluster,name=' + clusterName + ',*')
clusterId = AdminConfig.getid('/ServerCluster:' + clusterName + '/')
# stopping cluster
state = AdminControl.getAttribute(cluster, 'state')
print 'Cluster '+clusterName+' in cell '+cellName+' is '+state
print 'Stopping cluster '+clusterName+' in cell '+cellName+'...'
if (state != 'websphere.cluster.partial.stop') & (state != 'websphere.cluster.stopped)':
AdminControl.invoke(cluster, 'stop')
# Wait for it to stop
maxwait = 600
# wait about 10 minutes at most
count = 0
while state != 'websphere.cluster.stopped':
time.sleep(30)
print '.'
state = AdminControl.getAttribute( cluster, 'state' )
count += 1
if count > ( maxwait / 30 ):
break
# if servers hasn't stopped yet - terminate the servers
state = AdminControl.getAttribute(cluster, 'state')
if state == 'websphere.cluster.partial.stop':
clusterMembersList = AdminConfig.list("ClusterMember", clusterId )
clusterMembers = clusterMembersList.split(lineSeparator)
print 'Terminating servers...'
for clusterMember in clusterMembers:
nodeName = AdminConfig.showAttribute( clusterMember, "nodeName" )
serverName = AdminConfig.showAttribute( clusterMember, "memberName" )
print 'Terminating '+serverName+'...'
AdminControl.stopServer(serverName, nodeName, 'terminate')
# starting cluster
if state != 'websphere.cluster.partial.start' and state != 'websphere.cluster.running':
print 'Starting cluster '+clusterName+' in cell '+cellName+'...'
AdminControl.invoke( cluster, 'start' )
# Wait for it to start
maxwait = 300 # wait about 5 minutes at most
count = 0
while state != 'websphere.cluster.running':
time.sleep( 30 )
print '.'
state = AdminControl.getAttribute( cluster, 'state' )
count += 1
if count > ( maxwait / 30 ):
break