\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/cloudlinux/venv/lib/python3.11/site-packages/clwizard/modules/

Viewing File: __init__.py

# coding=utf-8
#
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2021 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENCE.TXT
#
import os
from collections import OrderedDict

from typing import Dict  # NOQA

from clwizard.config import NoSuchModule, acquire_config_access
from clwizard.constants import ModuleStatus, MAIN_LOG_PATH

from clwizard.exceptions import InstallationFailedException, UserInterventionNeededError
from clwizard.utils import setup_logger
from .base import WizardInstaller  # NOQA
from .cagefs import CagefsInstaller
from .governor import GovernorInstaller
from .nodejs import NodejsInstaller
from .php import PhpInstaller
from .python import PythonInstaller
from .ruby import RubyInstaller
from .lsapi import LsapiInstaller


# order of modules is important
# add new modules in correct order
ALL_MODULES = OrderedDict([
    ('cagefs', CagefsInstaller),
    ('mysql_governor', GovernorInstaller),
    ('nodejs', NodejsInstaller),
    ('php', PhpInstaller),
    ('python', PythonInstaller),
    ('ruby', RubyInstaller),
    ('mod_lsapi', LsapiInstaller),
    # add other modules here
])

log = setup_logger('wizard.runner', MAIN_LOG_PATH)


def get_supported_modules():
    """Get list of supported modules on current control panel"""
    return {
        name: module for name, module in ALL_MODULES.items()
        if module.is_supported_by_control_panel()
    }


def run_installation():
    """Install modules according to settings in status file"""
    log.info('~' * 60)
    log.info('> Start new modules installation in process with pid %s', os.getpid())
    for name, installer_class in get_supported_modules().items():
        installer = installer_class()
        # we should re-read config each time in order to be able to 'cancel'
        with acquire_config_access() as config:
            try:
                options = config.get_module_options(module_name=name)
                state = config.get_module_status(module_name=name)
            except NoSuchModule:
                log.info(
                    "Module %s is not set for installation, skip it", name)
                continue

            # 'resume case' when we should skip already installed modules
            if state == ModuleStatus.INSTALLED:
                log.info(
                    "Module %s is already installed, skip it", name)
                continue
            if state == ModuleStatus.CANCELLED:
                log.info(
                    "Module %s has been cancelled, skip it", name)
                continue
            if state == ModuleStatus.AUTO_SKIPPED:
                log.info(
                    "Module %s requires a manual installation. "
                    "Skipping it and continuing installation", name)
                continue
            config.set_module_status(
                module_name=name, new_state=ModuleStatus.INSTALLING)
        _install_module(name, installer, options=options)
    log.info('> Process with pid %s successfully finished work', os.getpid())
    log.info('-' * 60)


def _install_module(module, installer, options):
    # type: (str, WizardInstaller, Dict) -> None
    log.info("Installing module: %s", module)
    try:
        installer.run_installation(options)
    except InstallationFailedException:
        _write_module_state_atomic(
            module_name=module, new_state=ModuleStatus.FAILED)
        log.error(
            "Installation failed for module %s", module,
            extra={
                'fingerprint': ['{{ default }}', module],  # Used to group and break up events
                # Log only the option KEYS, never the raw option values, to keep
                # request payloads out of the log file and Sentry telemetry.
                'data': {'option_keys': sorted(options)}})  # Additional data for sentry event
        raise
    except UserInterventionNeededError:
        _write_module_state_atomic(
            module_name=module, new_state=ModuleStatus.AUTO_SKIPPED)
        log.warning("Automatic installation was skipped for module %s", module)
    except Exception as err:
        _write_module_state_atomic(
            module_name=module, new_state=ModuleStatus.FAILED)
        log.error("Installation failed for module %s", module)
        installer.app_logger.exception(
            "Unknown error occurred, please, retry "
            "or contact CloudLinux support if it happens again."
            "\n\nError: %s", str(err),
            extra={
                # Used to group and break up events
                'fingerprint': ['{{ default }}', module, str(err)[:25]],
                # Additional data for sentry event; option KEYS only, never values.
                'data': {'option_keys': sorted(options)}
            })
        raise InstallationFailedException() from err
    else:
        _write_module_state_atomic(
            module_name=module, new_state=ModuleStatus.INSTALLED)
        log.info("Module '%s' successfully installed "
                 "with option keys %s", module, sorted(options))


def _write_module_state_atomic(module_name, new_state):
    # type: (str, str) -> None
    with acquire_config_access() as config_access:
        config_access.set_module_status(module_name=module_name, new_state=new_state)