예제 #1
0
 def test_ping_fail(self, settings, AsyncHTTPClient):
     self.standard_setup(settings, AsyncHTTPClient)
     homestead.ping()
     self.mock_httpclient.fetch.assert_called_once_with("http://homestead/ping", ANY)
     mock_response = MagicMock()
     mock_response.body = "Failure"
     self.mock_httpclient.fetch.call_args[0][1](mock_response)
예제 #2
0
파일: homestead.py 프로젝트: biddyweb/ellis
 def test_ping_http(self, settings, AsyncHTTPClient):
     self.standard_setup(settings, AsyncHTTPClient)
     mock_response = MagicMock()
     mock_response.body = "OK"
     self.mock_httpclient.fetch.return_value = mock_response
     homestead.ping()
     self.mock_httpclient.fetch.assert_called_once_with("http://homestead/ping", ANY)
예제 #3
0
파일: homestead.py 프로젝트: vitosans/ellis
 def test_ping_fail(self, settings, AsyncHTTPClient):
     self.standard_setup(settings, AsyncHTTPClient)
     homestead.ping()
     self.mock_httpclient.fetch.assert_called_once_with(
         "http://homestead/ping", ANY)
     mock_response = MagicMock()
     mock_response.body = "Failure"
     self.mock_httpclient.fetch.call_args[0][1](mock_response)
예제 #4
0
파일: utils.py 프로젝트: tracyyjy/ellis
def check_connection():
    callback = Callback()

    homestead.ping(callback)
    response = callback.wait()[0]
    if response.body != "OK":
        _log.error("Can't contact homestead-prov at http://%s", settings.HOMESTEAD_URL)
        return False
    return True
예제 #5
0
파일: utils.py 프로젝트: Metaswitch/ellis
def check_connection():
    callback = Callback()

    homestead.ping(callback)
    response = callback.wait()[0]
    if response.body != "OK":
        _log.error("Can't contact homestead-prov at http://%s", settings.HOMESTEAD_URL)
        return False
    return True
예제 #6
0
파일: main.py 프로젝트: AiprNick/ellis
def standalone():
    """
    Initializes Tornado and our application.  Forks worker processes to handle
    requests.  Does not return until all child processes exit normally.
    """

    # Parse arguments
    parser = argparse.ArgumentParser(description="Ellis web server")
    parser.add_argument("--background", action="store_true", help="Detach and run server in background")
    args = parser.parse_args()

    # We don't initialize logging until we fork because we want each child to
    # have its own logging and it's awkward to reconfigure logging that is
    # defined by the parent.
    application = create_application()

    if args.background:
        # Get a new logfile, rotating the old one if present.
        err_log_name = os.path.join(settings.LOGS_DIR, settings.LOG_FILE_PREFIX + "-err.log")
        try:
            os.rename(err_log_name, err_log_name + ".old")
        except OSError:
            pass
        # Fork into background.
        utils.daemonize(err_log_name)

    utils.install_sigusr1_handler(settings.LOG_FILE_PREFIX)

    # Drop a pidfile.
    pid = os.getpid()
    with open(settings.PID_FILE, "w") as pidfile:
        pidfile.write(str(pid) + "\n")

    # Fork off a child process per core.  In the parent process, the
    # fork_processes call blocks until the children exit.
    num_processes = settings.TORNADO_PROCESSES_PER_CORE * tornado.process.cpu_count()
    task_id = tornado.process.fork_processes(num_processes)
    if task_id is not None:
        logging_config.configure_logging(settings.LOG_LEVEL, settings.LOGS_DIR, settings.LOG_FILE_PREFIX, task_id)
        # We're a child process, start up.
        _log.info("Process %s starting up", task_id)
        connection.init_connection()

        http_server = httpserver.HTTPServer(application)
        unix_socket = bind_unix_socket(settings.HTTP_UNIX + "-" + str(task_id),
                                       0666);
        http_server.add_socket(unix_socket)

        homestead.ping()
        background.start_background_worker_io_loop()
        io_loop = tornado.ioloop.IOLoop.instance()
        io_loop.start()
    else:
        # This shouldn't happen since the children should run their IOLoops
        # forever.
        _log.critical("Children all exited")
