diff --git a/node_cli/configs/__init__.py b/node_cli/configs/__init__.py index ad4c2216..35d776d8 100644 --- a/node_cli/configs/__init__.py +++ b/node_cli/configs/__init__.py @@ -55,7 +55,6 @@ SGX_CERTIFICATES_DIR_NAME = 'sgx_certs' COMPOSE_PATH = os.path.join(CONTAINER_CONFIG_PATH, 'docker-compose.yml') -PASSIVE_COMPOSE_PATH = os.path.join(CONTAINER_CONFIG_PATH, 'docker-compose-passive.yml') FAIR_COMPOSE_PATH = os.path.join(CONTAINER_CONFIG_PATH, 'docker-compose-fair.yml') STATIC_PARAMS_FILEPATH = os.path.join(CONTAINER_CONFIG_PATH, 'static_params.yaml') FAIR_STATIC_PARAMS_FILEPATH = os.path.join(CONTAINER_CONFIG_PATH, 'fair_static_params.yaml') diff --git a/node_cli/core/host.py b/node_cli/core/host.py index 8c684455..da4be640 100644 --- a/node_cli/core/host.py +++ b/node_cli/core/host.py @@ -19,7 +19,7 @@ import logging import os -from shutil import copyfile +from shutil import copyfile, chown from urllib.parse import urlparse from node_cli.core.resources import update_resource_allocation @@ -94,6 +94,7 @@ def prepare_host(env_filepath: str, env_type: str, allocation: bool = False) -> try: logger.info('Preparing host started') make_dirs() + chown(REDIS_DATA_PATH, user=999, group=1000) save_env_params(env_filepath) if allocation: diff --git a/node_cli/core/node.py b/node_cli/core/node.py index 725deee3..43df3c3a 100644 --- a/node_cli/core/node.py +++ b/node_cli/core/node.py @@ -94,7 +94,6 @@ logger = logging.getLogger(__name__) TEXTS = safe_load_texts() -BASE_CONTAINERS_AMOUNT = 5 BLUEPRINT_NAME = 'node' diff --git a/node_cli/operations/__init__.py b/node_cli/operations/__init__.py index f2ac1a94..7a72b442 100644 --- a/node_cli/operations/__init__.py +++ b/node_cli/operations/__init__.py @@ -21,8 +21,6 @@ update as update_op, init as init_op, init_passive as init_passive_op, - init_fair_boot as init_fair_boot_op, - update_fair_boot as update_fair_boot_op, update_passive as update_passive_op, turn_off as turn_off_op, turn_on as turn_on_op, @@ -31,7 +29,9 @@ configure_nftables, ) from node_cli.operations.fair import ( # noqa + init_fair_boot as init_fair_boot_op, init as init_fair_op, + update_fair_boot as update_fair_boot_op, update as update_fair_op, FairUpdateType, restore as restore_fair_op, diff --git a/node_cli/operations/base.py b/node_cli/operations/base.py index 94139959..1a64d585 100644 --- a/node_cli/operations/base.py +++ b/node_cli/operations/base.py @@ -159,48 +159,6 @@ def update(env_filepath: str, env: Dict, node_mode: NodeMode) -> bool: return True -@checked_host -def update_fair_boot(env_filepath: str, env: Dict, node_mode: NodeMode = NodeMode.ACTIVE) -> bool: - compose_rm(node_type=NodeType.FAIR, node_mode=node_mode, env=env) - remove_dynamic_containers() - cleanup_volume_artifacts(env['BLOCK_DEVICE']) - - sync_skale_node() - ensure_btrfs_kernel_module_autoloaded() - - if env.get('SKIP_DOCKER_CONFIG') != 'True': - configure_docker() - - enable_monitoring = str_to_bool(env.get('MONITORING_CONTAINERS', 'False')) - configure_nftables(enable_monitoring=enable_monitoring) - - generate_nginx_config() - prepare_block_device(env['BLOCK_DEVICE'], force=env['ENFORCE_BTRFS'] == 'True') - - prepare_host(env_filepath, env['ENV_TYPE']) - - meta_manager = FairCliMetaManager() - current_stream = meta_manager.get_meta_info().config_stream - skip_cleanup = env.get('SKIP_DOCKER_CLEANUP') == 'True' - if not skip_cleanup and current_stream != env['NODE_VERSION']: - logger.info( - 'Stream version was changed from %s to %s', - current_stream, - env['NODE_VERSION'], - ) - docker_cleanup() - - meta_manager.update_meta( - VERSION, - env['NODE_VERSION'], - distro.id(), - distro.version(), - ) - update_images(env=env, node_type=NodeType.FAIR, node_mode=NodeMode.ACTIVE) - compose_up(env=env, node_type=NodeType.FAIR, node_mode=NodeMode.ACTIVE, is_fair_boot=True) - return True - - @checked_host def init(env_filepath: str, env: dict, node_mode: NodeMode) -> None: sync_skale_node() @@ -236,39 +194,6 @@ def init(env_filepath: str, env: dict, node_mode: NodeMode) -> None: compose_up(env=env, node_type=NodeType.SKALE, node_mode=node_mode) -@checked_host -def init_fair_boot(env_filepath: str, env: dict, node_mode: NodeMode = NodeMode.ACTIVE) -> None: - sync_skale_node() - cleanup_volume_artifacts(env['BLOCK_DEVICE']) - - ensure_btrfs_kernel_module_autoloaded() - if env.get('SKIP_DOCKER_CONFIG') != 'True': - configure_docker() - - enable_monitoring = str_to_bool(env.get('MONITORING_CONTAINERS', 'False')) - configure_nftables(enable_monitoring=enable_monitoring) - - prepare_host(env_filepath, env_type=env['ENV_TYPE']) - link_env_file() - mark_active_node() - - configure_filebeat() - configure_flask() - generate_nginx_config() - prepare_block_device(env['BLOCK_DEVICE'], force=env['ENFORCE_BTRFS'] == 'True') - - meta_manager = FairCliMetaManager() - meta_manager.update_meta( - VERSION, - env['NODE_VERSION'], - distro.id(), - distro.version(), - ) - update_images(env=env, node_type=NodeType.FAIR, node_mode=NodeMode.ACTIVE) - - compose_up(env=env, node_type=NodeType.FAIR, node_mode=NodeMode.ACTIVE, is_fair_boot=True) - - def init_passive( env_filepath: str, env: dict, @@ -291,6 +216,16 @@ def init_passive( env_filepath, env_type=env['ENV_TYPE'], ) + failed_checks = run_host_checks( + env['BLOCK_DEVICE'], + TYPE, + NodeMode.PASSIVE, + env['ENV_TYPE'], + CONTAINER_CONFIG_PATH, + check_type=CheckType.PREINSTALL + ) + if failed_checks: + print_failed_requirements_checks(failed_checks) set_passive_node_options(archive=archive, indexer=indexer) @@ -339,6 +274,17 @@ def update_passive(env_filepath: str, env: Dict) -> bool: prepare_host(env_filepath, env['ENV_TYPE'], allocation=True) + failed_checks = run_host_checks( + env['BLOCK_DEVICE'], + TYPE, + NodeMode.PASSIVE, + env['ENV_TYPE'], + CONTAINER_CONFIG_PATH, + check_type=CheckType.PREINSTALL + ) + if failed_checks: + print_failed_requirements_checks(failed_checks) + meta_manager = CliMetaManager() meta_manager.update_meta( VERSION, diff --git a/node_cli/operations/fair.py b/node_cli/operations/fair.py index ca7baef5..f1e62305 100644 --- a/node_cli/operations/fair.py +++ b/node_cli/operations/fair.py @@ -38,7 +38,7 @@ from node_cli.core.nginx import generate_nginx_config from node_cli.core.schains import cleanup_no_lvm_datadir from node_cli.core.static_config import get_fair_chain_name -from node_cli.core.node_options import set_passive_node_options, upsert_node_mode +from node_cli.core.node_options import mark_active_node, set_passive_node_options, upsert_node_mode from node_cli.fair.record.chain_record import ( get_fair_chain_record, migrate_chain_record, @@ -80,6 +80,39 @@ class FairUpdateType(Enum): FROM_BOOT = 'from_boot' +@checked_host +def init_fair_boot(env_filepath: str, env: dict) -> None: + sync_skale_node() + cleanup_volume_artifacts(env['BLOCK_DEVICE']) + + ensure_btrfs_kernel_module_autoloaded() + if env.get('SKIP_DOCKER_CONFIG') != 'True': + configure_docker() + + enable_monitoring = str_to_bool(env.get('MONITORING_CONTAINERS', 'False')) + configure_nftables(enable_monitoring=enable_monitoring) + + prepare_host(env_filepath, env_type=env['ENV_TYPE']) + link_env_file() + mark_active_node() + + configure_filebeat() + configure_flask() + generate_nginx_config() + prepare_block_device(env['BLOCK_DEVICE'], force=env['ENFORCE_BTRFS'] == 'True') + + meta_manager = FairCliMetaManager() + meta_manager.update_meta( + VERSION, + env['NODE_VERSION'], + distro.id(), + distro.version(), + ) + update_images(env=env, node_type=NodeType.FAIR, node_mode=NodeMode.ACTIVE) + + compose_up(env=env, node_type=NodeType.FAIR, node_mode=NodeMode.ACTIVE, is_fair_boot=True) + + @checked_host def init( env_filepath: str, diff --git a/node_cli/utils/docker_utils.py b/node_cli/utils/docker_utils.py index 9aa95f4f..098a61e7 100644 --- a/node_cli/utils/docker_utils.py +++ b/node_cli/utils/docker_utils.py @@ -35,7 +35,6 @@ NGINX_CONTAINER_NAME, REMOVED_CONTAINERS_FOLDER_PATH, SGX_CERTIFICATES_DIR_NAME, - PASSIVE_COMPOSE_PATH, ) from node_cli.core.node_options import active_fair, active_skale, passive_fair, passive_skale from node_cli.utils.helper import run_cmd, str_to_bool @@ -77,7 +76,13 @@ 'boot-api': 'sk_boot_api', } -BASE_PASSIVE_COMPOSE_SERVICES = {'admin': 'sk_admin', 'nginx': 'sk_nginx', **REDIS_SERVICE_DICT} +BASE_PASSIVE_COMPOSE_SERVICES = { + 'admin': 'sk_admin', + 'nginx': 'sk_nginx', + 'api': 'sk_api', + 'watchdog': 'sk_watchdog', + **REDIS_SERVICE_DICT, +} BASE_PASSIVE_FAIR_COMPOSE_SERVICES = { 'admin': 'sk_admin', @@ -292,9 +297,7 @@ def compose_build(env: dict, node_type: NodeType, node_mode: NodeMode): def get_compose_path(node_type: NodeType, node_mode: NodeMode) -> str: - if passive_skale(node_type, node_mode): - return PASSIVE_COMPOSE_PATH - elif active_fair(node_type, node_mode) or passive_fair(node_type, node_mode): + if node_type == NodeType.FAIR: return FAIR_COMPOSE_PATH return COMPOSE_PATH