ok
Direktori : /proc/self/root/opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/migrations/ |
Current File : //proc/self/root/opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/migrations/configs.py |
import logging import os import shutil from clwpos.logsetup import setup_logging from clcommon.cpapi import cpusers from clwpos.utils import get_pw from clwpos.feature_suites import ( get_suites_allowed_path, get_admin_config_permissions ) from clcommon.clcagefs import CAGEFS_MP_FILENAME, remove_mount_dir_cagefs _logger = setup_logging( caller_name='configs_migration', file_level=logging.INFO, logfile_path='/var/log/clwpos/configs_migration.log', ) def _copy_with_perms(source, target, gid): shutil.copy2(source, target) owner, group, mode = get_admin_config_permissions(gid) for item in os.listdir(target): full_path = os.path.join(target, item) os.chown(full_path, owner, group) os.chmod(full_path, mode) def migrate_configs(): """ Migrate configs stored on CloudLinux Solo Edition: /var/clwpos/solo """ migrate_solo_edition_config() def _transfer_config_files(files_to_be_moved): if not files_to_be_moved: _logger.info('Nothing to do, no configs in directory') return for username in cpusers(): pw_info = get_pw(username=username) uid, gid = pw_info.pw_uid, pw_info.pw_gid path = os.path.dirname(get_suites_allowed_path(uid)) if not os.path.exists(path): os.makedirs(path, 0o755, exist_ok=False) for item in files_to_be_moved: _copy_with_perms(item, path, gid) def migrate_solo_edition_config(): solo_dir = '/var/clwpos/solo' files_to_be_moved = [] if os.path.exists(solo_dir): files_to_be_moved = [os.path.join(solo_dir, item) for item in os.listdir(solo_dir)] _transfer_config_files(files_to_be_moved) if os.path.exists(CAGEFS_MP_FILENAME): remove_mount_dir_cagefs('!/var/clwpos/solo', remount_cagefs=True, remount_in_background=True) if os.path.exists(solo_dir): shutil.rmtree(solo_dir)