Weblogic Startup Scripts

The following scripts and procedure allows stopping and starting of Weblogic Instances using Jython (Python) scripts and the nodemanager. Services are then created and can be used at startup and shutown for your NodeManager, Admin Server, and Managed Servers.

Assumptions:

Version = Weblogic 10.3.6
MW_HOME = /u01/app/oracle/weblogic1036R2
JAVA_HOME = /u01/app/jdk
DOMAIN = IDMdomain
BOOTSCRIPTS LOCATION = /u01/app/oracle/$MW_HOME/bootscripts
Node Manager is installed and configured.

Configure the nodemanager as follows

#Wed Nov 12 14:39:50 EST 2014
DomainsFile=/u01/app/oracle/weblogic1036R2/wlserver_10.3/common/nodemanager/nodemanager.domains
LogLimit=0
PropertiesVersion=10.3
DomainsDirRemoteSharingEnabled=false
javaHome=/u01/app/oracle/jrockit-jdk
AuthenticationEnabled=false
NodeManagerHome=/u01/app/oracle/weblogic1036R2/wlserver_10.3/common/nodemanager
LogLevel=INFO
DomainsFileEnabled=true
StartScriptName=startWebLogic.sh
ListenAddress=oam1
NativeVersionEnabled=true
ListenPort=5556
LogToStderr=true
SecureListener=false
LogCount=1
DomainRegistrationEnabled=false
StopScriptEnabled=true
QuitEnabled=false
LogAppend=true
StateCheckInterval=500
CrashRecoveryEnabled=false
StartScriptEnabled=true
LogFile=/u01/app/oracle/weblogic1036R2/wlserver_10.3/common/nodemanager/nodemanager.log
LogFormatter=weblogic.nodemanager.server.LogFormatter
ListenBacklog=50

 

Create the main wls.py script

import sys
def startAdmin():
    print 'Starting AdminServer'
    nmConnect(userConfigFile=nmUserFile, userKeyFile=nmKeyFile, host=nmHost, port=nmPort, domainName=domain, domainDir=domainPath, nmType=nmType)
    nmStart('AdminServer')
    nmDisconnect()
    return
def stopAdmin():
    print 'Stopping AdminServer'
    connect(userConfigFile=wlsUserFile, userKeyFile=wlsKeyFile, url=adminUrl)
    shutdown('AdminServer', force='true')
    return

def startManaged(managed):
    print 'Starting ', managed
    connect(userConfigFile=wlsUserFile, userKeyFile=wlsKeyFile, url=adminUrl)
    start(managed)
    disconnect()
    return
def stopManaged(managed):
    print 'Stopping ', managed
    connect(userConfigFile=wlsUserFile, userKeyFile=wlsKeyFile, url=adminUrl)
    shutdown(managed, force='true')
    disconnect()
    return
if ((len(sys.argv) < 2) | (len(sys.argv) > 3)):
    print ' Wrong number of arguments'
elif (sys.argv[1] == 'startadmin'):
    startAdmin()
elif (sys.argv[1] == 'stopadmin'):
    stopAdmin()
elif (sys.argv[1] == 'start'):
    startManaged(sys.argv[2])
elif (sys.argv[1] == 'stop'):
    stopManaged(sys.argv[2])

Next is the startall.sh script

/u01/app/oracle/weblogic1036R2/wlserver_10.3/common/bin/wlst.sh -loadProperties /u01/app/oracle/weblogic1036R2/bootscripts/config.properties -skipWLSModuleScanning /u01/app/oracle/weblogic1036R2/bootscripts/wls.py startadmin
/u01/app/oracle/weblogic1036R2/wlserver_10.3/common/bin/wlst.sh -loadProperties /u01/app/oracle/weblogic1036R2/bootscripts/config.properties -skipWLSModuleScanning /u01/app/oracle/weblogic1036R2/bootscripts/wls.py start oam_server1

stopall.sh

