Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

start a server based on sys.arg in Jython

Avatar of CharanR
CharanR asked on
ProgrammingPythonJava App Servers
5 Comments1 Solution883 ViewsLast Modified:
Hi guys,

I'm trying to start or stop servers based on the command line arguments. Could some one check whether the below approach I'm following is correct or not?


from java.util import Properties
from java.io import FileInputStream
from java.io import File
import os.path

from string import split

def carryFileProperties(serverName) :
        print 'carrying properties of: ' + serverName
        #properties file to be loaded
        myProps = Properties()
        #load properties file
        myProps.load(FileInputStream(File(serverName)))
        return myProps

def serversList(fileProperties):
        print 'selecting domains from the properties'
        domains = split(fileProperties.get('domainList'), ',')
        print 'Domains: ' + str(domains)
        print 'selecting servers from the properties'
        servers = []
        properties = fileProperties.propertyNames()
        while properties.hasMoreElements():
                key = properties.nextElement()
                element = split(key, '.')
                if len(element) > 1 and element[1] == 'Targets':
                        domain = element[0]
                        dservers = split(fileProperties.get(key), ',')
                        servers.append([domain, dservers])
        print'LIST OF servers to start through nodemanager'
        for dsvrs in servers:
                print '(domain, Servers) ==>> ' + '(' + dsvrs[0] + ', ' + str(dsvrs[1]) + ')'
        return servers

def startInstance():
        nmIP = fileProperties.get('nmIP')
        nmPort = fileProperties.get('nmPort')
        domainRoot = fileProperties.get('domainRoot')
        for dsvrs in servers:
                domainDirectory = os.path.join(domainRoot, dsvrs[0])
                nmConnect(userConfigFile, userKeyFile, host, port, domainName, domainDir, nmType, verbose)
                if sys.argv[1] == 'start':
                        for server in dsvrs[1]:
                                print 'requesting the server startup ' + server
                                nmStart(server, domainDirectory)
                        nmDisconnect()
                elif sys.argv[1] == 'stop':
                        for server in dsvrs[1]:
                                print 'requesting the server stop' + server
                                nmKill(server)
                        nmDisconnect()
                else:
                        print 'Invalid command line arguments\t-->' + sys.argv[1]
fileProperties = carryFileProperties('servers.properties')
servers = serversList(fileProperties)
startInstance()
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGodFlag of United States of America imageSoftware Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answers