#!/usr/bin/env python # vim: ts=4 et sts=4 sw=4 autoindent import Pyro import Pyro.constants import signal from optparse import OptionParser import os from sndcs.server.NameServer import NameServer from sndcs.server.EventServer import EventServer from sndcs.server.SndcsServer import SndcsServer from sndcs.server.Heartbeat import Heartbeat from sndcs_common.TrueAndFalseMixin import TrueAndFalseMixin from sndcs.Store import store from sndcs.Pinger import Pinger from sndcs.Config import config import sndcs_common from sndcs_common.Logger import logger log = logger.getLogger("sndcsd") def main(): # Check if we have correct Pyro version REQUIRED_PYRO_VERSION = '3.5' if Pyro.constants.VERSION < REQUIRED_PYRO_VERSION: log.error("Pyro version must be %s or greater. You have version %s installed.", REQUIRED_PYRO_VERSION, Pyro.constants.VERSION) return # Make sure we support threading if not Pyro.config.PYRO_MULTITHREADED: log.error("%s %s requires multithreading. Either your Python doesn't support it or it has been disabled in the config.", sndcs_common.NAME, sndcs_common.VERSION) return # Parse comand line options parser = OptionParser() parser.add_option("-c", "--config", dest="config_file", help="use FILE as additional config file", metavar="FILE") (options, args) = parser.parse_args() if options.config_file: # User specified an additional config file additional_config = config.read(os.path.expanduser(options.config_file)) log.info("Using config file(s): %s", config.getParsedFilenames()) # Set the maximum number of server connections we will allow try: max_connections = config.get("pyro", "max_connections", "200") Pyro.config.PYRO_MAXCONNECTIONS = int(max_connections) log.info("Setting max connections to %s.", max_connections) except: # Guess the user specified somrthing that can't be converted into an int log.warning("The max_connections config file value is incorrect. Reverting to default.") Pyro.config.PYRO_MAXCONNECTIONS = 200 # Find out if we should start the Pyro Name and Event Servers if TrueAndFalseMixin().true(config.get("pyro", "start_name_server", True)): hostname = config.get("pyro", "hostname", "") # If we are starting the name server set the PYRO_NS_HOSTNAME to whatever we are binding to Pyro.config.PYRO_NS_HOSTNAME = hostname ns = NameServer() ns.start() ns.waitUntilStarted() es = EventServer() es.start() es.waitUntilStarted() else: # If we aren't starting the Name Server look up the address from the config file pyro_ns_hostname = config.get("pyro", "ns_hostname", None) if pyro_ns_hostname: Pyro.config.PYRO_NS_HOSTNAME = pyro_ns_hostname # TODO: lookup from config whether to ping and if so, the frequency pinger = Pinger(store, 30) pinger.start() # Start the heartbeat heartbeat = Heartbeat() heartbeat.start() # Start the Sndcs Server... this will run a loop server = SndcsServer() server.start() if __name__ == "__main__": signal.signal(signal.SIGINT, signal.SIG_DFL) # Catch Ctrl-C main()