/u01/app/oracle/weblogic1036R2/Oracle_IDM1/common/bin/wlst.sh -loadProperties /u01/app/oracle/weblogic1036R2/bootscripts/config.properties -skipWLSModuleScanning /u01/app/oracle/weblogic1036R2/bootscripts/wls.py stop oam_server1
/u01/app/oracle/weblogic1036R2/Oracle_IDM1/common/bin/wlst.sh -loadProperties /u01/app/oracle/weblogic1036R2/bootscripts/config.properties -skipWLSModuleScanning /u01/app/oracle/weblogic1036R2/bootscripts/wls.py stopadmin

 

config.properties

adminUrl=t3://10.128.14.181:7001
nmHost=oam1
nmPort=5556
nmUserFile=/u01/app/oracle/config/nmUserFile
nmKeyFile=/u01/app/oracle/config/nmKeyFile
nmType=plain
wlsUserFile=/u01/app/oracle/config/wlsUserFile
wlsKeyFile=/u01/app/oracle/config/wlsKeyFile
domain=OAM_domain
domainPath=/u01/app/oracle/weblogic1036R2/user_projects/domains/OAM_domain

 

Before running this command (deprecated in 12c, but still works in 12.1.3), you must source setDomainEnv.sh for the domain you are using.

Encrypt username and password (11g)

source /u01/app/oracle/weblogic1036R2/user_projects/domains/OAM_domain/bin/setDomainEnv.sh

Then run this command to create your encrypted User and Key files

java weblogic.Admin -username weblogic -userconfigfile /u01/app/oracle/config/nmUserFile -userkeyfile /u01/app/oracle/config/nmKeyFile STOREUSERCONFIG

Encrypt credentials for Weblogic

 java weblogic.Admin -username weblogic -userconfigfile /u01/app/oracle/config/wlsUserFile -userkeyfile /u01/app/oracle/config/wlsKeyFile STOREUSERCONFIG

 

Now create your init.d startup scripts

 

/etc/init.d/nodemanager

#!/bin/sh
#
# nodemanager Oracle Weblogic NodeManager service
#
# chkconfig:   345 85 15
# description: Oracle Weblogic NodeManager service
### BEGIN INIT INFO
# Provides: nodemanager
# Required-Start: $network $local_fs
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: Oracle Weblogic NodeManager service.
# Description: Starts and stops Oracle Weblogic NodeManager.
### END INIT INFO
. /etc/rc.d/init.d/functions
# Your WLS home directory (where wlserver is)
export MW_HOME="/u01/app/oracle/weblogic1036R2"
export JAVA_HOME="/u01/app/oracle/jrockit-jdk"
DAEMON_USER="oracle"
PROCESS_STRING="^.*weblogic.NodeManager.*"
source $MW_HOME/wlserver_10.3/server/bin/setWLSEnv.sh > /dev/null
export NodeManagerHome="$WL_HOME/common/nodemanager"
NodeManagerLockFile="$NodeManagerHome/nodemanager.log.lck"
PROGRAM="/u01/app/oracle/weblogic1036R2/user_projects/domains/OAM_domain/bin/startNodeManager.sh"
SERVICE_NAME=`/bin/basename $0`
LOCKFILE="/var/lock/subsys/$SERVICE_NAME"
RETVAL=0
start() {
        OLDPID=`/usr/bin/pgrep -f $PROCESS_STRING`
        if [ ! -z "$OLDPID" ]; then
            echo "$SERVICE_NAME is already running (pid $OLDPID) !"
            exit
        fi
        echo -n $"Starting $SERVICE_NAME: "
        /bin/su $DAEMON_USER -c "$PROGRAM &"
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch $LOCKFILE
}
stop() {
        echo -n $"Stopping $SERVICE_NAME: "
        OLDPID=`/usr/bin/pgrep -f $PROCESS_STRING`
        if [ "$OLDPID" != "" ]; then
            /bin/kill -TERM $OLDPID
        else
            /bin/echo "$SERVICE_NAME is stopped"
        fi
        echo
        /bin/rm -f $NodeManagerLockFile
        [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
}
restart() {
        stop
        sleep 10
        start
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|force-reload|reload)
        restart
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac
exit $RETVAL

The weblogic scripts call the startall.sh when the server starts, and stopall.sh when the server stops.

/etc/init.d/weblogic

#!/bin/sh
#
# weblogic Oracle Weblogic start
#
# chkconfig: 345 85 15
# description: Oracle Weblogic service
### BEGIN INIT INFO
# Provides:
# Required-Start: $nodemanager
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: Oracle Weblogic service.
# Description: Starts and stops Oracle Weblogic.
### END INIT INFO
 . /etc/rc.d/init.d/functions
# Your WLS home directory (where wlserver is)
export MW_HOME="/u01/app/oracle/weblogic1036R2"
export BOOT_HOME="$MW_HOME/bootscripts"
export JAVA_HOME="/u01/app/oracle/jrockit-jdk"
DAEMON_USER="oracle"
source $MW_HOME/wlserver_10.3/server/bin/setWLSEnv.sh > /dev/null
PROGRAM_START="$BOOT_HOME/startall.sh"
PROGRAM_STOP="$BOOT_HOME/stopall.sh"
SERVICE_NAME=`/bin/basename $0`
LOCKFILE="/var/lock/subsys/$SERVICE_NAME"
RETVAL=0
start() {
 echo -n $"Starting $SERVICE_NAME: "
 /bin/su $DAEMON_USER -c "$PROGRAM_START &" RETVAL=$?
 echo [ $RETVAL -eq 0 ] && touch $LOCKFILE
}
 stop() {
 echo -n $"Stopping $SERVICE_NAME: "
 /bin/su $DAEMON_USER -c "$PROGRAM_STOP &" RETVAL=$?
 [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
 }
 restart() {
 stop
 sleep 10
 start
}
case "$1" in
 start)
        start
        ;;
 stop)
        stop
        ;;
 restart|force-reload|reload)
        restart
        ;;
 *)
        echo $"Usage: $0 {start|stop|restart}"
