From 6f53509fad08ac153b8c4f3adf259ad18c24ab95 Mon Sep 17 00:00:00 2001 From: lgromero Date: Wed, 3 Jul 2024 15:39:05 +0200 Subject: [PATCH] refs #477 add function to detect php fpm version and changes php socker owner to ogboot --- installer/ogboot_installer.py | 55 ++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/installer/ogboot_installer.py b/installer/ogboot_installer.py index 7c33dec..1c0b136 100755 --- a/installer/ogboot_installer.py +++ b/installer/ogboot_installer.py @@ -5,7 +5,7 @@ ##### Autor: Antonio Emmanuel Guerrero Silva ######## ################################################################################# -import platform, os, sys, subprocess, datetime, shutil, pwd, glob, zipfile, urllib.request, logging, distro +import platform, os, sys, subprocess, datetime, shutil, pwd, glob, zipfile, urllib.request, logging, distro, re global PACKAGES_TO_INSTALL global UBUNTU_OS_VERSION @@ -897,6 +897,53 @@ def setup_nginx(): logger.error(f"OS error: {e}") exit(1) +def get_php_fpm_version(): + try: + # Obtener la versión de PHP + php_version_output = subprocess.check_output(["php", "-v"]).decode() + # Extraer la versión principal y secundaria (por ejemplo, "7.4") + match = re.search(r"PHP (\d+\.\d+)", php_version_output) + if match: + php_version = match.group(1) + return php_version + else: + raise RuntimeError("No se pudo determinar la versión de PHP.") + except subprocess.CalledProcessError as e: + logger.error(f"Error al obtener la versión de PHP: {e}") + exit(1) + +def modify_php_fpm_config(): + php_version = get_php_fpm_version() + php_fpm_conf_path = f"/etc/php/{php_version}/fpm/pool.d/www.conf" + + try: + # Leer el archivo de configuración + with open(php_fpm_conf_path, 'r') as file: + config_lines = file.readlines() + + # Modificar las líneas necesarias + with open(php_fpm_conf_path, 'w') as file: + for line in config_lines: + if line.startswith('user ='): + file.write('user = www-data\n') + elif line.startswith('group ='): + file.write('group = ogboot\n') + elif line.startswith('listen.owner ='): + file.write('listen.owner = www-data\n') + elif line.startswith('listen.group ='): + file.write('listen.group = ogboot\n') + else: + file.write(line) + + logger.info("PHP-FPM configuration file modified successfully.") + + # Reiniciar el servicio PHP-FPM + subprocess.run(["sudo", "systemctl", "restart", f"php{php_version}-fpm"]) + logger.info("PHP-FPM service restarted successfully.") + except Exception as e: + logger.error(f"An error occurred: {e}") + exit(1) + def install_oglive_daemon(): try: DAEMON_SCRIPT_SRC = os.path.join(WORKDIR, "ogboot/bin/oglive_daemon.py") @@ -1036,6 +1083,12 @@ setup_nginx() if subprocess.run(["echo", "$?"]).returncode != 0: logger.error("Error setup nginx") +logger.info("Configure php fpm") +modify_php_fpm_config() +if subprocess.run(["echo", "$?"]).returncode != 0: + logger.error("Error configure php fpm") + + logger.info("Configure ogboot daemon") install_oglive_daemon() if subprocess.run(["echo", "$?"]).returncode != 0: