Exemplo n.º 1
0
def datajoint_server():
    print('Starting datajoint server')

    ss_pull = hi.ShellScript("""
    #!/bin/bash
    set -ex

    exec docker pull datajoint/mysql
    """)
    ss_pull.start()
    ss_pull.wait()

    process = multiprocessing.Process(target=run_service_datajoint_server,
                                      kwargs=dict())
    process.start()

    try:
        _wait_for_datajoint_server_to_start()
    except Exception:
        _kill_datajoint_server()
        raise

    yield process

    process.terminate()
    _kill_datajoint_server()
Exemplo n.º 2
0
def _kill_datajoint_server():
    print('Terminating datajoint server')

    ss2 = hi.ShellScript(f"""
    #!/bin/bash

    set -ex

    docker kill datajoint-server-fixture || true
    docker rm datajoint-server-fixture
    """)
    ss2.start()
    ss2.wait()
Exemplo n.º 3
0
def run_service_datajoint_server():
    # The following cleanup is needed because we terminate this compute resource process
    # See: https://pytest-cov.readthedocs.io/en/latest/subprocess-support.html
    from pytest_cov.embed import cleanup_on_sigterm
    cleanup_on_sigterm()

    os.environ['RUNNING_PYTEST'] = 'TRUE'

    with hi.ConsoleCapture(label='[datajoint-server]'):
        ss = hi.ShellScript(f"""
        #!/bin/bash
        set -ex

        docker kill datajoint-server-fixture > /dev/null 2>&1 || true
        docker rm datajoint-server-fixture > /dev/null 2>&1 || true
        exec docker run --name datajoint-server-fixture -e MYSQL_ROOT_PASSWORD=tutorial -p {DATAJOINT_SERVER_PORT}:3306 datajoint/mysql
        """, redirect_output_to_stdout=True)
        ss.start()
        ss.wait()
Exemplo n.º 4
0
def start_app(*, api_websocket: bool, api_http: bool, client_dev: bool, client_prod: bool):
    thisdir = os.path.dirname(os.path.realpath(__file__))

    scripts: List[hi.ShellScript] = []

    if api_websocket:
        s = hi.ShellScript(f'''
        #!/bin/bash

        export LABBOX_EXTENSIONS_DIR={thisdir}/extensions
        export LABBOX_WEBSOCKET_PORT=15308

        exec labbox_start_api_websocket
        ''')
        scripts.append(s)
    
    if api_http:
        s = hi.ShellScript(f'''
        #!/bin/bash

        export LABBOX_HTTP_PORT=15309

        exec labbox_start_api_http
        ''')
        scripts.append(s)
    
    if client_dev:
        s = hi.ShellScript(f'''
        #!/bin/bash

        cd {thisdir}/../..
        export PORT=15351
        exec yarn start
        ''')
        scripts.append(s)
    
    if client_prod:
        s = hi.ShellScript(f'''
        #!/bin/bash

        cd {thisdir}
        exec serve -l 15351 build
        ''')
        scripts.append(s)
    
    if len(scripts) == 0:
        return

    for s in scripts:
        s.start()

    def stop_all():
        for s in scripts:
            if s.isRunning():
                s.stop()
    
    signal.signal(signal.SIGINT, stop_all)

    while True:
        all_running = True
        for s in scripts:
            if not s.isRunning():
                all_running = False
        if not all_running:
            stop_all()
            return
        for s in scripts:
            s.wait(0.1)