2019-09-02 04:37:13 +02:00
|
|
|
from cement.core.controller import CementBaseController, expose
|
2019-09-05 11:47:04 +02:00
|
|
|
|
2020-10-23 12:50:31 +02:00
|
|
|
from wo.cli.plugins.stack_pref import post_pref, pre_pref
|
2018-11-13 21:55:59 +01:00
|
|
|
from wo.core.aptget import WOAptGet
|
2020-10-23 12:50:31 +02:00
|
|
|
from wo.core.fileutils import WOFileUtils
|
2019-09-02 04:37:13 +02:00
|
|
|
from wo.core.logging import Log
|
|
|
|
|
from wo.core.mysql import WOMysql
|
2018-11-13 21:55:59 +01:00
|
|
|
from wo.core.shellexec import WOShellExec
|
2019-10-02 13:13:32 +02:00
|
|
|
from wo.core.variables import WOVar
|
2020-10-23 13:32:39 +02:00
|
|
|
from wo.core.apt_repo import WORepo
|
2018-11-13 21:55:59 +01:00
|
|
|
|
2020-10-23 13:49:14 +02:00
|
|
|
|
2018-11-13 21:55:59 +01:00
|
|
|
class WOStackMigrateController(CementBaseController):
|
|
|
|
|
class Meta:
|
|
|
|
|
label = 'migrate'
|
|
|
|
|
stacked_on = 'stack'
|
|
|
|
|
stacked_type = 'nested'
|
|
|
|
|
description = ('Migrate stack safely')
|
|
|
|
|
arguments = [
|
|
|
|
|
(['--mariadb'],
|
2020-10-23 12:50:31 +02:00
|
|
|
dict(help="Migrate/Upgrade database to MariaDB",
|
|
|
|
|
action='store_true')),
|
|
|
|
|
(['--force'],
|
|
|
|
|
dict(help="Force Packages upgrade without any prompt",
|
2018-11-13 21:55:59 +01:00
|
|
|
action='store_true')),
|
2020-10-28 11:45:30 +01:00
|
|
|
(['--ci'],
|
|
|
|
|
dict(help="Argument used for testing, "
|
|
|
|
|
"do not use it on your server",
|
|
|
|
|
action='store_true')),
|
2019-03-19 16:58:35 +01:00
|
|
|
]
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
@expose(hide=True)
|
2020-10-28 12:25:09 +01:00
|
|
|
def migrate_mariadb(self, ci=False):
|
2023-07-16 23:29:52 +02:00
|
|
|
|
|
|
|
|
if WOShellExec.cmd_exec(self, 'mysqladmin ping'):
|
|
|
|
|
# Backup all database
|
|
|
|
|
WOMysql.backupAll(self, fulldump=True)
|
|
|
|
|
else:
|
|
|
|
|
Log.error(self, "Unable to connect to MariaDB")
|
|
|
|
|
|
|
|
|
|
# Check current MariaDB version
|
|
|
|
|
wo_mysql_current_repo = WOFileUtils.grep(
|
|
|
|
|
self, '/etc/apt/sources.list.d/wo-repo.list', 'mariadb')
|
|
|
|
|
if wo_mysql_current_repo:
|
|
|
|
|
current_mysql_version = wo_mysql_current_repo.split('/')
|
|
|
|
|
else:
|
2023-08-04 16:46:00 +02:00
|
|
|
Log.error(self, "MariaDB is not installed from repository yet")
|
2023-07-16 23:29:52 +02:00
|
|
|
if 'repo' in current_mysql_version:
|
|
|
|
|
current_mysql_version = current_mysql_version[5]
|
|
|
|
|
|
|
|
|
|
mariadb_release = WOVar.mariadb_ver
|
|
|
|
|
if mariadb_release <= current_mysql_version:
|
|
|
|
|
Log.info(self, "You already have the latest "
|
|
|
|
|
"MariaDB version available")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
wo_old_mysql_repo = ("deb [arch=amd64,arm64,ppc64el] "
|
|
|
|
|
"http://mariadb.mirrors.ovh.net/MariaDB/repo/"
|
|
|
|
|
"{version}/{distro} {codename} main"
|
|
|
|
|
.format(version=current_mysql_version,
|
|
|
|
|
distro=WOVar.wo_distro,
|
|
|
|
|
codename=WOVar.platform_codename))
|
|
|
|
|
|
2020-10-23 13:32:39 +02:00
|
|
|
if WOFileUtils.grepcheck(
|
|
|
|
|
self, '/etc/apt/sources.list.d/wo-repo.list',
|
2023-07-16 23:29:52 +02:00
|
|
|
wo_old_mysql_repo):
|
|
|
|
|
WORepo.remove(self, repo_url=wo_old_mysql_repo)
|
2018-11-13 21:55:59 +01:00
|
|
|
# Add MariaDB repo
|
2020-10-23 12:50:31 +02:00
|
|
|
pre_pref(self, WOVar.wo_mysql)
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
# Install MariaDB
|
|
|
|
|
|
2020-10-23 16:33:35 +02:00
|
|
|
Log.wait(self, "Updating apt-cache ")
|
2018-11-13 21:55:59 +01:00
|
|
|
WOAptGet.update(self)
|
2020-10-23 16:33:35 +02:00
|
|
|
Log.valide(self, "Updating apt-cache ")
|
|
|
|
|
Log.wait(self, "Upgrading MariaDB ")
|
2020-10-23 12:50:31 +02:00
|
|
|
WOAptGet.remove(self, ["mariadb-server"])
|
2018-11-13 21:55:59 +01:00
|
|
|
WOAptGet.auto_remove(self)
|
2020-10-23 12:50:31 +02:00
|
|
|
WOAptGet.install(self, WOVar.wo_mysql)
|
2020-10-28 12:25:09 +01:00
|
|
|
if not ci:
|
2020-10-28 11:45:30 +01:00
|
|
|
WOAptGet.dist_upgrade(self)
|
2020-10-28 11:11:01 +01:00
|
|
|
WOAptGet.auto_remove(self)
|
2022-09-25 13:29:40 +02:00
|
|
|
WOAptGet.auto_clean(self)
|
2020-10-23 16:33:35 +02:00
|
|
|
Log.valide(self, "Upgrading MariaDB ")
|
2020-10-23 12:50:31 +02:00
|
|
|
WOFileUtils.mvfile(
|
|
|
|
|
self, '/etc/mysql/my.cnf', '/etc/mysql/my.cnf.old')
|
|
|
|
|
WOFileUtils.create_symlink(
|
|
|
|
|
self, ['/etc/mysql/mariadb.cnf', '/etc/mysql/my.cnf'])
|
2020-10-23 16:33:35 +02:00
|
|
|
WOShellExec.cmd_exec(self, 'systemctl daemon-reload')
|
2020-10-27 11:25:14 +01:00
|
|
|
WOShellExec.cmd_exec(self, 'systemctl enable mariadb')
|
2020-10-23 16:33:35 +02:00
|
|
|
post_pref(self, WOVar.wo_mysql, [])
|
|
|
|
|
|
2018-11-13 21:55:59 +01:00
|
|
|
@expose(hide=True)
|
|
|
|
|
def default(self):
|
2020-10-23 12:50:31 +02:00
|
|
|
pargs = self.app.pargs
|
2022-09-25 13:32:38 +02:00
|
|
|
if not pargs.mariadb:
|
2018-11-13 21:55:59 +01:00
|
|
|
self.app.args.print_help()
|
2020-10-23 12:50:31 +02:00
|
|
|
if pargs.mariadb:
|
2020-10-28 11:45:30 +01:00
|
|
|
if WOVar.wo_distro == 'raspbian':
|
|
|
|
|
Log.error(self, "MariaDB upgrade is not available on Raspbian")
|
2019-10-02 13:13:32 +02:00
|
|
|
if WOVar.wo_mysql_host != "localhost":
|
2019-03-19 16:58:35 +01:00
|
|
|
Log.error(
|
|
|
|
|
self, "Remote MySQL server in use, skipping local install")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
2022-09-25 13:32:38 +02:00
|
|
|
if WOShellExec.cmd_exec(self, "mysqladmin ping"):
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
Log.info(self, "If your database size is big, "
|
|
|
|
|
"migration may take some time.")
|
|
|
|
|
Log.info(self, "During migration non nginx-cached parts of "
|
|
|
|
|
"your site may remain down")
|
2020-10-23 12:50:31 +02:00
|
|
|
if not pargs.force:
|
|
|
|
|
start_upgrade = input("Do you want to continue:[y/N]")
|
|
|
|
|
if start_upgrade != "Y" and start_upgrade != "y":
|
|
|
|
|
Log.error(self, "Not starting package update")
|
2020-10-28 12:25:09 +01:00
|
|
|
if not pargs.ci:
|
|
|
|
|
self.migrate_mariadb()
|
|
|
|
|
else:
|
|
|
|
|
self.migrate_mariadb(ci=True)
|
2018-11-13 21:55:59 +01:00
|
|
|
else:
|
|
|
|
|
Log.error(self, "Your current MySQL is not alive or "
|
|
|
|
|
"you allready installed MariaDB")
|