Use wo stack migrate for MariaDB major upgrade

This commit is contained in:
VirtuBox
2020-10-23 12:50:31 +02:00
parent cbd29a968c
commit bed285abc4
5 changed files with 44 additions and 102 deletions

View File

@@ -226,6 +226,24 @@ if [ -z "$1" ]; then
fi fi
done done
fi fi
echo -e "${CGREEN}#############################################${CEND}"
echo -e ' wo stack migrate --mariadb '
echo -e "${CGREEN}#############################################${CEND}"
echo -ne " Upgrading mariadb [..]\r"
if {
wo stack migrate --mariadb --force
} >>/var/log/wo/test.log; then
echo -ne " Upgrading mariadb [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Upgrading mariadb [${CRED}FAIL${CEND}]"
echo -ne '\n'
exit_script
fi
echo -e "${CGREEN}#############################################${CEND}" echo -e "${CGREEN}#############################################${CEND}"
echo -e ' wo clean ' echo -e ' wo clean '
echo -e "${CGREEN}#############################################${CEND}" echo -e "${CGREEN}#############################################${CEND}"

View File

@@ -8,7 +8,7 @@ VERSION = WOVar.wo_version
BANNER = """ BANNER = """
WordOps v%s WordOps v%s
Copyright (c) 2019 WordOps. Copyright (c) 2020 WordOps.
""" % VERSION """ % VERSION

View File

