def migrate_mariadb(self, ci=False): # Backup all database WOMysql.backupAll(self, fulldump=True) # Remove previous MariaDB repository wo_mysql_old_repo = ("deb [arch=amd64,ppc64el] " "http://mariadb.mirrors.ovh.net/MariaDB/repo/" "10.3/{distro} {codename} main".format( distro=WOVar.wo_distro, codename=WOVar.wo_platform_codename)) if WOFileUtils.grepcheck(self, '/etc/apt/sources.list.d/wo-repo.list', wo_mysql_old_repo): WORepo.remove(self, repo_url=wo_mysql_old_repo) # Add MariaDB repo pre_pref(self, WOVar.wo_mysql) # Install MariaDB Log.wait(self, "Updating apt-cache ") WOAptGet.update(self) Log.valide(self, "Updating apt-cache ") Log.wait(self, "Upgrading MariaDB ") WOAptGet.remove(self, ["mariadb-server"]) WOAptGet.auto_remove(self) WOAptGet.install(self, WOVar.wo_mysql) if not ci: WOAptGet.dist_upgrade(self) WOAptGet.auto_remove(self) Log.valide(self, "Upgrading MariaDB ") WOFileUtils.mvfile(self, '/etc/mysql/my.cnf', '/etc/mysql/my.cnf.old') WOFileUtils.create_symlink( self, ['/etc/mysql/mariadb.cnf', '/etc/mysql/my.cnf']) WOShellExec.cmd_exec(self, 'systemctl daemon-reload') WOShellExec.cmd_exec(self, 'systemctl enable mariadb') post_pref(self, WOVar.wo_mysql, [])
def migrate_mariadb(self): # Backup all database WOMysql.backupAll(self) # Add MariaDB repo Log.info(self, "Adding repository for MariaDB, please wait...") 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=WOVariables.wo_mysql_repo) Log.debug(self, 'Adding key for {0}' .format(WOVariables.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.0 " "mysql-server/root_password " "password \" | " "debconf-set-selections") WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 " "mysql-server/root_password " "password {chars}\" | " "debconf-set-selections" .format(chars=chars), log=False) Log.debug(self, "echo \"mariadb-server-10.0 " "mysql-server/root_password_again " "password \" | " "debconf-set-selections") WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 " "mysql-server/root_password_again " "password {chars}\" | " "debconf-set-selections" .format(chars=chars), log=False) # Install MariaDB apt_packages = WOVariables.wo_mysql # If PHP is installed then install php5-mysql if WOAptGet.is_installed(self, "php5-fpm"): apt_packages = apt_packages + ["php5-mysql"] Log.info(self, "Updating apt-cache, hang on...") WOAptGet.update(self) Log.info(self, "Installing MariaDB, hang on...") WOAptGet.remove(self, ["mysql-common", "libmysqlclient18"]) WOAptGet.auto_remove(self) WOAptGet.install(self, apt_packages)
def purge(self): """Start purging of packages""" apt_packages = [] packages = [] pargs = self.app.pargs # Default action for stack purge if ((not pargs.web) and (not pargs.admin) and (not pargs.nginx) and (not pargs.php) and (not pargs.mysql) and (not pargs.wpcli) and (not pargs.phpmyadmin) and (not pargs.composer) and (not pargs.netdata) and (not pargs.dashboard) and (not pargs.fail2ban) and (not pargs.security) and (not pargs.mysqlclient) and (not pargs.mysqltuner) and (not pargs.adminer) and (not pargs.utils) and (not pargs.redis) and (not pargs.proftpd) and (not pargs.extplorer) and (not pargs.clamav) and (not pargs.ufw) and (not pargs.phpredisadmin) and (not pargs.sendmail) and (not pargs.php73)): pargs.web = True pargs.admin = True pargs.security = True if pargs.all: pargs.web = True pargs.admin = True pargs.php73 = True pargs.fail2ban = True pargs.proftpd = True pargs.utils = True pargs.redis = True packages = packages + ['/var/www/22222/htdocs'] if pargs.web: pargs.nginx = True pargs.php = True pargs.mysql = True pargs.wpcli = True pargs.sendmail = True if pargs.admin: pargs.utils = True pargs.composer = True pargs.netdata = True pargs.mysqltuner = True if pargs.security: pargs.fail2ban = True pargs.clamav = True pargs.ufw = True # NGINX if pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom'): Log.debug(self, "Add Nginx to apt_packages list") apt_packages = apt_packages + WOVariables.wo_nginx else: Log.info(self, "Nginx is not installed") # PHP if pargs.php: Log.debug(self, "Add PHP to apt_packages list") if WOAptGet.is_installed(self, 'php7.2-fpm'): if not (WOAptGet.is_installed(self, 'php7.3-fpm')): apt_packages = apt_packages + WOVariables.wo_php + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php # PHP 7.3 if pargs.php73: Log.debug(self, "Removing apt_packages variable of PHP 7.3") if WOAptGet.is_installed(self, 'php7.3-fpm'): if not (WOAptGet.is_installed(self, 'php7.2-fpm')): apt_packages = apt_packages + WOVariables.wo_php73 + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php73 # REDIS if pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): Log.debug(self, "Remove apt_packages variable of Redis") apt_packages = apt_packages + ["redis-server"] else: Log.info(self, "Redis is not installed") # MariaDB if pargs.mysql: if WOAptGet.is_installed(self, 'mariadb-server'): Log.debug(self, "Add MySQL to apt_packages list") apt_packages = apt_packages + [ 'mariadb-server', 'mysql-common', 'mariadb-client' ] packages = packages + ['/etc/mysql', '/var/lib/mysql'] else: Log.info(self, "MariaDB is not installed") # mysqlclient if pargs.mysqlclient: if WOShellExec.cmd_exec(self, "mysqladmin ping"): Log.debug(self, "Add MySQL client to apt_packages list") apt_packages = apt_packages + WOVariables.wo_mysql_client # fail2ban if pargs.fail2ban: if WOAptGet.is_installed(self, 'fail2ban'): Log.debug(self, "Add Fail2ban to apt_packages list") apt_packages = apt_packages + WOVariables.wo_fail2ban # ClamAV if pargs.clamav: if WOAptGet.is_installed(self, 'clamav'): Log.debug(self, "Add ClamAV to apt_packages list") apt_packages = apt_packages + WOVariables.wo_clamav # UFW if pargs.ufw: if WOAptGet.is_installed(self, 'ufw'): Log.debug(self, "Add UFW to apt_packages list") apt_packages = apt_packages + ["ufw"] # sendmail if pargs.sendmail: if WOAptGet.is_installed(self, 'sendmail'): Log.debug(self, "Add sendmail to apt_packages list") apt_packages = apt_packages + ["sendmail"] # proftpd if pargs.proftpd: if WOAptGet.is_installed(self, 'proftpd-basic'): Log.debug(self, "Add Proftpd to apt_packages list") apt_packages = apt_packages + ["proftpd-basic"] # WP-CLI if pargs.wpcli: if os.path.isfile('/usr/local/bin/wp'): Log.debug(self, "Purge package variable WPCLI") packages = packages + ['/usr/local/bin/wp'] # PHPMYADMIN if pargs.phpmyadmin: if os.path.isdir('{0}22222/htdocs/db/pma'.format( WOVariables.wo_webroot)): Log.debug(self, "Removing package of phpMyAdmin ") packages = packages + [ '{0}22222/htdocs/db/pma'.format(WOVariables.wo_webroot) ] # Composer if pargs.composer: if os.path.isfile('/usr/local/bin/composer'): Log.debug(self, "Removing package variable of Composer ") packages = packages + ['/usr/local/bin/composer'] # MySQLTuner if pargs.mysqltuner: if os.path.isfile('/usr/bin/mysqltuner'): Log.debug(self, "Removing packages for MySQLTuner ") packages = packages + ['/usr/bin/mysqltuner'] # PHPREDISADMIN if pargs.phpredisadmin: Log.debug(self, "Removing package variable of phpRedisAdmin ") if os.path.isdir('{0}22222/htdocs/cache/redis'.format( WOVariables.wo_webroot)): packages = packages + [ '{0}22222/htdocs/' 'cache/redis'.format(WOVariables.wo_webroot) ] # ADMINER if pargs.adminer: if os.path.isdir('{0}22222/htdocs/db/adminer'.format( WOVariables.wo_webroot)): Log.debug(self, "Removing package variable of Adminer ") packages = packages + [ '{0}22222/htdocs/db/adminer'.format(WOVariables.wo_webroot) ] # utils if pargs.utils: Log.debug(self, "Purge package variable utils") packages = packages + [ '{0}22222/htdocs/php/webgrind/'.format(WOVariables.wo_webroot), '{0}22222/htdocs/cache/opcache'.format( WOVariables.wo_webroot), '{0}22222/htdocs/cache/nginx/' 'clean.php'.format( WOVariables.wo_webroot), '/usr/bin/pt-query-advisor', '{0}22222/htdocs/db/anemometer'.format(WOVariables.wo_webroot) ] if pargs.netdata: Log.debug(self, "Removing Netdata") if os.path.isfile('/opt/netdata/usr/' 'libexec/netdata/netdata-uninstaller.sh'): packages = packages + ['/var/lib/wo/tmp/kickstart.sh'] if pargs.dashboard: Log.debug(self, "Removing Wo-Dashboard") packages = packages + [ '{0}22222/htdocs/assets/'.format(WOVariables.wo_webroot), '{0}22222/htdocs/index.php'.format(WOVariables.wo_webroot) ] if (packages) or (apt_packages): if (not pargs.force): start_purge = input('Are you sure you to want to' ' purge stacks from this server ?' '\nPackage configuration and data ' 'will not remain' ' on this server after this operation.\n' 'Purge stacks [y/N]') if start_purge != "Y" and start_purge != "y": Log.error(self, "Not starting stack purge") if (set(["nginx-custom"]).issubset(set(apt_packages))): WOService.stop_service(self, 'nginx') if (set(["fail2ban"]).issubset(set(apt_packages))): WOService.stop_service(self, 'fail2ban') if (set(["mariadb-server"]).issubset(set(apt_packages))): if (os.path.isfile('/usr/bin/mysql') and os.path.isdir('/var/lib/mysql')): WOMysql.backupAll(self) WOService.stop_service(self, 'mysql') # Netdata uninstaller if (set(['/var/lib/wo/tmp/' 'kickstart.sh']).issubset(set(packages))): if WOVariables.wo_distro == 'Raspbian': WOShellExec.cmd_exec(self, "bash /usr/" "libexec/netdata/netdata-" "uninstaller.sh -y -f", errormsg='', log=False) else: WOShellExec.cmd_exec( self, "bash /opt/netdata/usr/" "libexec/netdata/netdata-" "uninstaller.sh -y -f") if (apt_packages): Log.wait(self, "Purging APT Packages ") WOAptGet.remove(self, apt_packages, purge=True) WOAptGet.auto_remove(self) Log.valide(self, "Purging APT Packages ") if (packages): Log.wait(self, "Purging Packages ") WOFileUtils.remove(self, packages) Log.valide(self, "Purging Packages ") Log.info(self, "Successfully purged packages")
def remove(self): """Start removal of packages""" apt_packages = [] packages = [] pargs = self.app.pargs if ((not pargs.web) and (not pargs.admin) and (not pargs.nginx) and (not pargs.php) and (not pargs.mysql) and (not pargs.wpcli) and (not pargs.phpmyadmin) and (not pargs.composer) and (not pargs.netdata) and (not pargs.dashboard) and (not pargs.fail2ban) and (not pargs.security) and (not pargs.mysqlclient) and (not pargs.mysqltuner) and (not pargs.adminer) and (not pargs.utils) and (not pargs.redis) and (not pargs.proftpd) and (not pargs.extplorer) and (not pargs.clamav) and (not pargs.ufw) and (not pargs.phpredisadmin) and (not pargs.sendmail) and (not pargs.php73)): pargs.web = True pargs.admin = True if pargs.all: pargs.web = True pargs.admin = True pargs.php73 = True pargs.fail2ban = True pargs.proftpd = True pargs.utils = True pargs.redis = True pargs.security = True packages = packages + ['/var/www/22222/htdocs'] if pargs.web: pargs.nginx = True pargs.php = True pargs.mysql = True pargs.wpcli = True pargs.sendmail = True if pargs.admin: pargs.composer = True pargs.utils = True pargs.netdata = True pargs.mysqltuner = True if pargs.security: pargs.fail2ban = True pargs.clamav = True pargs.ufw = True # NGINX if pargs.nginx: if WOAptGet.is_installed(self, 'nginx-custom'): Log.debug(self, "Removing apt_packages variable of Nginx") apt_packages = apt_packages + WOVariables.wo_nginx # PHP 7.2 if pargs.php: Log.debug(self, "Removing apt_packages variable of PHP") if WOAptGet.is_installed(self, 'php7.2-fpm'): if not WOAptGet.is_installed(self, 'php7.3-fpm'): apt_packages = apt_packages + WOVariables.wo_php + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php # PHP7.3 if pargs.php73: Log.debug(self, "Removing apt_packages variable of PHP 7.3") if WOAptGet.is_installed(self, 'php7.3-fpm'): if not (WOAptGet.is_installed(self, 'php7.2-fpm')): apt_packages = apt_packages + WOVariables.wo_php73 + \ WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php73 # REDIS if pargs.redis: if WOAptGet.is_installed(self, 'redis-server'): Log.debug(self, "Remove apt_packages variable of Redis") apt_packages = apt_packages + ["redis-server"] # MariaDB if pargs.mysql: if WOAptGet.is_installed(self, 'mariadb-server'): Log.debug(self, "Removing apt_packages variable of MySQL") apt_packages = apt_packages + [ 'mariadb-server', 'mysql-common', 'mariadb-client' ] # mysqlclient if pargs.mysqlclient: Log.debug(self, "Removing apt_packages variable " "for MySQL Client") if WOShellExec.cmd_exec(self, "mysqladmin ping"): apt_packages = apt_packages + WOVariables.wo_mysql_client # fail2ban if pargs.fail2ban: if WOAptGet.is_installed(self, 'fail2ban'): Log.debug(self, "Remove apt_packages variable of Fail2ban") apt_packages = apt_packages + WOVariables.wo_fail2ban # ClamAV if pargs.clamav: Log.debug(self, "Setting apt_packages variable for ClamAV") if WOAptGet.is_installed(self, 'clamav'): apt_packages = apt_packages + WOVariables.wo_clamav # sendmail if pargs.sendmail: Log.debug(self, "Setting apt_packages variable for Sendmail") if WOAptGet.is_installed(self, 'sendmail'): apt_packages = apt_packages + ["sendmail"] # proftpd if pargs.proftpd: if WOAptGet.is_installed(self, 'proftpd-basic'): Log.debug(self, "Remove apt_packages variable for ProFTPd") apt_packages = apt_packages + ["proftpd-basic"] # UFW if pargs.ufw: if WOAptGet.is_installed(self, 'ufw'): Log.debug(self, "Remove apt_packages variable for UFW") apt_packages = apt_packages + ["ufw"] # WPCLI if pargs.wpcli: Log.debug(self, "Removing package variable of WPCLI ") if os.path.isfile('/usr/local/bin/wp'): packages = packages + ['/usr/local/bin/wp'] # PHPMYADMIN if pargs.phpmyadmin: if os.path.isdir('{0}22222/htdocs/db/pma'.format( WOVariables.wo_webroot)): Log.debug(self, "Removing package of phpMyAdmin ") packages = packages + [ '{0}22222/htdocs/db/pma'.format(WOVariables.wo_webroot) ] # Composer if pargs.composer: Log.debug(self, "Removing package of Composer ") if os.path.isfile('/usr/local/bin/composer'): packages = packages + ['/usr/local/bin/composer'] # MySQLTuner if pargs.mysqltuner: if os.path.isfile('/usr/bin/mysqltuner'): Log.debug(self, "Removing packages for MySQLTuner ") packages = packages + ['/usr/bin/mysqltuner'] # PHPREDISADMIN if pargs.phpredisadmin: Log.debug(self, "Removing package variable of phpRedisAdmin ") if os.path.isdir('{0}22222/htdocs/cache/redis'.format( WOVariables.wo_webroot)): packages = packages + [ '{0}22222/htdocs/' 'cache/redis'.format(WOVariables.wo_webroot) ] # ADMINER if pargs.adminer: if os.path.isdir('{0}22222/htdocs/db/adminer'.format( WOVariables.wo_webroot)): Log.debug(self, "Removing package variable of Adminer ") packages = packages + [ '{0}22222/htdocs/db/adminer'.format(WOVariables.wo_webroot) ] if pargs.utils: Log.debug(self, "Removing package variable of utils ") packages = packages + [ '{0}22222/htdocs/php/webgrind/'.format(WOVariables.wo_webroot), '{0}22222/htdocs/cache/opcache'.format( WOVariables.wo_webroot), '{0}22222/htdocs/cache/nginx/' 'clean.php'.format( WOVariables.wo_webroot), '/usr/bin/pt-query-advisor', '{0}22222/htdocs/db/anemometer'.format(WOVariables.wo_webroot) ] if pargs.netdata: Log.debug(self, "Removing Netdata") if os.path.isfile('/opt/netdata/usr/' 'libexec/netdata/netdata-uninstaller.sh'): packages = packages + ['/var/lib/wo/tmp/kickstart.sh'] if pargs.dashboard: if (os.path.isfile('{0}22222/htdocs/index.php'.format( WOVariables.wo_webroot)) or os.path.isfile('{0}22222/htdocs/index.html'.format( WOVariables.wo_webroot))): Log.debug(self, "Removing Wo-Dashboard") packages = packages + [ '{0}22222/htdocs/assets'.format(WOVariables.wo_webroot), '{0}22222/htdocs/index.php'.format(WOVariables.wo_webroot), '{0}22222/htdocs/index.html'.format(WOVariables.wo_webroot) ] if (packages) or (apt_packages): if (not pargs.force): start_remove = input('Are you sure you to want to' ' remove from server.' '\nPackage configuration will remain' ' on server after this operation.\n' 'Remove stacks [y/N]?') if start_remove != "Y" and start_remove != "y": Log.error(self, "Not starting stack removal") if 'nginx-custom' in apt_packages: WOService.stop_service(self, 'nginx') if 'mariadb-server' in apt_packages: WOMysql.backupAll(self) WOService.stop_service(self, 'mysql') # Netdata uninstaller if (set(['/var/lib/wo/tmp/' 'kickstart.sh']).issubset(set(packages))): if WOVariables.wo_distro == 'Raspbian': WOShellExec.cmd_exec( self, "bash /usr/" "libexec/netdata/" "netdata-uninstaller.sh -y -f") else: WOShellExec.cmd_exec(self, "bash /opt/netdata/usr/" "libexec/netdata/" "netdata-uninstaller.sh - y - f", errormsg='', log=False) if (packages): Log.wait(self, "Removing packages ") WOFileUtils.remove(self, packages) Log.valide(self, "Removing packages ") if (apt_packages): Log.debug(self, "Removing apt_packages") Log.wait(self, "Removing APT packages ") WOAptGet.remove(self, apt_packages) WOAptGet.auto_remove(self) Log.valide(self, "Removing APT packages ") Log.info(self, "Successfully removed packages")