Example #1
0
def start(foreground):
    """
    Start the daemon
    """
    client = DaemonClient()

    click.echo('Starting the daemon... ', nl=False)

    if foreground:
        command = [
            'verdi', '-p', client.profile_name, 'daemon', '_start_circus',
            '--foreground'
        ]
    else:
        command = [
            'verdi', '-p', client.profile_name, 'daemon', '_start_circus'
        ]

    try:
        currenv = get_env_with_venv_bin()
        subprocess.check_output(command, env=currenv)
    except subprocess.CalledProcessError as exception:
        click.echo('failed: {}'.format(exception))
        sys.exit(1)

    # We add a small timeout to give the pid-file a chance to be created
    with spinner():
        time.sleep(1)
        response = client.get_status()

    print_client_response_status(response)
Example #2
0
def incr(number):
    """
    Add NUMBER [default=1] workers to the running daemon
    """
    client = DaemonClient()
    response = client.increase_workers(number)
    print_client_response_status(response)
Example #3
0
def stop(no_wait, all_profiles):
    """
    Stop the daemon
    """
    if all_profiles is True:
        profiles = [
            p for p in get_profiles_list() if not p.startswith('test_')
        ]
    else:
        profiles = [get_current_profile_name()]

    for profile_name in profiles:

        client = DaemonClient(profile_name)

        click.secho('Profile: ', fg='red', bold=True, nl=False)
        click.secho('{}'.format(profile_name), bold=True)

        if not client.is_daemon_running:
            click.echo('Daemon was not running')
            continue

        wait = not no_wait

        if wait:
            click.echo('Waiting for the daemon to shut down... ', nl=False)
        else:
            click.echo('Shutting the daemon down')

        response = client.stop_daemon(wait)

        if wait:
            print_client_response_status(response)
Example #4
0
def restart(ctx, reset, no_wait):
    """
    Restart the daemon. By default will only reset the workers of the running daemon.
    After the restart the same amount of workers will be running. If the --reset flag
    is passed, however, the full circus daemon will be stopped and restarted with just
    a single worker
    """
    client = DaemonClient()

    wait = not no_wait

    if reset:
        ctx.invoke(stop)
        ctx.invoke(start)
    else:

        if wait:
            click.echo('Restarting the daemon... ', nl=False)
        else:
            click.echo('Restarting the daemon')

        response = client.restart_daemon(wait)

        if wait:
            print_client_response_status(response)
Example #5
0
def start(foreground, number):
    """Start the daemon with NUMBER workers.

    If the NUMBER of desired workers is not specified, the default is used, which is determined by the configuration
    option `daemon.default_workers`, which if not explicitly changed defaults to 1.
    """
    from aiida.engine.daemon.client import get_daemon_client

    client = get_daemon_client()

    echo.echo('Starting the daemon... ', nl=False)

    if foreground:
        command = ['verdi', '-p', client.profile.name, 'daemon', _START_CIRCUS_COMMAND, '--foreground', str(number)]
    else:
        command = ['verdi', '-p', client.profile.name, 'daemon', _START_CIRCUS_COMMAND, str(number)]

    try:
        currenv = get_env_with_venv_bin()
        subprocess.check_output(command, env=currenv, stderr=subprocess.STDOUT)  # pylint: disable=unexpected-keyword-arg
    except subprocess.CalledProcessError as exception:
        click.secho('FAILED', fg='red', bold=True)
        echo.echo_critical(str(exception))

    # We add a small timeout to give the pid-file a chance to be created
    with spinner():
        time.sleep(1)
        response = client.get_status()

    print_client_response_status(response)
Example #6
0
def decr(number):
    """
    Remove NUMBER [default=1] workers from the running daemon
    """
    client = DaemonClient()
    response = client.decrease_workers(number)
    print_client_response_status(response)
Example #7
0
def restart(ctx, reset, no_wait):
    """Restart the daemon.

    By default will only reset the workers of the running daemon. After the restart the same amount of workers will be
    running. If the `--reset` flag is passed, however, the full daemon will be stopped and restarted with the default
    number of workers that is started when calling `verdi daemon start` manually.
    """
    from aiida.engine.daemon.client import get_daemon_client

    client = get_daemon_client()

    wait = not no_wait

    if reset:
        ctx.invoke(stop)
        # These two lines can be simplified to `ctx.invoke(start)` once issue #950 in `click` is resolved.
        # Due to that bug, the `callback` of the `number` argument the `start` command is not being called, which is
        # responsible for settting the default value, which causes `None` to be passed and that triggers an exception.
        # As a temporary workaround, we fetch the default here manually and pass that in explicitly.
        number = ctx.obj.config.get_option('daemon.default_workers', ctx.obj.profile.name)
        ctx.invoke(start, number=number)
    else:

        if wait:
            echo.echo('Restarting the daemon... ', nl=False)
        else:
            echo.echo('Restarting the daemon')

        response = client.restart_daemon(wait)

        if wait:
            print_client_response_status(response)
Example #8
0
def decr(number):
    """Remove NUMBER [default=1] workers from the running daemon."""
    from aiida.engine.daemon.client import get_daemon_client

    client = get_daemon_client()
    response = client.decrease_workers(number)
    print_client_response_status(response)
Example #9
0
def restart(ctx, reset, no_wait):
    """Restart the daemon.

    By default will only reset the workers of the running daemon. After the restart the same amount of workers will be
    running. If the `--reset` flag is passed, however, the full daemon will be stopped and restarted with the default
    number of workers that is started when calling `verdi daemon start` manually.
    """
    from aiida.engine.daemon.client import get_daemon_client

    client = get_daemon_client()

    wait = not no_wait

    if reset:
        ctx.invoke(stop)
        ctx.invoke(start)
    else:

        if wait:
            echo.echo('Restarting the daemon... ', nl=False)
        else:
            echo.echo('Restarting the daemon')

        response = client.restart_daemon(wait)

        if wait:
            print_client_response_status(response)
Example #10
0
def stop(no_wait, all_profiles):
    """Stop the daemon."""
    from aiida.engine.daemon.client import get_daemon_client

    config = get_config()

    if all_profiles is True:
        profiles = [
            profile for profile in config.profiles
            if not profile.is_test_profile
        ]
    else:
        profiles = [config.current_profile]

    for profile in profiles:

        client = get_daemon_client(profile.name)

        click.secho('Profile: ', fg='red', bold=True, nl=False)
        click.secho('{}'.format(profile.name), bold=True)

        if not client.is_daemon_running:
            echo.echo('Daemon was not running')
            continue

        delete_stale_pid_file(client)

        wait = not no_wait

        if wait:
            echo.echo('Waiting for the daemon to shut down... ', nl=False)
        else:
            echo.echo('Shutting the daemon down')

        response = client.stop_daemon(wait)

        if wait:
            if response['status'] == client.DAEMON_ERROR_NOT_RUNNING:
                click.echo('The daemon was not running.')
            else:
                print_client_response_status(response)
Example #11
0
def decr(number):
    """Remove NUMBER [default=1] workers from the running daemon.

    Returns exit code 0 if the daemon is OK, non-zero if there was an error.
    """
    from aiida.engine.daemon.client import get_daemon_client

    client = get_daemon_client()
    response = client.decrease_workers(number)
    retcode = print_client_response_status(response)
    if retcode:
        sys.exit(retcode)