Wednesday, July 22, 2020

Weblogic Autorestart - Managed Servers

Weblogic autorestart of managed servers might be required if there is a problem with it , like stuck thread , overloaded , aborted or suspended state. The below automation can help to restart based on a certain state of the manged server. In the below I am restarting the managed server when state is other than HEALTH_OK. feel free to customize it to your requirement.


oracle@marsweblogic:~$ cat /export/home/oracle/automation/autorestart/wls_autorestart.py
import os
import re
import string
import array
import java.lang
from jarray import array as jarray_c
from java.util import Hashtable
from javax.management import MBeanServerConnection
from javax.management import ObjectName
from java.lang import String
from java.lang import Object

connect('weblogic','xxxxxxxx','t3://192.168.0.1:7001')

domainRuntime();
cd('ServerRuntimes')
servers = domainRuntimeService.getServerRuntimes();
stoppedServers = []
for server in servers:
 try:
        cd ('/ServerRuntimes/' + server.getName())
        CS = get('OverallHealthState').getState()
        if CS == 0:
                print server.getName(), "= HEALTH_OK"
        elif CS == 1:
                print server.getName(), "= HEALTH_WARN :"
                ms = server.getName()
                shutdown(server.getName(), 'Server', force="true")
                start(ms, 'Server')
        elif CS == 2:
                print server.getName(), "= HEALTH_CRITICAL :"
                ms = server.getName()
                shutdown(server.getName(), 'Server', force="true")
                start(ms, 'Server')
        elif CS == 3:
                print server.getName(), "= HEALTH_FAILED :"
                ms = server.getName()
                shutdown(server.getName(), 'Server', force="true")
                start(ms, 'Server')
        elif CS == 4:
                print server.getName(), "= HEALTH_OVERLOADED :"
                ms = server.getName()
                shutdown(server.getName(), 'Server', force="true")
                start(ms, 'Server')
        else:
                print server.getName() + ': ' + get('State') + ': UNKNOWN HEALTH STATE (' + currentState + ')'
 except WLSTException, e:
                print server.getName() + " is not running."
                stoppedServers.append(server.getName())

disconnect()
exit()
oracle@marsweblogic:~$

Popular Posts