Properly use mariadb-admin instead of mysqladmin

This commit is contained in:
VirtuBox
2024-06-07 16:51:53 +02:00
parent 486ce838f7
commit c35e9e6fa3
7 changed files with 30 additions and 18 deletions

View File

@@ -8,8 +8,8 @@ from pynginxconfig import NginxConfig
from wo.core.aptget import WOAptGet from wo.core.aptget import WOAptGet
from wo.core.logging import Log from wo.core.logging import Log
from wo.core.shellexec import WOShellExec
from wo.core.variables import WOVar from wo.core.variables import WOVar
from wo.core.mysql import WOMysql
def wo_info_hook(app): def wo_info_hook(app):
@@ -598,11 +598,7 @@ class WOInfoController(CementBaseController):
self.info_php() self.info_php()
if pargs.mysql: if pargs.mysql:
if os.path.exists('/usr/bin/mariadb-admin'): if WOMysql.mariadb_ping(self):
mariadb_admin = "/usr/bin/mariadb-admin"
else:
mariadb_admin = "/usr/bin/mysqladmin"
if WOShellExec.cmd_exec(self, f"{mariadb_admin} ping"):
self.info_mysql() self.info_mysql()
else: else:
Log.info(self, "MySQL is not installed") Log.info(self, "MySQL is not installed")

View File

@@ -904,7 +904,7 @@ def site_package_check(self, stype):
if stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']: if stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
Log.debug(self, "Setting apt_packages variable for MySQL") Log.debug(self, "Setting apt_packages variable for MySQL")
if not WOShellExec.cmd_exec(self, "/usr/bin/mysqladmin ping"): if not WOMysql.mariadb_ping(self):
apt_packages = apt_packages + WOVar.wo_mysql apt_packages = apt_packages + WOVar.wo_mysql
if stype in ['wp', 'wpsubdir', 'wpsubdomain']: if stype in ['wp', 'wpsubdir', 'wpsubdomain']:

View File

