def remove(self): """Start removal of packages""" apt_packages = [] packages = [] # Default action for stack remove if ((not self.app.pargs.web) and (not self.app.pargs.apache2) and (not self.app.pargs.php) and (not self.app.pargs.mysql)): self.app.pargs.web = True self.app.pargs.apache2 = True self.app.pargs.php = True self.app.pargs.mysql = True if self.app.pargs.all: self.app.pargs.web = True self.app.pargs.apache2 = True self.app.pargs.php = True self.app.pargs.mysql = True if self.app.pargs.web: self.app.pargs.apache2 = True self.app.pargs.php = True self.app.pargs.mysql = True #self.app.pargs.wpcli = True #self.app.pargs.postfix = True if self.app.pargs.apache2: Log.debug(self,"Removing apt_packages variable of Apache") apt_packages = apt_packages + SSSVariables.sss_apache if self.app.pargs.php: Log.debug(self,"Removing apt_packages variable of PHP") apt_packages = apt_packages + SSSVariables.sss_php if self.app.pargs.mysql: Log.debug(self,"Removing apt_packages variable of PHP") apt_packages = apt_packages + SSSVariables.sss_mysql packages = packages + ['/usr/bin/tuning-primer'] if len(packages) or len(apt_packages): sss_prompt = input('Are you sure you to want to' ' remove from server.' '\nPackage configuration will remain' ' on server after this operation.\n' 'Any answer other than ' '"yes" will be stop this' ' operation : ') if sss_prompt == 'YES' or sss_prompt == 'yes': if len(packages): SSSFileUtils.remove(self, packages) SSSAptGet.auto_remove(self) if len(apt_packages): Log.debug(self, "Removing apt_packages") Log.info(self, "Removing packages, please wait...") SSSAptGet.remove(self, apt_packages) SSSAptGet.auto_remove(self) Log.info(self, "Successfully removed packages")
def remove(self): """Start removal of packages""" apt_packages = [] packages = [] # Default action for stack remove if ((not self.app.pargs.web) and (not self.app.pargs.apache2) and (not self.app.pargs.php) and (not self.app.pargs.mysql)): self.app.pargs.web = True self.app.pargs.apache2 = True self.app.pargs.php = True self.app.pargs.mysql = True if self.app.pargs.all: self.app.pargs.web = True self.app.pargs.apache2 = True self.app.pargs.php = True self.app.pargs.mysql = True if self.app.pargs.web: self.app.pargs.apache2 = True self.app.pargs.php = True self.app.pargs.mysql = True #self.app.pargs.wpcli = True #self.app.pargs.postfix = True if self.app.pargs.apache2: Log.debug(self, "Removing apt_packages variable of Apache") apt_packages = apt_packages + SSSVariables.sss_apache if self.app.pargs.php: Log.debug(self, "Removing apt_packages variable of PHP") apt_packages = apt_packages + SSSVariables.sss_php if self.app.pargs.mysql: Log.debug(self, "Removing apt_packages variable of PHP") apt_packages = apt_packages + SSSVariables.sss_mysql packages = packages + ['/usr/bin/tuning-primer'] if len(packages) or len(apt_packages): sss_prompt = input('Are you sure you to want to' ' remove from server.' '\nPackage configuration will remain' ' on server after this operation.\n' 'Any answer other than ' '"yes" will be stop this' ' operation : ') if sss_prompt == 'YES' or sss_prompt == 'yes': if len(packages): SSSFileUtils.remove(self, packages) SSSAptGet.auto_remove(self) if len(apt_packages): Log.debug(self, "Removing apt_packages") Log.info(self, "Removing packages, please wait...") SSSAptGet.remove(self, apt_packages) SSSAptGet.auto_remove(self) Log.info(self, "Successfully removed packages")
def migrate_mariadb(self): # Backup all database SSSMysql.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) SSSRepo.add(self, repo_url=SSSVariables.sss_mysql_repo) Log.debug(self, "Adding key for {0}".format(SSSVariables.sss_mysql_repo)) SSSRepo.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" ) SSSShellExec.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", ) SSSShellExec.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 = SSSVariables.sss_mysql # If PHP is installed then install php5-mysql if SSSAptGet.is_installed(self, "php5-fpm"): apt_packages = apt_packages + ["php5-mysql"] # If mail server is installed then install dovecot-sql and postfix-sql if SSSAptGet.is_installed(self, "dovecot-core"): apt_packages = apt_packages + ["dovecot-mysql", "postfix-mysql", "libclass-dbi-mysql-perl"] Log.info(self, "Updating apt-cache, please wait...") SSSAptGet.update(self) Log.info(self, "Installing MariaDB, please wait...") SSSAptGet.remove(self, ["mysql-common", "libmysqlclient18"]) SSSAptGet.auto_remove(self) SSSAptGet.install(self, apt_packages) # Restart dovecot and postfix if installed if SSSAptGet.is_installed(self, "dovecot-core"): SSSService.restart_service(self, "dovecot") SSSService.restart_service(self, "postfix")
def purge(self): """Start purging of packages""" apt_packages = [] packages = [] # Default action for stack remove if ((not self.app.pargs.web) and (not self.app.pargs.apache2) and (not self.app.pargs.php) and (not self.app.pargs.mysql) and (not self.app.pargs.phpmyadmin)): self.app.pargs.web = True self.app.pargs.apache2 = True self.app.pargs.php = True self.app.pargs.mysql = True if self.app.pargs.all: self.app.pargs.web = True self.app.pargs.apache2 = True self.app.pargs.php = True self.app.pargs.mysql = True if self.app.pargs.web: self.app.pargs.apache2 = True self.app.pargs.php = True self.app.pargs.mysql = True #self.app.pargs.wpcli = True #self.app.pargs.postfix = True if self.app.pargs.apache2: Log.debug(self, "Purge apt_packages variable of Apache") apt_packages = apt_packages + SSSVariables.sss_apache if self.app.pargs.php: Log.debug(self, "Purge apt_packages variable PHP") apt_packages = apt_packages + SSSVariables.sss_php if self.app.pargs.mysql: Log.debug(self,"Removing apt_packages variable of PHP") apt_packages = apt_packages + SSSVariables.sss_mysql packages = packages + ['/usr/bin/tuning-primer'] if self.app.pargs.phpmyadmin: packages = packages + ['{0}22222/htdocs/db/pma'. format(SSSVariables.sss_webroot)] Log.debug(self, "Purge package variable phpMyAdmin") if len(packages) or len(apt_packages): sss_prompt = input('Are you sure you to want to purge ' 'from server ' 'along with their configuration' ' packages,\nAny answer other than ' '"yes" will be stop this ' 'operation :') if sss_prompt == 'YES' or sss_prompt == 'yes': if len(apt_packages): Log.info(self, "Purging packages, please wait...") SSSAptGet.remove(self, apt_packages, purge=True) SSSAptGet.auto_remove(self) if len(packages): SSSFileUtils.remove(self, packages) SSSAptGet.auto_remove(self) Log.info(self, "Successfully purged packages")
def migrate_mariadb(self): # Backup all database SSSMysql.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) SSSRepo.add(self, repo_url=SSSVariables.sss_mysql_repo) Log.debug(self, 'Adding key for {0}'.format(SSSVariables.sss_mysql_repo)) SSSRepo.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") SSSShellExec.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") SSSShellExec.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 = SSSVariables.sss_mysql # If PHP is installed then install php5-mysql if SSSAptGet.is_installed(self, "php5-fpm"): apt_packages = apt_packages + ["php5-mysql"] # If mail server is installed then install dovecot-sql and postfix-sql if SSSAptGet.is_installed(self, "dovecot-core"): apt_packages = apt_packages + [ "dovecot-mysql", "postfix-mysql", "libclass-dbi-mysql-perl" ] Log.info(self, "Updating apt-cache, please wait...") SSSAptGet.update(self) Log.info(self, "Installing MariaDB, please wait...") SSSAptGet.remove(self, ["mysql-common", "libmysqlclient18"]) SSSAptGet.auto_remove(self) SSSAptGet.install(self, apt_packages) # Restart dovecot and postfix if installed if SSSAptGet.is_installed(self, "dovecot-core"): SSSService.restart_service(self, 'dovecot') SSSService.restart_service(self, 'postfix')