cinqict

Friday, April 5, 2013

Standardized environment settings

As you might know, weblogic has the ability to store the weblogic-, and nodemanager user credentials in a UserConfig-file (See other post on this blog to see how to create these).
Using these stores can make our lives a lot easier in managing multiple weblogic environments and create a sort of 'write-once-run-anywhere'-possibility for our home-made wlst-scripts.
Most important here, is to have a uniform location for the userconfig stores.
You probably have a location like /u01 for the weblogic instances on your servers, but you could also use a common place like /var/somedir. As long as the path to the location is equal on all machines and the location itself is a safe place (we don't want to expose these files!!!), you're good.

In this example I make the following assumptions:

We have a machine that hosts 4 domains, each having it's own nodemanager (I know, not necessary, could do with one. Just for the example...)

We have a user oracle managing the weblogic server.

We have a directory /u01 in which weblogic is running.

We have stored our userconfigstores in /u01/app/wl_userconfig/${DOMAIN_NAME}

First of all, we need a file called /home/oracle/wlconfig/wlDomainList
This file contains all the data needed for loading the environment settings. As this data is bound to the server, we can place it in our home directory.

The file in our example contains the following:


#  domainname domaindir adminurl nmhost   nmport  nmhome nmtype
1  domain1    /u01/app/domains/domain1   t3s://server.domain.com:27021   server.domain.com  7020    /u01/app/nodemanagers/MACHINE1 ssl
2  domain2    /u01/app/domains/domain2   t3s://server.domain.com:28021   server.domain.com  8020    /u01/app/nodemanagers/MACHINE2 ssl
3  domain3    /u01/app/domains/domain3   t3s://server.domain.com:25021   server.domain.com  5020    /u01/app/nodemanagers/MACHINE3 plain
4  domain4    /u01/app/domains/domain4   t3s://server.domain.com:26021   server.domain.com  6020    /u01/app/nodemanagers/MACHINE4 ssl


Make sure that you have one line per domain in the file containing:

domainname = name of the domain
domaindir = location of the domainhome
adminurl = the url to the admin server
nmhost = the servername running the nodemanager
nmport = nodemanager port number
nmhome = location of the nodemanagerhome
nmtype = plain or ssl nodemanager connection

Now, create a file /u01/app/wl_userconfig/bin/wlenvaps containing the following code.
This script will be loaded at login and will load the domain specific environment.

#declarere variabes
wlDomainList=$HOME/wlconfig/wlDomainList
wlConfigPath=/u01/app/wl_userconfig
wlConfigFile=wlconfigfile.secure
wlKeyFile=wlkeyfile.secure
nmConfigFile=nmconfigfile.secure
nmKeyFile=nmkeyfile.secure



showDomains (){
if [ -e $wlDomainList ]
then
        awk '{print $1,$2}' $wlDomainList

else
        echo "DomainListfile does not exist!" && exit 
fi

}

enterNumber (){
        echo "Please, enter the number of the domain home you wich to use:"

}

readDomain (){
        read DOMAINCHOICE
}

validateDomainChoice (){
        case $DOMAINCHOICE in
        ''|*[!0-9]*) echo "You did not enter a valid number."
        playAgain;;
        *) processDomain ;;
        esac
}

processDomain (){
        DOMHOME=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$3 }" $wlDomainList)
        DOMNAME=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$2 }" $wlDomainList)
        ADMINURL=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$4 }" $wlDomainList)
        NMHOST=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$5 }" $wlDomainList)
        NMPORT=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$6 }" $wlDomainList)
        NMHOME=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$7 }" $wlDomainList)

        NMTYPE=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$8 }" $wlDomainList)

        if [[ ! -z $DOMHOME ]]
        then
                export WLDOMHOME=$DOMHOME
                export WLDOMNAME=$DOMNAME
                export WLCONFIGPATH=$wlConfigPath/$DOMNAME
                export WLCONFIGFILE=$wlConfigPath/$DOMNAME/$wlConfigFile
                export WLKEYFILE=$wlConfigPath/$DOMNAME/$wlKeyFile
                export WLADMINURL=$ADMINURL
                export WLNMCONFIGFILE=$wlConfigPath/$DOMNAME/$nmConfigFile
                export WLNMKEYFILE=$wlConfigPath/$DOMNAME/$nmKeyFile
                export WLNMHOST=$NMHOST
                export WLNMPORT=$NMPORT
                export WLNMHOME=$NMHOME

                export WLNMTYPE=$NMTYPE
                export WLSTHOME=$DOMHOME/bin
                export PATH=$WLSTHOME:$PATH
                echo $DOMHOME " has been loaded as your domainhome."

                PS1="${USER}[${WLDOMNAME}](\${PWD})$ "
                echo "Setting domain environment settings..."
                . $WLDOMHOME/bin/setDomainEnv.sh
                clear
        else
                echo "No valid Domain was loaded!"
                playAgain
        fi
}

playAgain (){
        echo "Wanna play again? y or n"
        read  PLAYAGAIN
        if [[ $PLAYAGAIN == 'y' ]]
        then
                . /w001/nfs/wl_userconfig/bin/wlenvaps
        fi
}



showDomains
enterNumber
readDomain
validateDomainChoice

#Some weblogic specific aliases

alias serverstate='wlst.sh /u01/app/wlstscripts/serverState.py'
alias clusterstate='wlst.sh /u01/app/wlstscripts/clusterState.py'
alias stopallclusters='wlst.sh /u01/app/wlstscripts/stopAllClusters.py'
alias startallclusters='wlst.sh /u01/app/wlstscripts/startAllClusters.py'
alias startnm='wlst.sh /u01/app/wlstscripts/startNodeManager.py'
alias stopnm='wlst.sh /u01/app/wlstscripts/stopNodeManager.py'
alias startadmin='wlst.sh /u01/app/wlstscripts/startAdmin.py'
alias stopadmin='wlst.sh /u01/app/wlstscripts/killAdmin.py'
alias stopapp='wlst.sh /u01/app/wlstscripts/stopapp.py -a'
alias startapp='wlst.sh /u01/app/wlstscripts/startapp.py -a'
alias startcluster='wlst.sh /u01/app/wlstscripts/startCluster.py -a'
alias stopcluster='wlst.sh /u01/app/wlstscripts/stopCluster.py -a'
alias domhome='cd $WLDOMHOME'
alias nmhome='cd $WLNMHOME'
alias serverhome='cd $WLDOMHOME/servers'



 Next step is to make sure that this script is called at login.
For the oracle user, in the .profile or .bash_profile (depending on your OS) in the homedir, set the following:

#LOAD WEBLOGIC DOMAIN SETTINGS
. /u01/app/wl_userconfig/bin/wlenvaps


Now, logout and login again to the oracle user. You will get the following menu:

# domainname
1 domain1
2 domain2
3 domain3
4 domain4
Please, enter the number of the domain home you wich to use:


Choose your domain. The environment settings will be loaded.
Check your variables with env | sort
You will see a bunch of WL... variables that are now available. Use them wisely ;)

At the bottom of the wlenvaps, you see I created a few aliases to wlst scripts.
Of course, these will be different in your environment.
The thing here is, that you can have a folder (/u01/app/wlstscripts/ in the example) were you can store your wlst scripts.
Make sure the location of this folder is the same on all machines. You could even create this on shared storage like nfs or so.

Now that we have set our environment variables, we can use these in our wlst scripts, so you can create the scripts once and run them on all systems that conform to these 'standards'For example, here is the startAllClusters.py script.
Notice the Variables bit at the top. These make the scripts flexible and usable on all systems.

import os
#Variables
domain=os.getenv("WLDOMNAME")
adminUrl=os.getenv("WLADMINURL")
nmConfigFile=os.getenv("WLNMCONFIGFILE")
nmKeyFile=os.getenv("WLNMKEYFILE")
nmHost=os.getenv("WLNMHOST")
nmPort=os.getenv("WLNMPORT")

nmConnType=os.getenv("WLNMTYPE")

#Connect to NodeManager and start the admin server....
nmConnect(userConfigFile=nmConfigFile, userKeyFile=nmKeyFile, host=nmHost, port=nmPort, domainName=domain, nmType=nmConnType)
nmStart('AdminServer')

oraoas[UPA_GAT](/w001/app/wlstscripts)$ cat startAllClusters.py
import os

#Variables
adminUrl=os.getenv("WLADMINURL")
wlConfigFile=os.getenv("WLCONFIGFILE")
wlKeyFile=os.getenv("WLKEYFILE")

#Connect to Admin
print 'Connecting to AdminServer...'
connect(userConfigFile=wlConfigFile,userKeyFile=wlKeyFile,url=adminUrl)

#Get Serverstates
clusterNames = cmo.getClusters()
for clusterName in clusterNames:
  cd('/')
  start(clusterName.getName(),'Cluster')

disconnect()
exit()

 

 

Wednesday, April 3, 2013

weblogic custom log directory

In order to move the default log directory to a custom location, I have created the following piece of script. This can be inserted into the $DOMAIN_HOME/startWeblogic.sh script, under #START WEBLOGIC.

In the example I will place the custom log directory in /w001/logs/${DOMAIN_NAME}/serverlogs/${SERVER_NAME}



if [ -d ${DOMAIN_HOME}/servers/${SERVER_NAME} ] && [ ! -L ${DOMAIN_HOME}/servers/${SERVER_NAME}/logs ] ; then
DOMAIN_NAME=`echo ${DOMAIN_HOME} | awk -F/ '{ print $NF }'`
mkdir -p /w001/logs/${DOMAIN_NAME}/serverlogs/${SERVER_NAME}
mv ${DOMAIN_HOME}/servers/${SERVER_NAME}/logs ${DOMAIN_HOME}/servers/${SERVER_NAME}/logs.old && ln -s /w001/logs/${DOMAIN_NAME}/serverlogs/${SERVER_NAME} ${DOMAIN_HOME}/servers/${SERVER_NAME}/logs
fi


The existing log directory is moved to a logs.old directory, so you can copy these logs at a later time.

Enabling gc verbose logging

To enable garbage collection logging, you can put the -verbose:gc in the setDomainEnv.sh script. This makes it possible to enable the gc logging for multiple servers.
You can make use of the SERVER_NAME and DOMAIN_HOME variable, which are already set in the script, to write the logs to the standard log location.

In this example, the gc logs are enabled for all servers starting with ppls:


if echo ${SERVER_NAME} | grep -Eq '^ppls' ; then
EXTRA_JAVA_PROPERTIES="${EXTRA_JAVA_PROPERTIES} -verbose:gc -Xverbosegclog:/${DOMAIN_HOME}/servers/${SERVER_NAME}/logs/gc#.log,100,1000 "
export EXTRA_JAVA_PROPERTIES
fi


Thursday, March 14, 2013

Setting memory and other java options

In the domain home directory, there is a file setDomainEnv.sh (I'm ignoring windows here...)

There is a section called USER_MEM in that file, which can be used to adjust java settings on servername basis.
You can use regular expressions like so:

 # IF USER_MEM_ARGS the environment variable is set, use it to override ALL MEM_ARGS values
if [ "${SERVER_NAME}" = "AdminServer" ] ; then
        USER_MEM_ARGS="-Xms512m -Xmx1024m"
        MEM_ARGS="${USER_MEM_ARGS}"    
        export USER_MEM_ARGS
else
        USER_MEM_ARGS="-Xms2048m -Xmx2048m"
        MEM_ARGS="${USER_MEM_ARGS}"
        export MEM_ARGS
fi


That would set the memory to 2gb min max for all servers, except the AdminServer.

You can alse use regex like this:

# jdk settings
if echo ${SERVER_NAME} | grep -Eq '^osb' ; then
        EXTRA_JAVA_PROPERTIES="${EXTRA_JAVA_PROPERTIES} -Xcompressedrefs "
        export EXTRA_JAVA_PROPERTIES
fi


That is; For all servernames, starting with osb... use 32bits references.