Файловый менеджер - Редактировать - /opt/cpmigrate/environments/easyapache4.py
Ðазад
"""EasyApache4 Environment Module""" import glob import json import os import subprocess from environments.base import Environment class EasyApache4(Environment): """ Makes a backup of the current EA4 profile and copies over the origin EA4 profile and installs it. It will additionally match the default PHP version and fix the default PHP memory limit. """ def __init__(self): Environment.__init__(self) self.priority = 98 self.new_profile_path = None self.backup_profile_path = None self.default_version = None def check(self, _): if self.xfer.ea_version == 4: self.check_default_php() self.actions.append("* Export current EA4 profile as backup.") self.actions.append( "+ Export origin EA4 profile and install on this server." ) self.actions.append( f"+ Set default PHP version to {self.default_version}." ) self.actions.append( "+ Set default PHP memory limit to 512M (up from 32M)." ) def run(self, _): if self.xfer.ea_version == 4: self.export_local_eaprofile() self.export_remote_eaprofile() mv_success = self.mv_eaprofile() if mv_success: self.check_differences() self.import_eaprofile() self.set_default_php() self.set_default_memlimit() else: self.info("Skipping this Environment as origin is not EA4.") def check_default_php(self): """Checks and returns the origin server's default PHP version.""" ret_code, out = self.xfer.origin_command( "/usr/bin/php -v", command_out=subprocess.PIPE, sleep=2, quiet=True ) if ret_code == 0: output = out[0] if 'PHP' in output: version = output[4:7] self.default_version = int(version.replace(".", "")) if self.default_version < 56: self.warning(f"Origin default PHP version is {version}.") else: self.info(f"Origin default PHP version is {version}.") return version self.warning(f"Got unexpected output from PHP binary: {output}") self.error("Failed to obtain server default PHP version.") return None def export_local_eaprofile(self): """Exports the local EA4 profile as a backup.""" self.info("Backing up local EA4 profile.") ret_code, out = self.xfer.local_command( '/usr/local/bin/ea_current_to_profile', command_out=subprocess.PIPE, sleep=2, ) if ret_code == 0: self.backup_profile_path = out[0] self.info( f"Backed up local EA4 profile: {self.backup_profile_path}" ) else: self.error( f"Failed to back up local EA4 profile, return code: {ret_code}" ) def export_remote_eaprofile(self): """Exports the origin EA4 profile to prepare for transfer.""" self.info("Exporting remote EA4 profile.") ret_code, out = self.xfer.origin_command( '/usr/local/bin/ea_current_to_profile', command_out=subprocess.PIPE, sleep=2, ) if ret_code == 0: self.new_profile_path = out[0] self.info(f"Remote EA4 Profile path: {self.new_profile_path}") else: self.error( f"Failed to export EA profile, returned code: {ret_code}" ) def mv_eaprofile(self): """Transfers the origin EA4 profile to the target server.""" success = self.xfer.do_rsync( origin=f"{self.xfer.origin_server}:{self.new_profile_path}", destination=self.new_profile_path, name="mv_eaprofile", ) if success: self.info("EA Profile has been successfully copied over.") return success def import_eaprofile(self): """Imports the origin EA4 profile into EA4, installs packages.""" log_path = os.path.join(self.xfer.log_path, 'ea4_import.log') self.info(f"Importing origin EA4 profile, log: {log_path}") with open(log_path, 'w', encoding="utf-8") as out: ret_code, _ = self.xfer.local_command( [ '/usr/local/bin/ea_install_profile', '--install', self.new_profile_path, ], command_out=out, sleep=2, ) if ret_code == 0: self.info("Origin EA4 Profile has been imported successfully.") else: self.error("EA4 Profile import might have failed, check log.") def check_differences(self): """Finds the differences between the EA4 profiles""" backup_json = {} new_json = {} changes = [] with open(self.backup_profile_path, encoding="utf-8") as backup: backup_json = json.load(backup) with open(self.new_profile_path, encoding="utf-8") as new: new_json = json.load(new) for pkg in backup_json.get('pkgs'): if pkg not in new_json.get('pkgs'): changes.append(f"- {pkg}") for pkg in new_json.get('pkgs'): if pkg not in backup_json.get('pkgs'): changes.append(f"+ {pkg}") lines = '\n'.join(changes) self.info( "EA4 Adjustments Made:\n" "--- Original EA4 Profile\n" "+++ Migrated EA4 Profile\n\n" f"{lines}" ) def set_default_php(self): """Sets the server default PHP version.""" if self.default_version: self.xfer.whmapi_call( 'php_set_system_default_version', {'version': f'ea-php{self.default_version}'}, ) self.info( f"Default PHP version has been set to {self.default_version}." ) else: self.warning( "Could not set default PHP version as there was none found." ) def set_default_memlimit(self): """Changes the global memory limit from 32M to 256M""" files = glob.glob("/opt/cpanel/ea-php**/root/etc/php.ini") command = [ '/bin/sed', '-i', r's/memory_limit = 32M/memory_limit = 512M/g', ] command.extend(files) ret_code, _ = self.xfer.local_command(command) if ret_code == 0: self.info( "Successfully changed default PHP memory limit from 32M " "to 512M." ) else: self.error( "Failed to change default PHP memory limit from 32M to 512M." ) def capture_state(self): state = { 'new_profile_path': self.new_profile_path, 'backup_profile_path': self.backup_profile_path, } return super().capture_state(state) def load_state(self, loadstate): self.new_profile_path = loadstate.get('new_profile_path', False) self.backup_profile_path = loadstate.get('backup_profile_path', False) super().load_state(loadstate)
| ver. 1.1 | |
.
| PHP 8.3.30 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка