Fix Mariadb on almalinux 9

Fix Mariadb on almalinux 9
This commit is contained in:
Master3395
2025-09-10 17:36:09 +02:00
parent b05d9cb5bb
commit 90abff30ae

View File

@@ -66,8 +66,20 @@ class InstallCyberPanel:
}
actual_service = service_map.get(service_name, service_name)
command = f'systemctl {action} {actual_service}'
return install_utils.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
# For AlmaLinux 9, try both mariadb and mysqld services
if service_name == 'mariadb' and (self.distro == cent8 or self.distro == openeuler):
# Try mariadb first, then mysqld if mariadb fails
command = f'systemctl {action} {actual_service}'
result = install_utils.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
if result != 0:
# If mariadb service fails, try mysqld
command = f'systemctl {action} mysqld'
return install_utils.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
return result
else:
command = f'systemctl {action} {actual_service}'
return install_utils.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
def modify_file_content(self, file_path, replacements):
"""Generic file content modification"""
@@ -487,6 +499,13 @@ gpgcheck=1
command = 'sudo dnf module reset mariadb -y'
install_utils.call(command, self.distro, command, command, 1, 1, os.EX_OSERR, True)
# Disable problematic mariadb-maxscale repository to avoid 404 errors
command = 'dnf config-manager --disable mariadb-maxscale'
install_utils.call(command, self.distro, command, command, 1, 0, os.EX_OSERR, True)
# Clear dnf cache to avoid repository issues
command = 'dnf clean all'
install_utils.call(command, self.distro, command, command, 1, 1, os.EX_OSERR, True)
command = 'dnf install MariaDB-server MariaDB-client MariaDB-backup -y'
@@ -505,9 +524,17 @@ gpgcheck=1
passwordCMD = "use mysql;DROP DATABASE IF EXISTS test;DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%%';GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '%s';flush privileges;" % (
InstallCyberPanel.mysql_Root_password)
command = 'mariadb -u root -e "' + passwordCMD + '"'
install_utils.call(command, self.distro, command, command, 0, 0, os.EX_OSERR)
# For AlmaLinux 9, try mysql command first, then mariadb
if self.distro == cent8 or self.distro == openeuler:
command = 'mysql -u root -e "' + passwordCMD + '"'
result = install_utils.call(command, self.distro, command, command, 0, 0, os.EX_OSERR)
if result != 0:
# If mysql command fails, try mariadb
command = 'mariadb -u root -e "' + passwordCMD + '"'
install_utils.call(command, self.distro, command, command, 0, 0, os.EX_OSERR)
else:
command = 'mariadb -u root -e "' + passwordCMD + '"'
install_utils.call(command, self.distro, command, command, 0, 0, os.EX_OSERR)
def startMariaDB(self):
@@ -549,7 +576,14 @@ gpgcheck=1
except IOError as err:
self.stdOut("[ERROR] Error in setting: " + fileName + ": " + str(err), 1, 1, os.EX_OSERR)
os.system('systemctl restart mariadb')
# Use the manage_service method for consistent service management
if self.distro == cent8 or self.distro == openeuler:
# Try mariadb first, then mysqld
result = os.system('systemctl restart mariadb')
if result != 0:
os.system('systemctl restart mysqld')
else:
os.system('systemctl restart mariadb')
self.stdOut("MariaDB is now setup so it can support Cyberpanel's needs")