Tuesday, July 14, 2020

Weblogic Managed Server - Rolling Restart Automation

Rolling Restart on Weblogic is sometimes done on a periodic manner to get things cleared. Well I am not favor of doing rolling restart but sometimes this is the solution. 

This handy script can help 😊

oracle@wls-ser1:~$ cat /export/home/oracle/automation/autorestart/wls_rollingrestart.py
import os
import re
import string
import array
import java.lang
import time as systime
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','weblogic123','t3://localhost: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 :"
        elif CS == 2:
                print server.getName(), "= HEALTH_CRITICAL :"
        elif CS == 3:
                print server.getName(), "= HEALTH_FAILED :"
        elif CS == 4:
                print server.getName(), "= HEALTH_OVERLOADED :"
        else:
                print server.getName() + ': ' + get('State') + ': UNKNOWN HEALTH STATE (' + currentState + ')'
        ms = server.getName()
        if ms != "AdminServer":
                print ms, " Shutdown Initiated"
                systime.sleep(10)
                shutdown(server.getName(), 'Server', force="true")
                print ms, " Shutdown Completed"
                print ms, " Startup Initiated"
                start(ms, 'Server')
                systime.sleep(10)
                print server.getName(), " Startup Completed"
        else:
                print "AdminServer - no action performed"
        CS = get('OverallHealthState').getState()
        if CS == 0:
                print server.getName(), "= HEALTH_OK"
        elif CS == 1:
                print server.getName(), "= HEALTH_WARN :"
        elif CS == 2:
                print server.getName(), "= HEALTH_CRITICAL :"
        elif CS == 3:
                print server.getName(), "= HEALTH_FAILED :"
        elif CS == 4:
                print server.getName(), "= HEALTH_OVERLOADED :"
        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@wls-ser1:~$


 

oracle@wls-ser1:~$ cat /export/home/oracle/automation/autorestart/wls_rollingrestart.sh
log='/export/home/oracle/automation/autorestart/wls_rollingrestart.log'
date >> $log
echo >> $log
. /u01/app/oracle/product/fmw/middleware/wlserver/server/bin/setWLSEnv.sh >> $log
java weblogic.WLST -skipWLSModuleScanning /export/home/oracle/automation/autorestart/wls_rollingrestart.py >> $log
echo >> $log
echo >> $log
echo "-----------------------------------------------------------------------------" >> $log
oracle@wls-ser1:~$

oracle@wls-ser1:~$ crontab -l
10 0 * * 5   /export/home/oracle/automation/autorestart/wls_rollingrestart.sh
oracle@wls-ser1:~$


Execution Log
-----------------------------------------------------------------------------
Monday, July 13, 2020 at  5:20:12 PM +03

CLASSPATH=/usr/jdk/instances/jdk1.8.0/lib/tools.jar:/u01/app/oracle/product/fmw/middleware/wlserver/modules/features/wlst.wls.classpath.jar:/usr/jdk/instances/jdk1.8.0/lib/tools.jar:/u01/app/oracle/product/fmw/middleware/wlserver/modules/features/wlst.wls.classpath.jar:

PATH=/u01/app/oracle/product/fmw/middleware/wlserver/server/bin:/u01/app/oracle/product/fmw/middleware/wlserver/../oracle_common/modules/thirdparty/org.apache.ant/1.9.8.0.0/apache-ant-1.9.8/bin:/usr/jdk/instances/jdk1.8.0/jre/bin:/usr/jdk/instances/jdk1.8.0/bin:/usr/bin:/usr/sbin:/u01/app/oracle/product/fmw/middleware/wlserver/../oracle_common/modules/org.apache.maven_3.2.5/bin:/u01/app/oracle/product/fmw/middleware/wlserver/../oracle_common/modules/org.apache.maven_3.2.5/bin

Your environment has been set.

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server "AdminServer" that belongs to domain "ms_domain".

Warning: An insecure protocol was used to connect to the server.
To ensure on-the-wire security, the SSL port or Admin port should be used instead.

Location changed to domainRuntime tree. This is a read-only tree
with DomainMBean as the root MBean.
For more help, use help('domainRuntime')

ms_server02 = HEALTH_OK
ms_server02  Shutdown Initiated
Shutting down the server ms_server02 with force=true while connected to AdminServer ...
.
ms_server02  Shutdown Completed
ms_server02  Startup Initiated
Starting server ms_server02 ......................................................
Server with name ms_server02 started successfully
ms_server02  Startup Completed
ms_server02 = HEALTH_OK
ms_server01 = HEALTH_OK
ms_server01  Shutdown Initiated
Shutting down the server ms_server01 with force=true while connected to AdminServer ...
.
ms_server01  Shutdown Completed
ms_server01  Startup Initiated
Starting server ms_server01 ................................................
Server with name ms_server01 started successfully
ms_server01  Startup Completed
ms_server01 = HEALTH_OK
ms_server04 = HEALTH_OK
ms_server04  Shutdown Initiated
Shutting down the server ms_server04 with force=true while connected to AdminServer ...
.....
ms_server04  Shutdown Completed
ms_server04  Startup Initiated
Starting server ms_server04 ..................................................
Server with name ms_server04 started successfully
ms_server04  Startup Completed
ms_server04 = HEALTH_OK
ms_server03 = HEALTH_OK
ms_server03  Shutdown Initiated
Shutting down the server ms_server03 with force=true while connected to AdminServer ...
.
ms_server03  Shutdown Completed
ms_server03  Startup Initiated
Starting server ms_server03 ............................................
Server with name ms_server03 started successfully
ms_server03  Startup Completed
ms_server03 = HEALTH_OK
AdminServer = HEALTH_OK
AdminServer - no action performed
AdminServer = HEALTH_OK
Disconnected from weblogic server: AdminServer


Exiting WebLogic Scripting Tool.

Popular Posts