Oracle Weblogic password reset script

If you want to reset the ‘GOD’ password for Weblogic Server

Start the script and follow instructions

  <path_to_wlst>/wlst.sh resetWLS_password.py

Code for resetWLS_password.py

import datetime
import os
import random
import re
import string
import sys
import traceback

def tempname():
    return "/tmp/resetPassLog" + str(random.randint(1000, 9999))

def shout(cmd, check_returncode=False, check_output=False):
    tmpfile = tempname()
    retval = os.system(cmd + " >" + tmpfile + " 2>&1")
    file = open(tmpfile)
    out = file.read()
    file.close()
    os.system("rm -f " + tmpfile + " >/dev/null 2>&1")
    if check_returncode:
        if retval <> 0:
            print string.strip(out)
            raise Exception("Error: return code " + str(retval) + " from command: " + cmd)
    if check_output:
        if re.search(('ERROR|[Ee]rror|FAIL|[Ff]ail|TIMEOUT|[Tt]imeout'), out):
            print string.strip(out)
            raise Exception("Error message found from command: " + cmd)
    return string.strip(out)

def shlines(cmd):
    return string.split(shout(cmd), "\n")

# RETURN LIST OF PROCESS IDS FROM GREPING PROCESS COMMANDS
def psgrep(str):
    pat = re.compile(str)
    cmd = "ps -e -o pid,command"
    lines = shlines("ps -e -o pid,command")
    pids = []
    for line in lines:
        cols = string.split(line)
        if cols[1] == "grep": continue
        for col in cols[1:]:
            if pat.search(col):
                pids.append(cols[0])
                continue
    return pids
def stop_process_tree(ppid):
    java.lang.Thread.sleep(1)
    pids = get_child_processes(ppid)
    while len(pids) > 0:
        for pid in pids:
            stop_process_tree(pid)
        pids = get_child_processes(ppid)
    kill_process(ppid)
    return

def kill_process(pid):
    if pid == None or pid == '':
        return
    java.lang.Thread.sleep(1)
    if shout("ps -o pid= --pid " + pid) != '':
        os.system("kill " + pid)
    for i in range(30):
        java.lang.Thread.sleep(1)
        if shout("ps -o pid= --pid " + pid) == '':
            return
    os.system("kill -9 " + pid)
    for i in range(30):
        java.lang.Thread.sleep(1)
        if shout("ps -o pid= --pid " + pid) == '':
            return
    error("Cannot kill " + pid)
    return

def get_child_processes(ppid):
    return string.split(shout("ps -o pid= --ppid " + ppid))

#Stop adminserver
def stop_adminserver(name, domain_home):
    print "stopping adminserver " + name
    pids = psgrep("weblogic.Name=" + name)
    for pid in pids:
        stop_process_tree(pid)
    pids = psgrep(domain_home + "/startWebLogic.sh")
    for pid in pids:
        stop_process_tree(pid)
    pids = psgrep(domain_home + "/pointbase.ini")
    for pid in pids:
        stop_process_tree(pid)
    lok = domain_home + "/servers/" + name + "/tmp/" + name + ".lok"
    os.system("rm -f " + lok)
    print "stopped  adminserver " + name
    return ""

def start_adminserver(name, domain_home):
    if len(psgrep(domain_home + "/startWebLogic.sh")) > 0:
        print "adminserver " + name + " already running"
        return ""
    print "starting adminserver " + name
    scriptfile = domain_home + "/startAdminServer.sh"
    outfile = domain_home + "/nohup.out"
    file = open(scriptfile, "w")
    file.write("#!/bin/bash\n")
    file.write(domain_home + "/startWebLogic.sh >" + outfile + " 2>&1 &\n")
    file.close()
    os.system("rm -f " + outfile)
    os.system("chmod 0755 " + scriptfile)
    os.system(scriptfile)
    n = 1900
    while n > 0:
        n = n - 1
        java.lang.Thread.sleep(1)
        file = open(outfile, "r")
        text = file.read()
        file.close()
        if string.find(text, "Server state changed to RUNNING") > -1:
            print "started  adminserver " + name
            return ""
        if string.find(text, "Server state changed to FAILED") > -1:
            errmsg = "ERROR STARTING ADMIN SERVER " + name
            print errmsg
            return errmsg
    errmsg = "ERROR: timeout starting " + name
    return errmsg

