Showing posts with label Start WebLogic Admin Server. Show all posts
Showing posts with label Start WebLogic Admin Server. Show all posts

Tuesday, March 25, 2014

Startup Shutdown scripts for WebLogic on Windows

It's a serious pain in the neck to setup WebLogic (11g at the moment) to automatically stop and start along with the system startup/Shutdown. Oracle should seriously consider doing something about it. Ideally install as Windows Service as soon as a domain is configured. However until that happens we are on our own.

I search around the web if someone had created an ideal solution already a script/document that I could follow and get this going in matter of minutes but alas I couldn't find a complete solution. I found bits and pieces here and there. So I took them and tailored them to write this blog. So here are the steps (this document assumes you have already configured node manager as a service and it is running)


1. Make sure Node Manager credentials are set correctly in WebLogic Admin Console

Go to the WebLogic console in Domain Structure, click on Domain Name - top level (e.g. oam_domain), click on Security tab and under General sub-tab click Advanced. Set the Node Manger credentials here (e.g. weblogic / Password123)

2. Add those credentials are put in nm_password.properties

Find (or create) the nm_password.properties file under \user_projects\domains\\config\nodemanager (e.g. - D:\Oracle\Middleware\user_projects\domains\oam_domain\config\nodemanager). Add the Node Manager credentials to the file. e.g.-

username=weblogic
password=Password123

3. Create boot.properties for the Administration Server


Follow these steps to create the boot.properties file:

Go to \user_projects\domains\\servers\AdminServer\security directory. e.g.-

D:\Oracle\Middleware\user_projects\domains\oam_domain/servers/AdminServer/security/

Use a text editor to create a file called boot.properties under the security directory. Enter the admin credentials. e.g-

username=weblogic
password=Password123

4. The scripts

A. weblogic.properties - Properties file used by scripts:

DOMAIN_NAME=oam_domain
MW_HOME=D:\\Oracle\\Middleware
DOMAIN_HOME=D:\\Oracle\\Middleware\\user_projects\\domains\\oam_domain
WEBLOGIC_USER=weblogic
WEBLOGIC_PASSWORD=Password123
HOST=myweblogicserver.company.com
NODEMANAGER_PORT=5556
ADMINSERVER_NAME=AdminServer
ADMINSERVER_PORT=7001
ADMINSERVER_URL=t3://myweblogicserver.company.com7001
MANAGEDSERVERS=oam_server,oim_server

B. startAdminServer.py - Starts the Admin Server

from java.io import FileInputStream
import java.lang
import os
import string
import datetime

logfile = "startManagedServer.log"
LOGFILE = open(logfile,"a")
now = datetime.datetime.now()
LOGFILE.writelines("Starting Admin Server - " + str(now) + "\n")

propInputStream = FileInputStream("weblogic.properties")
configProps = Properties()
configProps.load(propInputStream)

WEBLOGIC_USER = configProps.get("WEBLOGIC_USER")
WEBLOGIC_PASSWORD = configProps.get("WEBLOGIC_PASSWORD")
HOST = configProps.get("HOST")
NODEMANAGER_PORT = configProps.get("NODEMANAGER_PORT")
DOMAIN_NAME = configProps.get("DOMAIN_NAME")
DOMAIN_HOME = configProps.get("DOMAIN_HOME")
ADMINSERVER_NAME = configProps.get("ADMINSERVER_NAME")
ADMINSERVER_URL = configProps.get("ADMINSERVER_URL")

nmConnect(WEBLOGIC_USER, WEBLOGIC_PASSWORD, HOST, NODEMANAGER_PORT, DOMAIN_NAME, DOMAIN_HOME)
LOGFILE.writelines("Connected to NODE MANAGER Successfully...!!!" + "\n")
print ''
print '============================================='
print 'Connected to NODE MANAGER Successfully...!!!'
print '============================================='
print ''

print '###### ADMINSERVER NAME = ', ADMINSERVER_NAME
nmStart(ADMINSERVER_NAME)
LOGFILE.writelines("Successfully started " + ADMINSERVER_NAME + "\n\n")
print ''
print '============================================='
print '===> Successfully started ', ADMINSERVER_NAME, '  <==='
print '============================================='
print ''

C. stopAdminServer.py - Stops the Admin Server

from java.io import FileInputStream
import java.lang
import os
import string
import datetime

logfile = "stopAdminServer.log"
LOGFILE = open(logfile,"a")
now = datetime.datetime.now()
LOGFILE.writelines("Stopping Admin Server - " + str(now) + "\n")

propInputStream = FileInputStream("weblogic.properties")
configProps = Properties()
configProps.load(propInputStream)

WEBLOGIC_USER = configProps.get("WEBLOGIC_USER")
WEBLOGIC_PASSWORD = configProps.get("WEBLOGIC_PASSWORD")
HOST = configProps.get("HOST")
NODEMANAGER_PORT = configProps.get("NODEMANAGER_PORT")
DOMAIN_NAME = configProps.get("DOMAIN_NAME")
DOMAIN_HOME = configProps.get("DOMAIN_HOME")
ADMINSERVER_NAME = configProps.get("ADMINSERVER_NAME")
ADMINSERVER_URL = configProps.get("ADMINSERVER_URL")

