Example #1
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
Example #2
0
    else:
        stdin = None
    for (service, path) in ordered:
        args = [sys.executable, path]
        args.extend(sys.argv[1:])
        try:
            process = subprocess.Popen(args, shell=False, stdin=stdin)
            print "start: service %s is pid %d" % (service, process.pid)
            # write the private key via stdout if necessary
            if private_key:
                process.stdin.write(private_key + "\n")
                # give the service's initialization code a chance to complete
            time.sleep(delay)
            # check that the process is still running before continuing
            if process.poll() is not None:
                print "start: Service did not start successfully"
                break
            else:
                pidlist.append(str(process.pid))
        except OSError:
            print 'start: Unable to execute "%s"' % command

            # Save the list of process IDs we have just started
    if len(pidlist) > 0:
        pidlist.reverse()
        pidfile = config.getfilename("start", "pidfile") or "pidlist"
        pidfile = file(pidfile, "w")
        print >> pidfile, " ".join(pidlist)
        pidfile.close()
        print "start: Services can be killed with: kill -INT `cat %s`" % pidfile.name