@@ -208,7 +208,7 @@ class WOStackController(CementBaseController):
if pargs.mysql: if pargs.mysql:
pargs.mysqltuner = True pargs.mysqltuner = True
Log.debug(self, "Setting apt_packages variable for MySQL") Log.debug(self, "Setting apt_packages variable for MySQL")
if not WOShellExec.cmd_exec(self, "mysqladmin ping"): if not WOMysql.mariadb_ping(self):
apt_packages = apt_packages + WOVar.wo_mysql apt_packages = apt_packages + WOVar.wo_mysql
else: else:
Log.debug(self, "MySQL already installed and alive") Log.debug(self, "MySQL already installed and alive")
@@ -218,7 +218,7 @@ class WOStackController(CementBaseController):
if pargs.mysqlclient: if pargs.mysqlclient:
Log.debug(self, "Setting apt_packages variable " Log.debug(self, "Setting apt_packages variable "
"for MySQL Client") "for MySQL Client")
if not WOShellExec.cmd_exec(self, "mysqladmin ping"): if not WOMysql.mariadb_ping(self):
apt_packages = apt_packages + WOVar.wo_mysql_client apt_packages = apt_packages + WOVar.wo_mysql_client
else: else:
Log.debug(self, "MySQL already installed and alive") Log.debug(self, "MySQL already installed and alive")
@@ -470,7 +470,7 @@ class WOStackController(CementBaseController):
# UTILS # UTILS
if pargs.utils: if pargs.utils:
if not WOShellExec.cmd_exec(self, 'mysqladmin ping'): if not WOMysql.mariadb_ping(self):
pargs.mysql = True pargs.mysql = True
if not (WOAptGet.is_installed(self, 'php7.2-fpm') or if not (WOAptGet.is_installed(self, 'php7.2-fpm') or
WOAptGet.is_installed(self, 'php7.3-fpm') or WOAptGet.is_installed(self, 'php7.3-fpm') or
@@ -655,7 +655,7 @@ class WOStackController(CementBaseController):
if pargs.mysqlclient: if pargs.mysqlclient:
Log.debug(self, "Removing apt_packages variable " Log.debug(self, "Removing apt_packages variable "
"for MySQL Client") "for MySQL Client")
if WOShellExec.cmd_exec(self, "mysqladmin ping"): if WOMysql.mariadb_ping(self):
apt_packages = apt_packages + WOVar.wo_mysql_client apt_packages = apt_packages + WOVar.wo_mysql_client
# fail2ban # fail2ban
@@ -844,7 +844,7 @@ class WOStackController(CementBaseController):
packages = packages + ["/opt/netdata"] packages = packages + ["/opt/netdata"]
else: else:
Log.debug(self, "Netdata uninstaller not found") Log.debug(self, "Netdata uninstaller not found")
if WOShellExec.cmd_exec(self, 'mysqladmin ping'): if WOMysql.mariadb_ping(self):
WOMysql.execute( WOMysql.execute(
self, "DELETE FROM mysql.user WHERE User = 'netdata';") self, "DELETE FROM mysql.user WHERE User = 'netdata';")
@@ -972,7 +972,7 @@ class WOStackController(CementBaseController):
# mysqlclient # mysqlclient
if pargs.mysqlclient: if pargs.mysqlclient:
if WOShellExec.cmd_exec(self, "mysqladmin ping"): if WOMysql.mariadb_ping(self):
Log.debug(self, "Add MySQL client to apt_packages list") Log.debug(self, "Add MySQL client to apt_packages list")
apt_packages = apt_packages + WOVar.wo_mysql_client apt_packages = apt_packages + WOVar.wo_mysql_client
@@ -1145,7 +1145,7 @@ class WOStackController(CementBaseController):
packages = packages + ["/opt/netdata"] packages = packages + ["/opt/netdata"]
else: else:
Log.debug(self, "Netdata uninstaller not found") Log.debug(self, "Netdata uninstaller not found")
if WOShellExec.cmd_exec(self, 'mysqladmin ping'): if WOMysql.mariadb_ping(self):
WOMysql.execute( WOMysql.execute(
self, "DELETE FROM mysql.user WHERE User = 'netdata';") self, "DELETE FROM mysql.user WHERE User = 'netdata';")

View File

@@ -34,7 +34,7 @@ class WOStackMigrateController(CementBaseController):
@expose(hide=True) @expose(hide=True)
def migrate_mariadb(self, ci=False): def migrate_mariadb(self, ci=False):
if WOShellExec.cmd_exec(self, 'mysqladmin ping'): if WOMysql.mariadb_ping(self):
# Backup all database # Backup all database
WOMysql.backupAll(self, fulldump=True) WOMysql.backupAll(self, fulldump=True)
else: else:
@@ -111,7 +111,7 @@ class WOStackMigrateController(CementBaseController):
Log.error( Log.error(
self, "Remote MySQL server in use, skipping local install") self, "Remote MySQL server in use, skipping local install")
if WOShellExec.cmd_exec(self, "mysqladmin ping"): if WOMysql.mariadb_ping(self):
Log.info(self, "If your database size is big, " Log.info(self, "If your database size is big, "
"migration may take some time.") "migration may take some time.")

View File

@@ -1144,7 +1144,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
else: else:
wo_grant_host = 'localhost' wo_grant_host = 'localhost'
# check if mysql credentials are available # check if mysql credentials are available
if (WOShellExec.cmd_exec(self, "mysqladmin ping") if (WOMysql.mariadb_ping(self)
and wo_grant_host == 'localhost'): and wo_grant_host == 'localhost'):
try: try:
WOMysql.execute( WOMysql.execute(

View File

@@ -12,6 +12,7 @@ from wo.core.logging import Log
from wo.core.shellexec import WOShellExec from wo.core.shellexec import WOShellExec
from wo.core.variables import WOVar from wo.core.variables import WOVar
from wo.core.services import WOService from wo.core.services import WOService
from wo.core.mysql import WOMysql
class WOStackUpgradeController(CementBaseController): class WOStackUpgradeController(CementBaseController):
@@ -152,7 +153,7 @@ class WOStackUpgradeController(CementBaseController):
# mysql # mysql
if pargs.mysql: if pargs.mysql:
if WOShellExec.cmd_exec(self, 'mysqladmin ping'): if WOMysql.mariadb_ping(self):
apt_packages = apt_packages + ['mariadb-server'] apt_packages = apt_packages + ['mariadb-server']
# redis # redis

View File

@@ -7,6 +7,7 @@ from pymysql import DatabaseError, Error, connections
from wo.core.logging import Log from wo.core.logging import Log
from wo.core.variables import WOVar from wo.core.variables import WOVar
from wo.core.shellexec import WOShellExec
class MySQLConnectionError(Exception): class MySQLConnectionError(Exception):
@@ -161,3 +162,17 @@ class WOMysql():
except MySQLConnectionError as e: except MySQLConnectionError as e:
Log.debug(self, str(e)) Log.debug(self, str(e))
return False return False
def mariadb_ping(self):
if os.path.exists('/usr/bin/mariadb-admin'):
mariadb_admin = "/usr/bin/mariadb-admin"
elif os.path.exists('/usr/bin/mysqladmin'):
mariadb_admin = "/usr/bin/mysqladmin"
else:
Log.info(self, "MariaDB server isn't installed")
return False
if WOShellExec.cmd_exec(self, f"{mariadb_admin} ping"):
return True
else:
Log.info(self, "Unable to connect to MariaDB server")
return False