esac
exit 1

 

Both the nodemanager and weblogic startup scripts need to made runable (chmod 755) and then added to chkconfig

chkconfig --add weblogic
chkconfig --add nodemanager

Update your Nodemanager type to be “Plain”

image2015-6-24 7-54-27

This can be done for each domain on your server

Well Done! Grab a beer

 

Weblogic startup scripts using “UpStart”

I previously wrote on how to create weblogic startup scripts using standard init.d scripting. There is an even easier way to do things now. Why not use upstart, which is an event based replacement for the /sbin/init daemon.

Simply create a file “wlnode.conf” and put it in the /etc/init directory. This will start the Weblogic Nodemanager. You will need to modify based on your installation of course.

1st Weblogic Server

/etc/init/wlnode.conf

start on runlevel [345]
# console output
exec /bin/su - oracle -- /u01/app/oracle/middleware/user_projects/domains/DEV_domain/bin/startWebLogic.sh

Now you want the Weblogic Admin to start as well? Create a file called wladmin.conf

/etc/init/wladmin.conf

start on runlevel [345]
# console output
exec /bin/su - oracle -- /u01/app/oracle/middleware/user_projects/domains/DEV_domain/bin/startWebLogic.sh

Do you have any instances? You can start them too. Create a file called wlinstance1.conf

/etc/init/wlinstance1.conf

start on runlevel [345]
exec /bin/su - oracle -- /u01/app/oracle/middleware/user_projects/domains/DEV_domain/bin/startManagedWebLogic.sh instance1

To start and stop and find status, simply run “start wlnode”, “stop wlnode” and “status wlnode” using whatever you named your config file in /etc/init.

If you have a cluster setup, then you need to make sure the node manager is running and configured correctly on the second server. Once that is setup, you can add the following Upstart config files to bring everything up.

Second Weblogic Server

/etc/init/wlnode.conf

start on runlevel [345]
# console output
exec /bin/su - oracle -- /u01/app/oracle/middleware/user_projects/domains/DEV_domain/bin/startWebLogic.sh

/etc/init/wlinstance2.conf

start on runlevel [345]
exec /bin/su - oracle -- /u01/app/oracle/middleware/user_projects/domains/DEV_domain/bin/startManagedWebLogic.sh instance2 http://centos.my.lan:7001

This is just a quick example and much more can be done using UpStart!