예제 #7
0
파일: main.py 프로젝트: rkday/ellis
def standalone():
    """
    Initializes Tornado and our application.  Forks worker processes to handle
    requests.  Does not return until all child processes exit normally.
    """

    # Parse arguments
    parser = argparse.ArgumentParser(description="Ellis web server")
    parser.add_argument("--background", action="store_true", help="Detach and run server in background")
    args = parser.parse_args()

    # We don't initialize logging until we fork because we want each child to
    # have its own logging and it's awkward to reconfigure logging that is
    # defined by the parent.
    application = create_application()
    listening_on_some_port = False

    http_sockets = None
    https_sockets = None

    if settings.ALLOW_HTTP:
        http_sockets = bind_sockets(settings.HTTP_PORT, address=settings.LOCAL_IP)
        listening_on_some_port = True

    if (os.path.exists(settings.TLS_CERTIFICATE) and
        os.path.exists(settings.TLS_PRIVATE_KEY)):
        https_sockets = bind_sockets(settings.HTTPS_PORT, address=settings.LOCAL_IP)
        listening_on_some_port = True

    if not listening_on_some_port:
        # We usually don't configure logging until after we fork but since
        # we're about to crash...
        logging_config.configure_logging("parent")
        _log.critical("Failed to listen on any ports.")
        raise Exception("Failed to listen on any ports")

    if args.background:
        # Get a new logfile, rotating the old one if present.
        err_log_name = os.path.join(settings.LOGS_DIR, settings.LOG_FILE_PREFIX + "-err.log")
        try:
            os.rename(err_log_name, err_log_name + ".old")
        except OSError:
            pass
        # Fork into background.
        utils.daemonize(err_log_name)

    utils.install_sigusr1_handler(settings.LOG_FILE_PREFIX)

    # Drop a pidfile.
    pid = os.getpid()
    with open(settings.PID_FILE, "w") as pidfile:
        pidfile.write(str(pid) + "\n")

    # Fork off a child process per core.  In the parent process, the
    # fork_processes call blocks until the children exit.
    num_processes = settings.TORNADO_PROCESSES_PER_CORE * tornado.process.cpu_count()
    task_id = tornado.process.fork_processes(num_processes)
    if task_id is not None:
        logging_config.configure_logging(task_id)
        # We're a child process, start up.
        _log.info("Process %s starting up", task_id)
        connection.init_connection()
        if http_sockets:
            _log.info("Going to listen for HTTP on port %s", settings.HTTP_PORT)
            http_server = httpserver.HTTPServer(application)
            http_server.add_sockets(http_sockets)
        else:
            _log.info("Not starting HTTP, set ALLOW_HTTP in local_settings.py to enable HTTP.")
        if https_sockets:
            _log.info("Going to listen for HTTPS on port %s", settings.HTTPS_PORT)
            https_server = httpserver.HTTPServer(application,
                       ssl_options={
                           "certfile": settings.TLS_CERTIFICATE,
                           "keyfile": settings.TLS_PRIVATE_KEY,
                       })
            https_server.add_sockets(https_sockets)
        else:
            _log.critical("Not starting HTTPS")
        homestead.ping()
        background.start_background_worker_io_loop()
        io_loop = tornado.ioloop.IOLoop.instance()
        io_loop.start()
    else:
        # This shouldn't happen since the children should run their IOLoops
        # forever.
        _log.critical("Children all exited")
예제 #8
0
def standalone():
    """
    Initializes Tornado and our application.  Forks worker processes to handle
    requests.  Does not return until all child processes exit normally.
    """

    # Parse arguments
    parser = argparse.ArgumentParser(description="Ellis web server")
    parser.add_argument("--background",
                        action="store_true",
                        help="Detach and run server in background")
    parser.add_argument("--log-level", default=2, type=int)
    args = parser.parse_args()

    prctl.prctl(prctl.NAME, "ellis")

    # We don't initialize logging until we fork because we want each child to
    # have its own logging and it's awkward to reconfigure logging that is
    # defined by the parent.
    application = create_application()

    if args.background:
        # Get a new logfile, rotating the old one if present.
        err_log_name = os.path.join(settings.LOGS_DIR,
                                    settings.LOG_FILE_PREFIX + "-err.log")
        try:
            os.rename(err_log_name, err_log_name + ".old")
        except OSError:
            pass
        # Fork into background.
        utils.daemonize(err_log_name)

    utils.install_sigusr1_handler(settings.LOG_FILE_PREFIX)

    # Drop a pidfile. We must keep a reference to the file object here, as this keeps
    # the file locked and provides extra protection against two processes running at
    # once.
    pidfile_lock = None
    try:
        pidfile_lock = utils.lock_and_write_pid_file(settings.PID_FILE)  # noqa
    except IOError:
        # We failed to take the lock - another process is already running
        exit(1)

    # Only run one process, not one per core - we don't need the performance
    # and this keeps everything in one log file
    prctl.prctl(prctl.NAME, "ellis")
    logging_config.configure_logging(
        utils.map_clearwater_log_level(args.log_level), settings.LOGS_DIR,
        settings.LOG_FILE_PREFIX)
    _log.info("Ellis process starting up")
    connection.init_connection()

    http_server = httpserver.HTTPServer(application)
    unix_socket = bind_unix_socket(settings.HTTP_UNIX, 0666)
    http_server.add_socket(unix_socket)

    homestead.ping()
    background.start_background_worker_io_loop()
    io_loop = tornado.ioloop.IOLoop.instance()
    io_loop.start()