Monday, May 12, 2008

Multiple Name Servers and SVEs [OSU specific]

With several developers working on the SISPI infrastructure code we are facing the problem of having multiple Pyro Name Servers and multiple SVE servers running on the same network segment. Pyro is sufficiently flexible so that it and the name server can be configured to use different IP ports. This simple shell script uses this to create distinct environments for the OSU developers - the last step - setting PYRO_NS_HOSTNAME - is only required because we don't use broadcast messages to locate the name server.

Shell script:

#!/bin/tcsh
# Usage: source startSISPI
if ($1 != "") then
set customer = $1
else
set customer = $user
endif
echo "Configuring Pyro Name Server and SVE for user " $customer
setenv PYRO_USER $customer
setenv PYRO_DNS_URI 1

# Overwrite Port numbers?
if ($2 != "" && $3 != "") then
setenv PYRO_PORT $2
setenv PYRO_NS_PORT $3
setenv PYRO_NS_BC_PORT $3
else if ($customer == "eiting") then
setenv PYRO_PORT 8000
setenv PYRO_NS_PORT 8111
setenv PYRO_NS_BC_PORT 8111
else if ($customer == "kkuehn") then
setenv PYRO_PORT 8200
setenv PYRO_NS_PORT 8333
setenv PYRO_NS_BC_PORT 8333
else if ($customer == "richman") then
setenv PYRO_PORT 8400
setenv PYRO_NS_PORT 8444
setenv PYRO_NS_BC_PORT 8444
else if ($customer == "klaus") then
setenv PYRO_PORT 7888
setenv PYRO_NS_PORT 7999
setenv PYRO_NS_BC_PORT 7999
else
echo "Using Default "
setenv PYRO_PORT 7766
setenv PYRO_NS_PORT 9090
setenv PYRO_NS_BC_PORT 9090
endif


echo "PYRO Port Numbers. PYRO_PORT = " $PYRO_PORT ", PYRO_NS_PORT = " $PYRO_NS_PORT, "PYRO_NS_BC_PORT = " $PYRO_NS_BC_PORT

# Reuse old uri file to set PYRO_NS_HOSTNAME
setenv PYRO_NS_HOSTNAME `~/.pyroNS.py`
echo "Trying to find Name Server at " $PYRO_NS_HOSTNAME


# Start Name Server and SVE if necessary
~/.pyroTest.py

# Setting new PYRO_NS_HOSTNAME
setenv PYRO_NS_HOSTNAME `~/.pyroNS.py`
echo "PYRO_NS_HOSTNAME set to " $PYRO_NS_HOSTNAME

Usage: source startSISPI <>
For example: source startSISPI klaus 5000 5200
Default values are set for the OSU developers (klaus, eiting, kkuehn, richman)

This script calls the following two python scripts to check if the name server and the SVE are already running.

.pyroTest.py:


#!/usr/bin/env python
import Pyro.core
import Pyro.naming
from Pyro.errors import NamingError
from SVE.PythonClient.SVEclient import *
import os, time

hostname = os.getenv("HOSTNAME")
user = os.getenv("PYRO_USER")
try:
ns=Pyro.naming.NameServerLocator().getNS()
print "PYRO Name Server is running. "
try:
mySVE = Pyro.core.getProxyForURI("PYRONAME://SVE")
print "SVE is running."
except:
print "Starting SVE using default installation"
os.system('xterm -T SVE_%s_%s -iconic -e "/n/cima02/python/installed/SVE/SVE/SVEserver.py" &' % (hostname, user))

except:
print "PYRO Name Server not found. Starting it now."
os.system('xterm -T PYRO_%s_%s -iconic -e "pyro-ns" &' % (hostname, user))
time.sleep(1)
print "Starting SVE using default installation"
os.system('xterm -T SVE_%s_%s -iconic -e "/n/cima02/python/installed/SVE/SVE/SVEserver.py" &' % (hostname, user))


and .pyroNS.py:

#!/usr/bin/env python
# Get location of Pyro Name Server until we fix broadcast.

try:
uri = open('Pyro_NS_URI','r').read()
host = uri.split(":")
hostname = host[1].strip("/")
print hostname
except:
print "UNDEFINED"

No comments: