示例#1
0
def initialize(name):
	"""
	Initializes the proxy environment before a new proxy is declared.
	
	The name provided must be a valid and unique network service name.
	See tops.core.network.naming for details.
	"""
	# check the name format (does not check uniqueness)
	from tops.core.network.naming import ResourceName
	name = ResourceName(name)
	# remember our service name
	Proxy.service_name = name
	# initialize our run-time configuration
	config.initialize()
	# initialize the logger
	logging.initialize(name)
	# initialize the archiver
	archiving.initialize(name)
示例#2
0
def initialize():
	"""
	Starts the server main loop.
	"""
	from twisted.internet import reactor
	from twisted.python.logfile import LogFile
	import sys
	import os,os.path
	
	# load our run-time configuration
	import tops.core.utility.config as config
	verbose = config.initialize()

	# use file-based logging for ourself (print statements are automatically redirected)
	logpath = config.getfilename('logger','logfile')
	if not logpath or logpath == 'stdout':
		log.startLogging(sys.stdout)
	else:
		(logpath,logfile) = os.path.split(logpath)
		log.startLogging(LogFile(logfile,logpath))

	print 'Executing',__file__,'as PID',os.getpid()
	try:
		# create a record buffer to connect our feed watchers to our clients
		feed = FeedBuffer()

		# initialize socket servers to listen for local and network log message producers
		factory = Factory()
		factory.protocol = LogServer
		factory.feed = feed
		reactor.listenTCP(config.getint('logger','tcp_port'),factory)
		reactor.listenUNIX(config.getfilename('logger','unix_addr'),factory)

		# initialize an HTTP server to handle feed watcher requests via http
		prepareWebServer(
			portNumber = config.getint('logger','http_port'),
			handlers = {"feed":FeedUpdate()},
			properties = {"feed":feed},
			filterLogs = True
		)

		# fire up the reactor
		print 'Waiting for clients...'
		reactor.run()
		
	except Exception:
		print 'Reactor startup failed'
		# How do I release my unix socket cleanly here?
		#reactor.stop()
		raise
示例#3
0
文件: test.py 项目: TheProjecter/tops
is running and correctly handles the messages.
"""

## @package tops.core.network.logging.test
# Tests the distributed logging infrastructure
#
# @author David Kirkby, [email protected]
# @date Created 6-Aug-2008
#
# This project is hosted at sdss3.org and tops.googlecode.com

if __name__ == "__main__":

	# load our run-time configuration
	import tops.core.utility.config as config
	verbose = config.initialize()

	import tops.core.network.logging.producer as logging
	
	logging.initialize('log.client.test')

	from time import sleep

	log = logging.getLogger('proxy.tcc')
	log.setLevel(logging.DEBUG)

	extra = { 'SaveContext':True }

	for (level) in (logging.DEBUG,logging.INFO,logging.WARNING,logging.ERROR,logging.CRITICAL):
		log.log(level,"This message has level %s",logging.getLevelName(level),extra=extra)
		sleep(0.5)
示例#4
0
    except KeyError:
        print "start: Setting PYTHONPATH = %s" % tops_path
        sys.path.insert(1, tops_path)
        os.environ["PYTHONPATH"] = tops_path
    try:
        from tops.core.utility import config, secret
    except ImportError:
        if env_path:
            print "start: Import failed with PYTHONPATH = \n", env_path
            sys.exit(1)
        else:
            print "start: Unable to bootstrap module path. Please check your installation."
            sys.exit(2)

            # load our run-time configuration
    verbose = config.initialize("start")

    # prompt for the decryption passphrase used for private data if requested
    private_key = None
    if config.getboolean("start", "get_passphrase"):
        passphrase = getpass.getpass("Enter the pass phrase: ")
        engine = secret.SecretEngine(passphrase=passphrase)
        private_key = engine.key
        del engine

        # collect a list of services to start and perform some checks
    services = {}
    for section in config.theParser.sections():
        service_name = config.get(section, "service")
        launch_order = config.getint(section, "launch_order")
        if service_name and launch_order and config.getboolean(section, "enable"):