Booting Oracle WebLogic

Content might be outdated

This post is related to our presentations at Oracle OpenWorld 2014 and UKOUG Tech 14. All code/configuration used during the presentations are available here.

To start and stop AdminServer and the managed servers, we use a Jython (Python) script. It is on purpose made simple, but on production systems there should be more error handling, and also more efficient connection handling (i.e., check if there is a connection to NodeManager and/or AdminServer and reuse the connection if there is one active). Instead of calling the script below once for each server that we want to start, this script and the startall.sh script could be changed to give a list of servers to start, not just one and one as it is now.

wls.py

 1import sys
 2
 3def startAdmin():
 4    print 'Starting AdminServer'
 5    nmConnect(userConfigFile=nmUserFile, userKeyFile=nmKeyFile, host=nmHost, port=nmPort, domainName=domain, domainDir=domainPath, nmType=nmType)
 6    nmStart('AdminServer')
 7    nmDisconnect()
 8    return
 9
10def stopAdmin():
11    print 'Stopping AdminServer'
12    connect(userConfigFile=wlsUserFile, userKeyFile=wlsKeyFile, url=adminUrl)
13    shutdown('AdminServer', force='true')
14    disconnect()
15    return
16
17def startManaged(managed):
18    print 'Starting ', managed
19    connect(userConfigFile=wlsUserFile, userKeyFile=wlsKeyFile, url=adminUrl)
20    start(managed)
21    disconnect()
22return
23
24def stopManaged(managed):
25    print 'Stopping ', managed
26    connect(userConfigFile=wlsUserFile, userKeyFile=wlsKeyFile, url=adminUrl)
27    shutdown(managed, force='true')
28    disconnect()
29return
30
31if ((len(sys.argv) < 2) | (len(sys.argv) > 3)):
32    print ' Wrong number of arguments'
33elif (sys.argv[1] == 'startadmin'):
34    startAdmin()
35elif (sys.argv[1] == 'stopadmin'):
36    stopAdmin()
37elif (sys.argv[1] == 'start'):
38    startManaged(sys.argv[2])
39elif (sys.argv[1] == 'stop'):
40    stopManaged(sys.argv[2])

Full path for wlst.sh (under wlserver/common/bin) and wls.py must be given, unless they are in $PATH

startall.sh

1wlst.sh -loadProperties config.properties -skipWLSModuleScanning wls.py startadmin
2wlst.sh -loadProperties config.properties -skipWLSModuleScanning wls.py start ms1

stopall.sh

1wlst.sh -loadProperties config.properties -skipWLSModuleScanning wls.py stop ms1
2wlst.sh -loadProperties config.properties -skipWLSModuleScanning wls.py stopadmin

adminUrl must point to the AdminServer (often a VIP address) while nmHost points to the local NodeManager.

config.properties

 1adminUrl=t3://wls12c.dev.sysco.no:7001
 2nmHost=wls12c.dev.sysco.no
 3nmPort=5556
 4nmUserFile=/u01/app/oracle/config/nmUserFile
 5nmKeyFile=/u01/app/oracle/config/nmKeyFile
 6nmType=plain
 7wlsUserFile=/u01/app/oracle/config/wlsUserFile
 8wlsKeyFile=/u01/app/oracle/config/wlsKeyFile
 9domain=mydomain
10domainPath=/u01/app/oracle/user_projects/domains/mydomain

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)

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

To run this command, you must start WLST in interactive mode. First you have to source setDomainEnv.sh, then start WLST

Encrypt username and password (12c)

