Technical

Starting servers with WLST

Starting a server

You can start a server in WLST using the startServer() command, but it’s recommended to use the NodeManager to start and stop servers. This is mainly because the NodeManager can manage servers on multiple machines at once, whereas the startServer() can only work on local servers. The process to start a server is:

startNodeManager(NodeManagerHome='/oracle/product/middleware/wlserver_10.3/common/nodemanager')
nmConnect('weblogic', 'welcome1', 'localhost', 5556, 'osb_domain', '/oracle/config/domains/osb_domain', 'plain')
nmStart('AdminServer')

NodeManager properties

The nodemanager.properties file sets up the configuration required to start a node manager. The NodeManager will create a properties file by default when first started if you haven’t provided one. If you intend to start servers via the node manager in WLST you will have to need to change StartScriptEnabled to true. If you don’t the node manager will start the server but not apply the classpath and other environment variables. You will get an error like this:

<BEA-000286> <Failed to invoke startup class "JRF Startup Class", java.lang.ClassNotFoundException: oracle.jrf.wls.JRFStartup
java.lang.ClassNotFoundException: oracle.jrf.wls.JRFStartup

The following nodemanager.properties file will work for WLST (I’ve also turned SSL off for the NodeManager as the plain connection is faster to start. For production systems you should connect via SSL)

DomainsFile=/oracle/product/middleware/wlserver_10.3/common/nodemanager/nodemanager.domains 
LogLimit=0 
PropertiesVersion=10.3 
DomainsDirRemoteSharingEnabled=false 
javaHome=/usr/java/jdk1.7.0_45 
AuthenticationEnabled=true 
NodeManagerHome=/oracle/product/middleware/wlserver_10.3/common/nodemanager 
JavaHome=/usr/java/jdk1.7.0_45/jre 
LogLevel=INFO 
DomainsFileEnabled=true 
StartScriptName=startWebLogic.sh 
ListenAddress= 
NativeVersionEnabled=true 
ListenPort=5556 
LogToStderr=true 
SecureListener=false 
LogCount=1 
DomainRegistrationEnabled=false 
StopScriptEnabled=false 
QuitEnabled=false 
LogAppend=true 
StateCheckInterval=500 
CrashRecoveryEnabled=false 
StartScriptEnabled=true 
LogFile=/oracle/product/middleware/wlserver_10.3/common/nodemanager/nodemanager.log 
LogFormatter=weblogic.nodemanager.server.LogFormatter 
ListenBacklog=50

Putting it all together

I’ve added a build script in our GitHub repo that starts up the NodeManager (if it’s not running) and then starts the AdminServer for a domain. It needs some work to be part of a full-fledged build environment, but it should get you started. It’s fairly straight-forward, but let’s step through the key steps.

echo "Checking if node manager is running"
nodePid=`/bin/ps -eo pid,cmd | /bin/grep weblogic.NodeManager | /bin/grep -v grep | awk '{print $1}'`

First, we check if the NodeManager is running by checking for it in the running processes.

if [ ${nodePid} ]
then
echo "The NodeManager is already running."
else
echo "NodeManager not running. Start NodeManager"
$WL_HOME/common/bin/wlst.sh <<-EOF
startNodeManager(NodeManagerHome='/oracle/product/middleware/wlserver_10.3/common/nodemanager')
EOF

If it’s not, then we open a WLST shell and run the startNodeManager command. We could have simply called the startNodeManager script in the WL_HOME/server/bin folder, but this script needs to be run in the background as it won’t return control to this script. This means that you’d have to add some logic to wait for the node manager to start before continuing. The startNodeManager command will handle this for us and only resume control once the NodeManager has started.

$WL_HOME/common/bin/wlst.sh <<-EOF
nmConnect('weblogic', 'welcome1', 'localhost', 5556, '$DOMAIN', '$DOMAIN_PATH', 'plain')
nmStart('AdminServer')
nmServerStatus('AdminServer')
nmDisconnect()
EOF

Then we check if the AdminServer is running in a similar manner to above and if it’s not we again start a WLST console and connect to the NodeManager and start the server.

Tips

  • When you use wlst.sh it echoes the CLASS_PATH which results in a large amount of useless text. I recommend editing the WL_HOME/common/bin/wlst.sh file and commenting out the echo CLASSPATH={$CLASSPATH} line
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s