From 98c7fefd99ae39447e6c9d6c031f3cea3f656255 Mon Sep 17 00:00:00 2001 From: master3395 Date: Tue, 27 Jan 2026 00:41:43 +0100 Subject: [PATCH] Fix MariaDB installation issues on AlmaLinux 9 - Enhanced MariaDB-server-compat package removal with multiple aggressive attempts - Added --allowerasing and dnf exclude to prevent compat package conflicts - Added MariaDB binary verification before password change - Added service status verification and wait time - Improved error handling and graceful failure - Fixed FileNotFoundError when mysql command not found Fixes: - MariaDB-server-compat-12.1.2-1.el9.noarch conflict with MariaDB 10.11 - mysql command not found after failed installation - Installation proceeding when MariaDB wasn't actually installed --- .gitignore.patreon | 5 ++ install/install.py | 59 ++++++++++++++++++- plogical/upgrade.py | 41 ++++++++++++-- to-do/MARIADB_INSTALLATION_FIXES.md | 88 +++++++++++++++++++++++++++++ 4 files changed, 186 insertions(+), 7 deletions(-) create mode 100644 .gitignore.patreon create mode 100644 to-do/MARIADB_INSTALLATION_FIXES.md diff --git a/.gitignore.patreon b/.gitignore.patreon new file mode 100644 index 000000000..2804dc3f0 --- /dev/null +++ b/.gitignore.patreon @@ -0,0 +1,5 @@ +# Patreon Secrets - Never commit these files +patreon_config.py +patreon_secrets.env +.env.patreon +*patreon*.secret diff --git a/install/install.py b/install/install.py index 384aeb76f..51d98ef71 100644 --- a/install/install.py +++ b/install/install.py @@ -1815,14 +1815,29 @@ module cyberpanel_ols { # These packages from MariaDB 12.1 can conflict with MariaDB 10.11 self.stdOut("Removing conflicting MariaDB compat packages...", 1) try: + # Multiple aggressive removal attempts to ensure compat package is gone + # Step 1: Try dnf remove with allowerasing + subprocess.run("dnf remove -y --allowerasing 'MariaDB-server-compat*' 2>/dev/null || true", shell=True, timeout=60) + + # Step 2: Force remove with rpm subprocess.run("rpm -e --nodeps MariaDB-server-compat-12.1.2-1.el9.noarch 2>/dev/null; true", shell=True, timeout=30) - subprocess.run("dnf remove -y 'MariaDB-server-compat*' 2>/dev/null || true", shell=True, timeout=60) + + # Step 3: Find and remove any remaining compat packages r = subprocess.run("rpm -qa 2>/dev/null | grep -i MariaDB-server-compat", shell=True, capture_output=True, text=True, timeout=30) for line in (r.stdout or "").strip().splitlines(): pkg = (line.strip().split() or [""])[0] if pkg and "MariaDB-server-compat" in pkg: + self.stdOut(f"Force removing remaining compat package: {pkg}", 1) subprocess.run(["rpm", "-e", "--nodeps", pkg], timeout=30) - self.stdOut("Removed conflicting MariaDB compat packages", 1) + + # Step 4: Verify removal and exclude from future installs + r = subprocess.run("rpm -qa 2>/dev/null | grep -i MariaDB-server-compat", shell=True, capture_output=True, text=True, timeout=30) + if r.stdout.strip(): + self.stdOut(f"Warning: Some compat packages still present: {r.stdout.strip()}", 0) + # Add to dnf exclude to prevent reinstallation + subprocess.run("dnf config-manager --setopt exclude='MariaDB-server-compat*' --save 2>/dev/null || true", shell=True, timeout=30) + else: + self.stdOut("Successfully removed all MariaDB-server-compat packages", 1) except Exception as e: self.stdOut("Warning: Could not remove compat packages: " + str(e), 0) @@ -1852,8 +1867,34 @@ module cyberpanel_ols { command = 'dnf install mariadb-server mariadb-devel mariadb-client-utils -y' self.call(command, self.distro, command, command, 1, 1, os.EX_OSERR, True) + # Verify MariaDB was installed successfully before proceeding + if not os.path.exists('/usr/bin/mysql') and not os.path.exists('/usr/bin/mariadb'): + self.stdOut("Error: MariaDB binaries not found after installation. Installation may have failed.", 0) + return False + # Start and enable MariaDB - self.startMariaDB() + if not self.startMariaDB(): + self.stdOut("Error: Failed to start MariaDB service", 0) + return False + + # Wait a moment for MariaDB to be ready + import time + time.sleep(3) + + # Verify MariaDB is running before changing password + mariadb_running = False + for service_name in ['mariadb', 'mysql', 'mysqld']: + try: + result = subprocess.run(f"systemctl is-active {service_name}", shell=True, capture_output=True, text=True, timeout=5) + if result.returncode == 0 and 'active' in result.stdout.lower(): + mariadb_running = True + break + except: + continue + + if not mariadb_running: + self.stdOut("Warning: MariaDB service may not be running. Attempting password change anyway...", 0) + self.changeMYSQLRootPassword() self.fixMariaDB() @@ -1897,6 +1938,18 @@ module cyberpanel_ols { """Change MySQL root password""" try: if self.remotemysql == 'OFF': + # Verify mysql/mariadb command exists before attempting password change + mysql_exists = False + for cmd in ['mysql', 'mariadb', '/usr/bin/mysql', '/usr/bin/mariadb']: + if self.command_exists(cmd.split()[-1]) or os.path.exists(cmd): + mysql_exists = True + break + + if not mysql_exists: + self.stdOut("Error: mysql/mariadb command not found. MariaDB may not have been installed successfully.", 0) + self.ensure_mysql_password_file() # Still save password for manual fix + return False + # Use ALTER USER syntax (compatible with MariaDB 10.4+ and MySQL 5.7+) # GRANT ... IDENTIFIED BY is deprecated in MariaDB 10.4+ and removed in 10.11+ passwordCMD = "use mysql;DROP DATABASE IF EXISTS test;DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%%';ALTER USER 'root'@'localhost' IDENTIFIED BY '%s';GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;flush privileges;" % (self.mysql_Root_password) diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 9a1ff2353..67cfc2a3e 100644 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -4302,13 +4302,29 @@ echo $oConfig->Save() ? 'Done' : 'Error'; # CRITICAL: Remove MariaDB-server-compat* before any MariaDB install (conflicts with 10.11) Upgrade.stdOut("Removing conflicting MariaDB-server-compat packages...", 1) try: + # Multiple aggressive removal attempts to ensure compat package is gone + # Step 1: Try dnf remove with allowerasing + subprocess.run("dnf remove -y --allowerasing 'MariaDB-server-compat*' 2>/dev/null || true", shell=True, timeout=60) + + # Step 2: Force remove with rpm subprocess.run("rpm -e --nodeps MariaDB-server-compat-12.1.2-1.el9.noarch 2>/dev/null; true", shell=True, timeout=30) - subprocess.run("dnf remove -y 'MariaDB-server-compat*' 2>/dev/null || true", shell=True, timeout=60) + + # Step 3: Find and remove any remaining compat packages r = subprocess.run("rpm -qa 2>/dev/null | grep -i MariaDB-server-compat", shell=True, capture_output=True, text=True, timeout=30) for line in (r.stdout or "").strip().splitlines(): pkg = (line.strip().split() or [""])[0] if pkg and "MariaDB-server-compat" in pkg: + Upgrade.stdOut(f"Force removing remaining compat package: {pkg}", 1) subprocess.run(["rpm", "-e", "--nodeps", pkg], timeout=30) + + # Step 4: Verify removal and exclude from future installs + r = subprocess.run("rpm -qa 2>/dev/null | grep -i MariaDB-server-compat", shell=True, capture_output=True, text=True, timeout=30) + if r.stdout.strip(): + Upgrade.stdOut(f"Warning: Some compat packages still present: {r.stdout.strip()}", 0) + # Add to dnf exclude to prevent reinstallation + subprocess.run("dnf config-manager --setopt exclude='MariaDB-server-compat*' --save 2>/dev/null || true", shell=True, timeout=30) + else: + Upgrade.stdOut("Successfully removed all MariaDB-server-compat packages", 1) except Exception as e: Upgrade.stdOut("Warning: compat cleanup: " + str(e), 0) @@ -4340,13 +4356,30 @@ echo $oConfig->Save() ? 'Done' : 'Error'; if result.returncode != 0: Upgrade.stdOut(f"Warning: MariaDB repo setup failed: {result.stderr}", 0) - # Install MariaDB packages + # Install MariaDB packages with exclude to prevent compat package conflicts Upgrade.stdOut("Installing MariaDB packages...", 1) mariadb_packages = "MariaDB-server MariaDB-client MariaDB-backup MariaDB-devel" - command = f"dnf install -y {mariadb_packages}" + # Use --exclude to prevent compat package from being installed + command = f"dnf install -y --exclude='MariaDB-server-compat*' {mariadb_packages}" result = subprocess.run(command, shell=True, capture_output=True, text=True) if result.returncode != 0: - Upgrade.stdOut(f"Warning: MariaDB installation issues: {result.stderr}", 0) + # Check if it's a compat package conflict + error_output = result.stderr + result.stdout + if "MariaDB-server-compat" in error_output or "conflicts" in error_output.lower(): + Upgrade.stdOut("Compat package conflict detected, trying with --allowerasing...", 1) + command = f"dnf install -y --allowerasing --exclude='MariaDB-server-compat*' {mariadb_packages}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + if result.returncode != 0: + Upgrade.stdOut(f"Error: MariaDB installation failed: {result.stderr}", 0) + return False + else: + Upgrade.stdOut(f"Warning: MariaDB installation issues: {result.stderr}", 0) + return False + + # Verify MariaDB was installed successfully + if not os.path.exists('/usr/bin/mysql') and not os.path.exists('/usr/bin/mariadb'): + Upgrade.stdOut("Error: MariaDB binaries not found after installation", 0) + return False # Start and enable MariaDB service Upgrade.stdOut("Starting MariaDB service...", 1) diff --git a/to-do/MARIADB_INSTALLATION_FIXES.md b/to-do/MARIADB_INSTALLATION_FIXES.md new file mode 100644 index 000000000..f133868d3 --- /dev/null +++ b/to-do/MARIADB_INSTALLATION_FIXES.md @@ -0,0 +1,88 @@ +# MariaDB Installation Fixes + +## Issues Fixed + +### 1. MariaDB-server-compat Package Conflict +**Problem**: `MariaDB-server-compat-12.1.2-1.el9.noarch` was conflicting with MariaDB 10.11 installation, causing transaction test errors. + +**Solution**: +- Enhanced compat package removal with multiple aggressive removal attempts +- Added `--allowerasing` flag to dnf remove commands +- Added dnf exclude configuration to prevent compat package reinstallation +- Verification step to ensure all compat packages are removed before installation + +**Files Modified**: +- `cyberpanel-repo/plogical/upgrade.py` - `fix_almalinux9_mariadb()` function +- `cyberpanel-repo/install/install.py` - `installMySQL()` function + +### 2. MySQL Command Not Found Error +**Problem**: After MariaDB installation failed, the `changeMYSQLRootPassword()` function tried to use the `mysql` command which didn't exist, causing `FileNotFoundError`. + +**Solution**: +- Added verification that MariaDB binaries exist before attempting password change +- Added check for mysql/mariadb command availability +- Added MariaDB service status verification before password change +- Added wait time for MariaDB to be ready after service start + +**Files Modified**: +- `cyberpanel-repo/install/install.py` - `changeMYSQLRootPassword()` function +- `cyberpanel-repo/install/install.py` - `installMySQL()` function + +### 3. MariaDB Installation Verification +**Problem**: Installation was proceeding even when MariaDB wasn't actually installed successfully. + +**Solution**: +- Added binary existence check after installation +- Added service status verification +- Added proper error handling and return values +- Installation now fails gracefully if MariaDB wasn't installed + +**Files Modified**: +- `cyberpanel-repo/plogical/upgrade.py` - `fix_almalinux9_mariadb()` function +- `cyberpanel-repo/install/install.py` - `installMySQL()` function + +## Changes Made + +### upgrade.py +1. **Enhanced compat package removal**: + - Multiple removal attempts (dnf remove, rpm -e, individual package removal) + - Added `--allowerasing` flag + - Added dnf exclude configuration + - Verification step + +2. **Improved MariaDB installation**: + - Added `--exclude='MariaDB-server-compat*'` to dnf install command + - Added fallback with `--allowerasing` if conflicts occur + - Added binary existence verification after installation + - Proper error handling and return values + +### install.py +1. **Enhanced compat package removal** (same as upgrade.py) + +2. **Improved installation verification**: + - Check for MariaDB binaries after installation + - Verify service is running before password change + - Added wait time for service to be ready + - Proper error handling + +3. **Improved password change function**: + - Verify mysql/mariadb command exists before attempting password change + - Better error messages + - Graceful failure handling + +## Testing Recommendations + +1. Test on clean AlmaLinux 9 system +2. Test with existing MariaDB-server-compat package installed +3. Test with MariaDB 10.x already installed +4. Test with MariaDB 12.x already installed +5. Verify MariaDB service starts correctly +6. Verify mysql/mariadb commands are available +7. Verify password change succeeds + +## Notes + +- The fixes maintain backward compatibility +- All changes include proper error handling +- Installation now fails gracefully with clear error messages +- Compat package removal is more aggressive to handle edge cases