Sindbad~EG File Manager

Current Path : /proc/thread-self/root/opt/alt/python37/lib/python3.7/site-packages/clconfigure/cli/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python37/lib/python3.7/site-packages/clconfigure/cli/cloudlinux-reconfigure.py

#!/opt/alt/python37/bin/python3 -bb
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2018 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# https://cloudlinux.com/docs/LICENCE.TXT
#
from __future__ import absolute_import
import argparse
import logging
import sys

from clconfigure import task
from clconfigure.limits import set_default_limits_state
from clconfigure.services import set_service_state, STATE_RUNNING, STATE_MASKED, STATE_STOPPED, STATE_UNMASKED
from clconfigure.packages import set_package_state, STATE_INSTALLED, STATE_REMOVED
from lve_utils.sentry import init_lve_utils_sentry_client
from clconfigure import setup_logger
from clcommon.lib.cledition import is_cl_solo_edition, is_cl_admin_edition, is_container

LOGS_PATH = '/var/log/cloudlinux/clcustomizer.log'

CONFLICTED_PACKAGES = (
    'ea-apache24-mod_lsapi',
    'mod_lsapi',
    'httpd24-mod_lsapi',
    'mod_hostinglimits',
    'ea-apache24-mod_hostinglimits',
    'httpd24-mod_hostinglimits',
    'governor-mysql',
)


def _disable_lve_services():
    """
    Turn off all lve-related services.
    """
    set_service_state(STATE_STOPPED, 'lve')
    set_service_state(STATE_STOPPED, 'lve_namespaces')
    set_service_state(STATE_STOPPED, 'lvestats')
    set_service_state(STATE_STOPPED, 'lvectl')
    set_service_state(STATE_MASKED, 'lve')
    set_service_state(STATE_MASKED, 'lve_namespaces')
    set_service_state(STATE_MASKED, 'lvestats')
    set_service_state(STATE_MASKED, 'lvectl')


@task("Configuring environment for CloudLinux OS Solo: is_posttrans='{is_posttrans}'")
def install_cl_solo(is_posttrans):
    """
    Converts "normal" CloudLinux into CL Solo by disabling
    some services and installing some packages.
    :param is_posttrans:
        When true, we must do only actions that need to be done during
        %posttrans section of cloudlinux-solo-meta package
    """
    if not is_posttrans:
        for conflicted_package in CONFLICTED_PACKAGES:
            set_package_state(STATE_REMOVED, conflicted_package)
        set_package_state(STATE_INSTALLED, 'cloudlinux-solo-meta')
    else:
        _disable_lve_services()


@task("Configuring environment for CloudLinux OS Shared (container): is_posttrans='{is_posttrans}'")
def install_cl_container(is_posttrans):
    """
    Converts "normal" CloudLinux Shared into container by disabling
    some services and installing some packages.
    :param is_posttrans:
        When true, we must do only actions that need to be done during
        %posttrans section of cloudlinux-container package
    """
    if not is_posttrans:
        set_package_state(STATE_INSTALLED, 'cloudlinux-container')
    else:
        _disable_lve_services()


@task("Configuring environment for CloudLinux OS Admin: is_posttrans='{is_posttrans}'")
def install_cl_admin(is_posttrans):
    """
    Converts "normal" CloudLinux into CL Admin by changing default limits
    and some other stuff that may be added later.
    :param is_posttrans:
        When true, we must do only actions that need to be done during
        %posttrans section of cloudlinux-solo-meta package
    """
    if not is_posttrans:
        # TODO: mysql-governor is not so easy to install and
        #       also we don't support shared -> admin migration in production
        #       so just omit this case for now
        set_package_state(STATE_INSTALLED, 'cloudlinux-admin-meta')
    else:
        set_default_limits_state('unlimited')


@task("Converting environment from CloudLinux OS Solo to CloudLinux OS Shared: is_posttrans='{is_posttrans}'")
def uninstall_cl_solo(is_posttrans):
    """
    Converts CL Solo into "normal" CloudLinux by enabling
    some services and installing some packages.
    :param is_posttrans:
        When true, we must do only actions that need to be done during
        %posttrans section of cloudlinux-solo-meta package
    """
    if not is_posttrans:
        set_package_state(STATE_REMOVED, 'cloudlinux-solo-meta')
        set_package_state(STATE_INSTALLED, 'cagefs')
    else:
        set_service_state(STATE_UNMASKED, 'lve')
        set_service_state(STATE_UNMASKED, 'lve_namespaces')
        set_service_state(STATE_UNMASKED, 'lvestats')
        set_service_state(STATE_UNMASKED, 'lvectl')
        set_service_state(STATE_RUNNING, 'lve')
        set_service_state(STATE_RUNNING, 'lve_namespaces')
        set_service_state(STATE_RUNNING, 'lvectl')
        set_service_state(STATE_RUNNING, 'lvestats')


def main():
    """
    Entry point for this program.
    Parses arguments and calls needed methods.
    """
    setup_logger(None, LOGS_PATH)
    logging.debug('Executing "%s"', ' '.join(sys.argv))

    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers(dest='action')
    reconfigure = subparsers.add_parser('reconfigure')
    reconfigure.add_argument('-t', '--target', choices=[
        'solo',
        'shared',
        'container',
        'admin',
        'auto'
    ], required=True)
    reconfigure.add_argument('--posttrans', default=False, action='store_true')

    args = parser.parse_args()
    if args.action is None:
        parser.print_help()
        return

    if args.target == 'solo':
        install_cl_solo(args.posttrans)
    elif args.target == 'admin':
        install_cl_admin(args.posttrans)
    elif args.target == 'container':
        install_cl_container(args.posttrans)
    elif args.target == 'shared':
        uninstall_cl_solo(args.posttrans)
    elif args.target == 'auto':
        if is_container():
            install_cl_container(args.posttrans)
        elif is_cl_solo_edition(skip_jwt_check=False):
            install_cl_solo(args.posttrans)
        elif is_cl_admin_edition(skip_jwt_check=False):
            install_cl_admin(args.posttrans)
        else:
            # uninstall is currently not supported
            pass
    else:
        raise NotImplementedError()


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)

    init_lve_utils_sentry_client('clconfigure')
    main()


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists