def start_launchpad(argv=list(sys.argv), setup=None): # We really want to replace this with a generic startup harness. # However, this should last us until this is developed services, argv = split_out_runlaunchpad_arguments(argv[1:]) argv = process_config_arguments(argv) services = get_services_to_run(services) # Create the ZCML override file based on the instance. config.generate_overrides() # Many things rely on a directory called 'logs' existing in the current # working directory. ensure_directory_exists('logs') if setup is not None: # This is the setup from start_testapp, above. setup() try: with nested(*services): # Store our process id somewhere make_pidfile('launchpad') if config.launchpad.launch: main(argv) else: # We just need the foreground process to sit around forever # waiting for the signal to shut everything down. Normally, # Zope itself would be this master process, but we're not # starting that up, so we need to do something else. try: signal.pause() except KeyboardInterrupt: pass except Exception as e: print >> sys.stderr, "stopping services on exception %r" % e for service in services: print >> sys.stderr, service, "fixture details:" # There may be no details on some services if they haven't been # initialized yet. if getattr(service, '_details', None) is None: print >> sys.stderr, "(not ready yet?)" continue details_str = _details_to_str(service.getDetails()) if details_str: print >> sys.stderr, details_str else: print >> sys.stderr, "(no details present)" raise
def main(): """Run the HTTP server.""" # Redirect our service output to a log file. global log ensure_directory_exists(os.path.dirname(config.google_test_service.log)) filelog = logging.FileHandler(config.google_test_service.log) log.addHandler(filelog) log.setLevel(logging.DEBUG) # To support service shutdown we need to create a PID file that is # understood by the Launchpad services framework. global service_name make_pidfile(service_name) host, port = get_service_endpoint() server = HTTPServer((host, port), GoogleRequestHandler) log.info("Starting HTTP Google webservice server on port %s", port) server.serve_forever()