Thursday, December 9, 2010

How to start a Node Agent using scripting?

This is a tricky question.  The quick answer is that it can't be done using the typical wsadmin commands.  But it can be done by 'shelling out' from your python script to issue an operating system command.

My colleague and fellow wsadmin contributor Jose Luis provided this Q&A dialog...

1) Is it possible to start the Node agent using wsadmin scripting?


You can not do any operations on a Node agent if it is down. A Node agent must be running in order to work with it.

2) Why don't methods such as 'startServer' and 'isServerRunning' work for Node agents?

The job of the node agent is to start and stop servers, and to monitor them.  Under the covers, the wsadmin startServer command asks a running node agent to start servers.  But the node agent can not start itself.  Therefore the 'startServer' command can not start a node agent.

However, method 'isServerRunning' does work on Node agents. It returns True if the node agent is running and False if it is down.

3) How do I start a Node agent that is not running?

Execute operating system commmand '' or 'startNode.bat'. This command is under /profiles//bin.

For example:

4) Hold it there!!! Question 3 describes how to start a Node agent manually and not programmatically. How can I achieve that?

You could use python libraries such as OS or Subprocess to do it. These libraries allow you to execute "external" commands within a script.

For example, the following command will list the contents of the current working directory:


5) How can I use these libraries to start a Node agent?



where PATH_TO_STARTNODE_SCRIPT is the location of your script.

In my case, is something like:


Below is a script that exercises these concepts. It checks the status of a Node agent. If it is running, the script issues a command to stop it; else it issues a command to start it.


# Import python os library to execute external commands
import os

# Import (update this to your own path)

# Node name
nodename = 'node1'

# Server name
servername = 'nodeagent'

# Counter used to keep track of while loop execution
counter = 0

while(counter < 2):
    # Check if Node agent is running
    print "\nIs Node agent running?"
    isItRunning = isServerRunning(nodename,servername)
    # If Node agent is running let's stop it
    # else let's start it
    if (isItRunning):
        print "YES\n"
        print "Request issued to stop Node agent\n"
        stopServer( nodename, servername, immediate=False )
        counter = counter + 1
        print "NO\n"
        print "Request issued to start Node agent\n"
        counter = counter + 1

Script Output:

Is Node agent running?

Request issued to stop Node agent

WASX7337I: Invoked stop for server "nodeagent" Waiting for stop completion.

Is Node agent running?

Request issued to start Node agent

ADMU0116I: Tool information is being logged in file
ADMU0128I: Starting tool with the node1 profile
ADMU3100I: Reading configuration for server: nodeagent
ADMU3200I: Server launched. Waiting for initialization status.
ADMU3000I: Server nodeagent open for e-business; process id is 24175