def status(all_profiles): """Print the status of the current daemon or all daemons. Returns exit code 0 if all requested daemons are running, else exit code 3. """ 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] daemons_running = [] for profile in profiles: client = get_daemon_client(profile.name) delete_stale_pid_file(client) click.secho('Profile: ', fg='red', bold=True, nl=False) click.secho('{}'.format(profile.name), bold=True) result = get_daemon_status(client) echo.echo(result) daemons_running.append(client.is_daemon_running) if not all(daemons_running): sys.exit(3)
def stop(no_wait, all_profiles): """Stop the daemon. Returns exit code 0 if the daemon was shut down successfully (or was not running), non-zero if there was an error. """ 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(f'{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: retcode = print_client_response_status(response) if retcode: sys.exit(retcode)
def status(all_profiles): """Print the status of the current daemon or all daemons.""" 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) delete_stale_pid_file(client) click.secho('Profile: ', fg='red', bold=True, nl=False) click.secho('{}'.format(profile.name), bold=True) result = get_daemon_status(client) echo.echo(result)
def verdi_status(no_rmq): """Print status of AiiDA services.""" # pylint: disable=broad-except,too-many-statements from aiida.cmdline.utils.daemon import get_daemon_status, delete_stale_pid_file from aiida.common.utils import Capturing from aiida.manage.external.rmq import get_rmq_url from aiida.manage.manager import get_manager from aiida.manage.configuration.settings import AIIDA_CONFIG_FOLDER exit_code = ExitCode.SUCCESS print_status(ServiceStatus.UP, 'config dir', AIIDA_CONFIG_FOLDER) manager = get_manager() profile = manager.get_profile() if profile is None: print_status(ServiceStatus.WARNING, 'profile', 'no profile configured yet') echo.echo_info( 'Configure a profile by running `verdi quicksetup` or `verdi setup`.' ) return try: profile = manager.get_profile() print_status(ServiceStatus.UP, 'profile', 'On profile {}'.format(profile.name)) except Exception as exc: print_status(ServiceStatus.ERROR, 'profile', 'Unable to read AiiDA profile', exception=exc) sys.exit(ExitCode.CRITICAL ) # stop here - without a profile we cannot access anything # Getting the repository repo_folder = 'undefined' try: repo_folder = profile.repository_path except Exception as exc: print_status(ServiceStatus.ERROR, 'repository', 'Error with repo folder', exception=exc) exit_code = ExitCode.CRITICAL else: print_status(ServiceStatus.UP, 'repository', repo_folder) # Getting the postgres status by trying to get a database cursor database_data = [ profile.database_username, profile.database_hostname, profile.database_port ] try: with override_log_level(): # temporarily suppress noisy logging backend = manager.get_backend() backend.cursor() except Exception: print_status(ServiceStatus.DOWN, 'postgres', 'Unable to connect as {}@{}:{}'.format(*database_data)) exit_code = ExitCode.CRITICAL else: print_status(ServiceStatus.UP, 'postgres', 'Connected as {}@{}:{}'.format(*database_data)) # Getting the rmq status if not no_rmq: try: with Capturing(capture_stderr=True): with override_log_level( ): # temporarily suppress noisy logging comm = manager.create_communicator(with_orm=False) comm.stop() except Exception as exc: print_status(ServiceStatus.ERROR, 'rabbitmq', 'Unable to connect to rabbitmq', exception=exc) exit_code = ExitCode.CRITICAL else: print_status(ServiceStatus.UP, 'rabbitmq', 'Connected to {}'.format(get_rmq_url())) # Getting the daemon status try: client = manager.get_daemon_client() delete_stale_pid_file(client) daemon_status = get_daemon_status(client) daemon_status = daemon_status.split('\n')[ 0] # take only the first line if client.is_daemon_running: print_status(ServiceStatus.UP, 'daemon', daemon_status) else: print_status(ServiceStatus.WARNING, 'daemon', daemon_status) exit_code = ExitCode.SUCCESS # A daemon that is not running is not a failure except Exception as exc: print_status(ServiceStatus.ERROR, 'daemon', 'Error getting daemon status', exception=exc) exit_code = ExitCode.CRITICAL # Note: click does not forward return values to the exit code, see https://github.com/pallets/click/issues/747 sys.exit(exit_code)