Esempio n. 1
0
def stop():
    """Stop the ModelCI backend server."""
    # get backend process pid
    pid = check_process_running(SERVER_PORT)
    if pid:
        os.killpg(os.getpgid(pid), signal.SIGTERM)
        logger.info(f'The Uvicorn server with pid={pid} stopped.')
    else:
        logger.warning(f'No process is listening on {SERVER_PORT}')
Esempio n. 2
0
def start():
    """Run a ModelCI backend server with Uvicorn."""
    # check if the process is running
    pid = check_process_running(SERVER_PORT)
    if not pid:
        args = [sys.executable, '-m', 'uvicorn', 'modelci.app.main:app', '--port',
                str(SERVER_PORT), '--host', '0.0.0.0']
        if SERVER_HOST != 'localhost':
            args += ['--host', SERVER_HOST]
        backend_process = subprocess.Popen(args, preexec_fn=os.setsid)
        pid = backend_process.pid
        logger.info(f'Uvicorn server listening on {SERVER_PORT}')
    else:
        logger.warning(f'Unable to started server. A process with pid={pid} is already listening on {SERVER_PORT}. '
                       'Please check if your Uvicorn server has started.')
Esempio n. 3
0
def start():
    """Run a ModelCI backend server with Uvicorn."""
    from modelci.app.main import _app_start_detach

    # check if the process is running
    pid = check_process_running(app_settings.server_port)
    if not pid:
        backend_process = mp.Process(target=_app_start_detach,
                                     args=(default_log_file, ))
        backend_process.start()

        logger.info(
            f'Uvicorn server listening on {app_settings.server_url}, check full log at {default_log_file}'
        )
    else:
        logger.warning(
            f'Unable to started server. A process with pid={pid} is already listening on '
            f'port {app_settings.server_port}. '
            'Please check if your Uvicorn server has started.')
Esempio n. 4
0
def start():
    """Run a ModelCI backend server with Uvicorn."""
    # check if the process is running
    pid = check_process_running(app_settings.server_port)
    if not pid:
        args = [
            sys.executable, f'{Path(__file__).absolute().parent / "main.py"}',
            '&>', f'{Path.home()}/tmp/test.log', '&'
        ]
        backend_process = subprocess.Popen(args,
                                           preexec_fn=os.setsid,
                                           close_fds=True)
        logger.info(
            f'Uvicorn server [PID {backend_process.pid}] listening on {app_settings.server_url}'
        )
    else:
        logger.warning(
            f'Unable to started server. A process with pid={pid} is already listening on '
            f'port {app_settings.server_port}. '
            'Please check if your Uvicorn server has started.')