Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AdminControl.startServer (jython) and threads

Status
Not open for further replies.

Winstonb

Technical User
Aug 11, 2001
29
0
0
GB
Hello,

Does anyone know why this is happening ?
I've written a jython script that should be able to start non-running AppServers simultaneously on a "per node" basis.
ie, Each node starting 1 x AppServer at a time, but independantly of of each other. This works ok if I run each command one by one via the wasadmin interface, but when I however try to run this via a script using (-f), wasadmin exits and AdminControl.startServer doesn't seem to run. I've even tried appending the wsadmin.sh -lang jython -f $SCRIPT with "&" in order to run this as a Unix background task, but to no avail. I've detailed the script below.

Thanks in advance

----------------------------------------------------------
import thread
nodes = AdminConfig.list('Node')
nodes1 = nodes.split(lineSeparator)

def func(node):
node_name = AdminConfig.showAttribute(node, 'name')
servers = AdminConfig.list('Server', node)
servers1 = servers.split(lineSeparator)
for server in servers1:
serv_name = AdminConfig.showAttribute(server, 'name')
serv_type = AdminConfig.showAttribute(server, 'serverType')
run_serv = AdminConfig.getObjectName(server)
len_run = len(run_serv)
if len_run < 1:
try:
AdminControl.startServer(serv_name, node_name)
except:
print serv_name
print node_name
print "ERROR"
else:
print serv_name
print node_name
print "OK"

for node in nodes1:
thread.start_new_thread(func, (node,))
----------------------------------------------------------
 
I've never played around with threading in jython before - have you tried printing out some messages in between everything to see where the execution is happening?

Another idea might be to change the script to just start all servers on 1 node (remove for node in nodes1:, etc), and then make your loop in a shell script and fork each process.
 
Thanks for the reply. Script does work ok however when I run it through line by line, it's only when I use the wsadmin.sh -f option does it fail, despite the script being identical to the lines I've just typed in via the wsadmin.sh cmd line. Don't know if a shell script would work as I want the script to be independent of any hard coding, but It has given me something to go on

Thanks again
Winston
 
If anyones interested, I did find a way to get this to work.
KSH script invokes JY script.

==========================================================
#!/usr/bin/ksh

# Scriptname: start_server.ksh

# Notes: Starts appservers which are not already running.
# Can be run with either 0,1,2 or 3 args.
# These args are basically filters that are used to find the
# names of the required appservers.
# eg, "./start_servers.ksh STR1 STR2" will only start appservers
# containing the string STR1 and STR2 which are stopped.
# This is case sensitive.
# The script invokes the start_server.jy script which obtains the
# names of all the stopped appservers and then creates it's own
# jython scripts based on this information and the filters.
# These scripts replaces the server_start.jy script.
# The reason for this change was that server_start.jy could not
# start the appservers simultaneously on a per node basis, this script does.
# ie, it creates and invokes 1 x jython start script per node which contain
# all the appservers to eb started on that node.
# These node scripts are started simultaneously.

# Logic: 1.) Get list of all non-running appservers from jython script
# 2.) From that list filetrs out names based on args supllied (args can be 0,1.2 or 3)
# 3.) From this list, creates 1 x appserver jython start script per node
# 4.) Runs each script in background
# 5.) Runs function that checks alerts if background jython scripts have complete

# Variables
INIT=start_server_initial.out
FILT=start_server_filtered.out
RUN=start_server_run

# Clean up from last run if req'd
rm start_server_run* 2>/dev/null
rm $INIT 2>/dev/null
rm $FILT 2>/dev/null

# Get list of all non-running appservers
wsadmin.sh -lang jython -f start_server.jy | grep -v WASX7209I > $INIT