1java weblogic.WLST
2wls:/offline> nmConnect( ‘nodemanager','welcome1','localhost',5556,'mydomain', '/u01/app/oracle/user_projects/domains/mydomain', 'plain')

Encrypt username and password for Node Manager

1wls:/mydomain/serverConfig> storeUserConfig(
2'/u01/app/oracle/config/nmUserFile','/u01/app/oracle/config/nmKeyFile', 'true')

Encrypt username and password for WebLogic admin user

1wls:/mydomain/serverConfig> connect('weblogic', 'welcome1', 't3://wls12c.dev.sysco.no:7001')
2wls:/mydomain/serverConfig> storeUserConfig(
3'/u01/app/oracle/config/wlsUserFile','/u01/app/oracle/config/wlsKeyFile','false')

This is not based on the script from the 12c documentation http://docs.oracle.com/middleware/1213/wls/NODEM/java_nodemgr.htm#BABJIDFD. One important difference is that this script starts NodeManager with user oracle, while the script in the documentation starts NodeManager as root, which is not recommended.

/etc/init.d/nodemanager

 1#!/bin/sh
 2#
 3# nodemanager Oracle Weblogic NodeManager service
 4#
 5# chkconfig:   345 85 15
 6# description: Oracle Weblogic NodeManager service
 7
 8### BEGIN INIT INFO
 9# Provides: nodemanager
10# Required-Start: $network $local_fs
11# Required-Stop:
12# Should-Start:
13# Should-Stop:
14# Default-Start: 3 4 5
15# Default-Stop: 0 1 2 6
16# Short-Description: Oracle Weblogic NodeManager service.
17# Description: Starts and stops Oracle Weblogic NodeManager.
18### END INIT INFO
19
20. /etc/rc.d/init.d/functions
21
22# Your WLS home directory (where wlserver is)
23export MW_HOME="/u01/app/oracle/middleware/Oracle_Home"
24export JAVA_HOME="/usr/java/latest"
25DAEMON_USER="oracle"
26PROCESS_STRING="^.*weblogic.NodeManager.*"
27
28source $MW_HOME/wlserver/server/bin/setWLSEnv.sh &gt; /dev/null
29export NodeManagerHome="$WL_HOME/common/nodemanager"
30NodeManagerLockFile="$NodeManagerHome/nodemanager.log.lck"
31
32PROGRAM="/u01/app/oracle/user_projects/domains/mydomain/bin/startNodeManager.sh"
33SERVICE_NAME=`/bin/basename $0`
34LOCKFILE="/var/lock/subsys/$SERVICE_NAME"
35
36RETVAL=0
37
38start() {
39        OLDPID=`/usr/bin/pgrep -f $PROCESS_STRING`
40        if [ ! -z "$OLDPID" ]; then
41            echo "$SERVICE_NAME is already running (pid $OLDPID) !"
42            exit
43        fi
44
45        echo -n $"Starting $SERVICE_NAME: "
46        /bin/su $DAEMON_USER -c "$PROGRAM &amp;"
47
48        RETVAL=$?
49        echo
50        [ $RETVAL -eq 0 ] && touch $LOCKFILE
51}
52
53stop() {
54        echo -n $"Stopping $SERVICE_NAME: "
55        OLDPID=`/usr/bin/pgrep -f $PROCESS_STRING`
56        if [ "$OLDPID" != "" ]; then
57            /bin/kill -TERM $OLDPID
58        else
59            /bin/echo "$SERVICE_NAME is stopped"
60        fi
61        echo
62        /bin/rm -f $NodeManagerLockFile
63        [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
64
65}
66
67restart() {
68        stop
69        sleep 10
70        start
71}
72
73case "$1" in
74  start)
75        start
76        ;;
77  stop)
78        stop
79        ;;
80  restart|force-reload|reload)
81        restart
82        ;;
83  *)
84        echo $"Usage: $0 {start|stop|restart}"
85        exit 1
86esac
87
88exit $RETVAL

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

/etc/init.d/weblogic

 1#!/bin/sh
 2#
 3# weblogic Oracle Weblogic start
 4#
 5# chkconfig: 345 85 15
 6# description: Oracle Weblogic service
 7
 8### BEGIN INIT INFO
 9# Provides:
10# Required-Start: $nodemanager
11# Required-Stop:
12# Should-Start:
13# Should-Stop:
14# Default-Start: 3 4 5
15# Default-Stop: 0 1 2 6
16# Short-Description: Oracle Weblogic service.
17# Description: Starts and stops Oracle Weblogic.
18### END INIT INFO
19
20 . /etc/rc.d/init.d/functions
21
22# Your WLS home directory (where wlserver is)
23export MW_HOME="/u01/app/oracle/middleware/Oracle_Home"
24export BOOT_HOME="/u01/app/oracle/bootscripts"
25export JAVA_HOME="/usr/java/latest"
26DAEMON_USER="oracle"
27
28source $MW_HOME/wlserver/server/bin/setWLSEnv.sh &gt; /dev/null
29PROGRAM_START="$BOOT_HOME/startall.sh"
30PROGRAM_STOP="$BOOT_HOME/stopall.sh"
31SERVICE_NAME=`/bin/basename $0`
32LOCKFILE="/var/lock/subsys/$SERVICE_NAME"
33RETVAL=0
34
35start() {
36 echo -n $"Starting $SERVICE_NAME: "
37 /bin/su $DAEMON_USER -c "$PROGRAM_START &amp;" RETVAL=$?
38 echo [ $RETVAL -eq 0 ] && touch $LOCKFILE
39}
40
41 stop() {
42 echo -n $"Stopping $SERVICE_NAME: "
43 /bin/su $DAEMON_USER -c "$PROGRAM_STOP &amp;" RETVAL=$?
44 [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
45 }
46
47 restart() {
48 stop
49 sleep 10
50 start
51}
52
53case "$1" in
54 start)
55        start
56        ;;
57 stop)
58        stop
59        ;;
60 restart|force-reload|reload)
61        restart
62        ;;
63 *)
64        echo $"Usage: $0 {start|stop|restart}"
65esac
66
67exit 1

For both the nodemanager and the weblogic scripts, they must be made runnable (chmod 0755) and activated (chkconfig --add) before they will be used next time the server starts or stops.

First published on Sysco Middlware Blog