##############################
print "Please enter domain data: "
now = datetime.datetime.now()
adminUser = raw_input("Enter Admin user: ")
oldAdminPassword = raw_input("Enter OLD password: ")
newAdminPassword = raw_input("Enter NEW password: ")
url = raw_input("Please, enter url (t3 or http): ")

print "Connection to Oracle Weblogic Adminserver"
connect(adminUser, oldAdminPassword, url)
domainName=cmo.getName()
domainHome = cmo.getRootDirectory()
adminServerName = cmo.getAdminServerName()

cd('/SecurityConfiguration/'+domainName+'/Realms/myrealm/AuthenticationProviders/DefaultAuthenticator')
cmo.resetUserPassword(adminUser,newAdminPassword)
disconnect()
print "Adminpassword succesfully changed"
print "Connecting Using New Credentials....."
connect(adminUser,newAdminPassword,url)
print "Successfully Connected Using New Credentials !!!!"
disconnect()

print " Resetting boot.properties "
bootfile = domainHome + "/boot.properties"
f = open(bootfile, "w")
bootfilestr = "Password file changed by reset adminpass script on " + str(now) + "\n"
bootfilestr += "username=" + adminUser + "\n"
bootfilestr += "password=" + newAdminPassword
f.write(bootfilestr)
f.close()
print "Boot.properties succesfully set"
stop_adminserver(adminServerName, domainHome)
os.system("rm " + domainHome + "/servers/" + adminServerName + "/security/boot.properties")
os.system("cp " + bootfile + " " + domainHome + "/servers/" + adminServerName + "/security/")
start_adminserver(adminServerName, domainHome)
Advertisements

Oracle JDBC URL types

In Oracle Weblogic we define an url for every datasource. Hereby an overview of the different types URL’s. Note the database service name which points to the RAC listeners.

Simple JDBC Connection String

jdbc:oracle:thin:@localhost:1521:xe

Load-Balanced JDBC Connection String

jdbc:oracle:thin:@(description=(address_list=
(load_balance=on)
(failover=on)
(address=(protocol=tcp)(host=dev-database-2.org.com)(port=1521))
(address=(protocol=tcp)(host=dev-database-2.org.com)(port=1521)))
(connect_data=(service_name=rac1)))

Failover JDBC Connection String

jdbc:oracle:thin:@(description=(address_list=
(load_balance=off)
(failover=on)
(address=(protocol=tcp)(host=dev-database-2.org.com)(port=1521))
(address=(protocol=tcp)(host=dev-database-2.org.com)(port=1521)))
(connect_data=(service_name=rac1)))

Oracle enterprise Linux 5: Install GIT

For those who are getting to the mext level of versioning and have to use EL5.

1. Get the extra packages for EL5:

wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -Uvh ./epel-release-5-4.noarch.rpm

wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -Uvh ./epel-release-5-4.noarch.rpm

2. Use yum to get GIT

yum install git
yum install git-svn

Oracle SOA high availabilty documentation

Following links contain good describtions for making Oracle  SOA Suite HA.

1.  Extending the Domain for SOA Components

http://docs.oracle.com/cd/E21043_01/core.1111/e12037/extend_soa.htm#CDEDHDHA

2. A document which bundles the Oracle documentation

http://www.namredlek.nl/orasoa/InstallSOASuite11gOnCluster_v1.pdf

3. Clustering SOA suite (theorectical description)

http://blogs.oracle.com/reynolds/entry/clustering_soa_suite

4. Scripting your Oracle SOA 11g Cluster (Scripts are not complete)

http://orasoa.blogspot.com/2010/12/scripting-your-oracle-soa-11g-cluster.html