@@ -1,10 +1,8 @@
import configparser
import os
from cement.core.controller import CementBaseController, expose from cement.core.controller import CementBaseController, expose
from wo.core.apt_repo import WORepo from wo.cli.plugins.stack_pref import post_pref, pre_pref
from wo.core.aptget import WOAptGet from wo.core.aptget import WOAptGet
from wo.core.fileutils import WOFileUtils
from wo.core.logging import Log from wo.core.logging import Log
from wo.core.mysql import WOMysql from wo.core.mysql import WOMysql
from wo.core.shellexec import WOShellExec from wo.core.shellexec import WOShellExec
@@ -19,7 +17,10 @@ class WOStackMigrateController(CementBaseController):
description = ('Migrate stack safely') description = ('Migrate stack safely')
arguments = [ arguments = [
(['--mariadb'], (['--mariadb'],
dict(help="Migrate database to MariaDB", dict(help="Migrate/Upgrade database to MariaDB",
action='store_true')),
(['--force'],
dict(help="Force Packages upgrade without any prompt",
action='store_true')), action='store_true')),
] ]
@@ -28,95 +29,45 @@ class WOStackMigrateController(CementBaseController):
# Backup all database # Backup all database
WOMysql.backupAll(self, fulldump=True) WOMysql.backupAll(self, fulldump=True)
if not WOVar.wo_distro == 'raspbian':
if (not WOVar.wo_platform_codename == 'jessie'):
wo_mysql = ["mariadb-server", "percona-toolkit",
"python3-mysqldb", "mariadb-backup"]
else:
wo_mysql = ["mariadb-server", "percona-toolkit",
"python3-mysql.connector"]
else:
wo_mysql = ["mariadb-server", "percona-toolkit",
"python3-mysqldb"]
# Add MariaDB repo # Add MariaDB repo
Log.info(self, "Adding repository for MariaDB, please wait...") Log.info(self, "Adding repository for MariaDB, please wait...")
pre_pref(self, WOVar.wo_mysql)
mysql_pref = ("Package: *\nPin: origin sfo1.mirrors.digitalocean.com"
"\nPin-Priority: 1000\n")
with open('/etc/apt/preferences.d/'
'MariaDB.pref', 'w') as mysql_pref_file:
mysql_pref_file.write(mysql_pref)
WORepo.add(self, repo_url=WOVar.wo_mysql_repo)
Log.debug(self, 'Adding key for {0}'
.format(WOVar.wo_mysql_repo))
WORepo.add_key(self, '0xcbcb082a1bb943db',
keyserver="keyserver.ubuntu.com")
config = configparser.ConfigParser()
if os.path.exists('/etc/mysql/conf.d/my.cnf'):
config.read('/etc/mysql/conf.d/my.cnf')
else:
config.read(os.path.expanduser("~")+'/.my.cnf')
try:
chars = config['client']['password']
except Exception as e:
Log.error(self, "Error: process exited with error %s"
% e)
Log.debug(self, "Pre-seeding MariaDB")
Log.debug(self, "echo \"mariadb-server-10.3 "
"mysql-server/root_password "
"password \" | "
"debconf-set-selections")
WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.3 "
"mysql-server/root_password "
"password {chars}\" | "
"debconf-set-selections"
.format(chars=chars),
log=False)
Log.debug(self, "echo \"mariadb-server-10.3 "
"mysql-server/root_password_again "
"password \" | "
"debconf-set-selections")
WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.3 "
"mysql-server/root_password_again "
"password {chars}\" | "
"debconf-set-selections"
.format(chars=chars),
log=False)
# Install MariaDB # Install MariaDB
apt_packages = wo_mysql
Log.info(self, "Updating apt-cache, hang on...") Log.info(self, "Updating apt-cache, hang on...")
WOAptGet.update(self) WOAptGet.update(self)
Log.info(self, "Installing MariaDB, hang on...") Log.info(self, "Installing MariaDB, hang on...")
WOAptGet.remove(self, ["mysql-common", "libmysqlclient18"]) WOAptGet.remove(self, ["mariadb-server"])
WOAptGet.auto_remove(self) WOAptGet.auto_remove(self)
WOAptGet.install(self, apt_packages) WOAptGet.install(self, WOVar.wo_mysql)
post_pref(self, WOVar.wo_mysql, [])
WOShellExec.cmd_exec(self, 'systemctl daemon-reload')
WOFileUtils.mvfile(
self, '/etc/mysql/my.cnf', '/etc/mysql/my.cnf.old')
WOFileUtils.create_symlink(
self, ['/etc/mysql/mariadb.cnf', '/etc/mysql/my.cnf'])
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
if ((not self.app.pargs.mariadb)): pargs = self.app.pargs
if ((not pargs.mariadb)):
self.app.args.print_help() self.app.args.print_help()
if self.app.pargs.mariadb: if pargs.mariadb:
if WOVar.wo_mysql_host != "localhost": if WOVar.wo_mysql_host != "localhost":
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") and if (WOShellExec.cmd_exec(self, "mysqladmin ping")):
(not WOAptGet.is_installed(self, 'mariadb-server'))):
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.")
Log.info(self, "During migration non nginx-cached parts of " Log.info(self, "During migration non nginx-cached parts of "
"your site may remain down") "your site may remain down")
start_migrate = input("Type \"mariadb\" to continue:") if not pargs.force:
if start_migrate != "mariadb": start_upgrade = input("Do you want to continue:[y/N]")
Log.error(self, "Not starting migration") if start_upgrade != "Y" and start_upgrade != "y":
Log.error(self, "Not starting package update")
self.migrate_mariadb() self.migrate_mariadb()
else: else:
Log.error(self, "Your current MySQL is not alive or " Log.error(self, "Your current MySQL is not alive or "

View File

@@ -37,17 +37,7 @@ def pre_pref(self, apt_packages):
with open('/etc/apt/preferences.d/' with open('/etc/apt/preferences.d/'
'MariaDB.pref', 'w') as mysql_pref_file: 'MariaDB.pref', 'w') as mysql_pref_file:
mysql_pref_file.write(mysql_pref) mysql_pref_file.write(mysql_pref)
if not os.path.exists('/etc/apt/sources.list.d/wo-repo.list'): WORepo.add(self, repo_url=WOVar.wo_mysql_repo)
WORepo.add(self, repo_url=WOVar.wo_mysql_repo)
else:
if not WOFileUtils.grepcheck(
self, '/etc/apt/sources.list.d/wo-repo.list',
'MariaDB/repo/10.3'):
WORepo.add(self, repo_url=WOVar.wo_mysql_repo)
else:
WOFileUtils.searchreplace(
self, '/etc/apt/sources.list.d/wo-repo.list',
'10.3', '10.5')
WORepo.add_key(self, '0xcbcb082a1bb943db', WORepo.add_key(self, '0xcbcb082a1bb943db',
keyserver='keyserver.ubuntu.com') keyserver='keyserver.ubuntu.com')
WORepo.add_key(self, '0xF1656F24C74CD1D8', WORepo.add_key(self, '0xF1656F24C74CD1D8',
@@ -996,10 +986,6 @@ def post_pref(self, apt_packages, packages, upgrade=False):
WOTemplate.deploy( WOTemplate.deploy(
self, '/etc/mysql/mariadb.conf.d/50-server.cnf', self, '/etc/mysql/mariadb.conf.d/50-server.cnf',
'my.mustache', data) 'my.mustache', data)
WOFileUtils.mvfile(
self, '/etc/mysql/my.cnf', '/etc/mysql/my.cnf.old')
WOFileUtils.create_symlink(
self, ['/etc/mysql/mariadb.cnf', '/etc/mysql/my.cnf'])
else: else:
WOTemplate.deploy( WOTemplate.deploy(
self, '/etc/mysql/my.cnf', 'my.mustache', data) self, '/etc/mysql/my.cnf', 'my.mustache', data)

View File

@@ -294,12 +294,6 @@ class WOStackUpgradeController(CementBaseController):
# additional pre_pref # additional pre_pref
if "nginx-custom" in apt_packages: if "nginx-custom" in apt_packages:
pre_pref(self, WOVar.wo_nginx) pre_pref(self, WOVar.wo_nginx)
if "mariadb-server" in apt_packages:
mariadbmajorupgrade = bool(
WOFileUtils.grepcheck(
self, '/etc/apt/sources.list.d/wo-repo.list',
'MariaDB/repo/10.3'))
pre_pref(self, WOVar.wo_mysql)
Log.wait(self, "Updating APT cache") Log.wait(self, "Updating APT cache")
# apt-get update # apt-get update
WOAptGet.update(self) WOAptGet.update(self)
@@ -312,17 +306,10 @@ class WOStackUpgradeController(CementBaseController):
# redis pre_pref # redis pre_pref
if "redis-server" in apt_packages: if "redis-server" in apt_packages:
pre_pref(self, WOVar.wo_redis) pre_pref(self, WOVar.wo_redis)
# mariadb upgrade # upgrade packages
if ("mariadb-server" in apt_packages and
mariadbmajorupgrade is True):
WOMysql.backupAll(self, fulldump=True)
WOAptGet.remove(self, ["mariadb-server"])
# upgrade packages
WOAptGet.install(self, apt_packages) WOAptGet.install(self, apt_packages)
Log.wait(self, "Configuring APT Packages") Log.wait(self, "Configuring APT Packages")
post_pref(self, apt_packages, [], True) post_pref(self, apt_packages, [], True)
if "mariadb-server" in apt_packages:
WOShellExec.cmd_exec(self, 'mysql_upgrade')
Log.valide(self, "Configuring APT Packages") Log.valide(self, "Configuring APT Packages")
# Post Actions after package updates # Post Actions after package updates