connect(WEBLOGIC_USER, WEBLOGIC_PASSWORD, ADMINSERVER_URL) 
LOGFILE.writelines("Connected to Admin Server Successfully...!!!" + "\n")
print ''
print '============================================='
print 'Connected to Admin Server Successfully...!!!'
print '============================================='
print ''

print '###### ADMINSERVER NAME = ', ADMINSERVER_NAME
shutdown(force='true')
now = datetime.datetime.now()
LOGFILE.writelines("Successfully stopped " + ADMINSERVER_NAME + " " + str(now) + "\n\n")
print ''
print '============================================='
print '===> Successfully stopped ', ADMINSERVER_NAME, '  <==='
print '============================================='
print ''

LOGFILE.close()

D. startManagedServers.py - Starts all the Managed Servers (comma separated list in properties file)

from java.io import FileInputStream
import java.lang
import os
import string
import datetime

logfile = "startManagedServer.log"
LOGFILE = open(logfile,"a")
now = datetime.datetime.now()
LOGFILE.writelines("Starting Managed Server - " + str(now) + "\n")

propInputStream = FileInputStream("weblogic.properties")
configProps = Properties()
configProps.load(propInputStream)

WEBLOGIC_USER = configProps.get("WEBLOGIC_USER")
WEBLOGIC_PASSWORD = configProps.get("WEBLOGIC_PASSWORD")
HOST = configProps.get("HOST")
NODEMANAGER_PORT = configProps.get("NODEMANAGER_PORT")
DOMAIN_NAME = configProps.get("DOMAIN_NAME")
DOMAIN_HOME = configProps.get("DOMAIN_HOME")
ADMINSERVER_NAME = configProps.get("ADMINSERVER_NAME")
ADMINSERVER_URL = configProps.get("ADMINSERVER_URL")
MANAGEDSERVERS = configProps.get("MANAGEDSERVERS")

while True:
try:
print 'Trying to connect to AdminServer...'
connect(WEBLOGIC_USER, WEBLOGIC_PASSWORD, ADMINSERVER_URL) 
break
except:
print 'Could not connect to Admin Server. Sleeping for 30 seconds...'
sleep(30)

LOGFILE.writelines("Connected to Admin Server Successfully...!!!" + "\n\n")
print ''
print '============================================='
print 'Connected to Admin Server Successfully...!!!'
print '============================================='
print ''

MANAGEDSERVERLIST = MANAGEDSERVERS.split(',')
for MANAGEDSERVER in MANAGEDSERVERLIST:
print 'Starting managed server...'
print '###### MANAGEDSERVER = ', MANAGEDSERVER
start(MANAGEDSERVER, "Server", ADMINSERVER_URL, block="true")
LOGFILE.writelines("Successfully Started " + MANAGEDSERVER + "\n")
print ''
print '============================================='
print '===> Successfully started ', MANAGEDSERVER, '  <==='
print '============================================='
print ''

E. stopManagedServers.py - Stops all the Managed Servers (comma separated list in properties file)

from java.io import FileInputStream
import java.lang
import os
import string
import datetime

logfile = "stopManagedServer.log"
LOGFILE = open(logfile,"a")
now = datetime.datetime.now()
LOGFILE.writelines("Stopping Managed Server - " + str(now) + "\n")

propInputStream = FileInputStream("weblogic.properties")
configProps = Properties()
configProps.load(propInputStream)

WEBLOGIC_USER = configProps.get("WEBLOGIC_USER")
WEBLOGIC_PASSWORD = configProps.get("WEBLOGIC_PASSWORD")
HOST = configProps.get("HOST")
NODEMANAGER_PORT = configProps.get("NODEMANAGER_PORT")
DOMAIN_NAME = configProps.get("DOMAIN_NAME")
DOMAIN_HOME = configProps.get("DOMAIN_HOME")
ADMINSERVER_NAME = configProps.get("ADMINSERVER_NAME")
ADMINSERVER_URL = configProps.get("ADMINSERVER_URL")
MANAGEDSERVERS = configProps.get("MANAGEDSERVERS")

while True:
try:
print 'Trying to connect to AdminServer...'
connect(WEBLOGIC_USER, WEBLOGIC_PASSWORD, ADMINSERVER_URL) 
break
except:
print 'Could not connect to Admin Server. Sleeping for 30 seconds...'
sleep(30)

LOGFILE.writelines("Connected to Admin Server Successfully...!!!" + "\n")
print ''
print '============================================='
print 'Connected to Admin Server Successfully...!!!'
print '============================================='
print ''

MANAGEDSERVERLIST = MANAGEDSERVERS.split(',')
for MANAGEDSERVER in MANAGEDSERVERLIST:
print 'Stopping managed server...'
print '###### MANAGEDSERVER = ', MANAGEDSERVER
shutdown(MANAGEDSERVER, "Server", ADMINSERVER_URL, force="true", block="true")
LOGFILE.writelines("Successfully stopped " + MANAGEDSERVER + "\n\n")
print ''
print '============================================='
print '===> Successfully stopped ', MANAGEDSERVER, '  <==='
print '============================================='
print ''

F. startup.bat - Batch file to start all servers sequentially

startAdminServer.bat && startManagedServer.bat

G. shutdown.bat - Batch file to stop all servers sequentially

stopManagedServer.bat & stopAdminServer.bat

5. Add scripts to system start-up / shutdown

Follow the steps provided here: http://technet.microsoft.com/en-us/library/cc770556.aspx to add startup.bat and shutdown.bat to the system startup and shutdown.