# Based upon No of arg supplied, filter out appserver names to that required
if [ $# = 0 ]
then
cat $INIT > $FILT
elif [ $# = 1 ]
then
cat $INIT | grep $1 > $FILT
elif [ $# = 2 ]
then
cat $INIT | grep $1 | grep $2 > $FILT
elif [ $# = 3 ]
then
cat $INIT | grep $1 | grep $2 | grep $3 > $FILT
else
echo "Only =< 3 Arguments can be supplied"
exit 1
fi

# Now we have all the appservers we require to start, echo this to stdout for confirmation
echo
cat $FILT
echo
echo "These are the servers which will be started:"
echo
echo "Do you want to proceed ? (y/n)"
echo
read ANS
echo
if [ $ANS != Y ]
then
if [ $ANS != y ]
then
echo "No action taken"
echo
exit 0
fi
fi

# Now we definetely know we want these appservers started
# Create 1 x jython script for each participating node
# Each script should contain names of all AppServers on that node, which require starting
echo "\tAdminControl.startServer('servername', 'nodename')" > template
cat $FILT | while read LINE
do
THIS_SERVER=`echo $LINE | awk '{print $1}'`
THIS_NODE=`echo $LINE | awk '{print $3}'`
NODE_SCRIPT=$RUN"_"$THIS_NODE.jy
echo "try:" >> $NODE_SCRIPT
cat template | sed s/servername/$THIS_SERVER/g | sed -e s/nodename/$THIS_NODE/g >> $NODE_SCRIPT
echo 'except:' >> $NODE_SCRIPT
echo "\tprint 'ERROR starting $THIS_SERVER on $THIS_NODE'" >> $NODE_SCRIPT
echo 'else:' >> $NODE_SCRIPT
echo "\tprint '$THIS_SERVER started OK on $THIS_NODE'" >> $NODE_SCRIPT
echo >> $NODE_SCRIPT
done

# Check to make sure that there are node scripts to run
ls $RUN* > /dev/null 2>&1
if [ $? != 0 ]
then
echo "No AppServers to start"
echo
exit 0
fi

# This is the body of the script now.
# For each node, run script simultaneously.
# Each script contains in series, all the AppServers to start.
# ie, although the nodes are mutually starting the AppServers in parallel,
# each node will be starting each of it's AppServers one by one.
# This allow us to start everything as quickly as possible,
# but without straining the node.
# PS. The "&" is the important bit.
for i in `ls $RUN*`
do
wsadmin.sh -lang jython -f $i | grep -v WASX7209I &
done

# Give node jython scripts time to to start
sleep 60

# Exit once all node jython scripts have finished.
# This allows us to see when all the tasks have complete.
# Otherwise, it's difficult to recognise completion as the tasks are run in the background
while
COUNT=`/usr/ucb/ps auxww | grep "/opt/ibm/WebSphere/60/AppServer/bin/wsadmin.sh -lang jython -f $RUN" | grep -v grep | wc -l`
do
sleep 10
if [ $COUNT -eq 0 ]
then
echo
echo "<<<<<< COMPLETE >>>>>>"
echo
exit 0
fi
done

# Clean up
rm start_server_run* 2>/dev/null
rm $INIT 2>/dev/null
rm $FILT 2>/dev/null

===========================================================

# Scriptname: start_server.jy

# Notes: Invoked by start_server.ksh
# Collects names of non-running appservers
# Feeds this info back to start_server.ksh
# Replaces server_start.jy

# Logic: 1.) Gets cell name
# 2.) From this gets nodenames
# 3.) Filters out non-application servers as they aren't required
# 4.) Prints out names of affected appservers, to be used by start_server.ksh



# get cell id, just for printing reasons
cell = AdminConfig.list('Cell')

# from cell id, get cell name, again just for printing
cell_name = AdminConfig.showAttribute(cell, 'name')

# get list of node id's
nodes = AdminConfig.list('Node')

# format node id's for jython
nodes1 = nodes.split(lineSeparator)

# for each node, get list of servers etc and format for jython
for node in nodes1:
node_name = AdminConfig.showAttribute(node, 'name')
servers = AdminConfig.list('Server', node)
servers1 = servers.split(lineSeparator)
# for every server get type and name
for server in servers1:
serv_name = AdminConfig.showAttribute(server, 'name')
serv_type = AdminConfig.showAttribute(server, 'serverType')
# don't want webservers, DM's or nodeagents
if serv_type == 'APPLICATION_SERVER':
# get list of servers
run_serv = AdminConfig.getObjectName(server)
len_run = len(run_serv)
# non-running servers will of zero length
if len_run < 1:
print serv_name, "on", node_name
====================================================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top