Пример #1
0
    def migrate_mariadb(self):
        # Backup all database
        EEMysql.backupAll(self)

        # Add MariaDB repo
        Log.info(self, "Adding repository for MariaDB, please wait ...")

        mysql_pref = ("Package: *\nPin: origin mirror.aarnet.edu.au"
                      "\nPin-Priority: 1000\n")
        with open('/etc/apt/preferences.d/'
                  'MariaDB.pref', 'w') as mysql_pref_file:
            mysql_pref_file.write(mysql_pref)

        EERepo.add(self, repo_url=EEVariables.ee_mysql_repo)
        Log.debug(self, 'Adding key for {0}'
                  .format(EEVariables.ee_mysql_repo))
        EERepo.add_key(self, '0xcbcb082a1bb943db',
                       keyserver="keyserver.ubuntu.com")

        config = configparser.ConfigParser()
        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")
        EEShellExec.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")
        EEShellExec.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 = EEVariables.ee_mysql + ["php5-mysql"]
        Log.info(self, "Updating apt-cache, please wait ...")
        EEAptGet.update(self)
        Log.info(self, "Installing MariaDB, please wait ...")
        EEAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
        EEAptGet.auto_remove(self)
        EEAptGet.install(self, apt_packages)
Пример #2
0
    def upgrade_php56(self):
        if EEVariables.ee_platform_distro == "ubuntu":
            if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}."
                              "list".format(EEVariables.ee_platform_codename)):
                Log.error(self, "Unable to find PHP 5.5")
        else:
            if not (os.path.isfile(EEVariables.ee_repo_file_path)
                    and EEFileUtils.grep(self, EEVariables.ee_repo_file_path,
                                         "php55")):
                Log.error(self, "Unable to find PHP 5.5")

        Log.info(
            self, "During PHP update process non nginx-cached"
            " parts of your site may remain down.")

        # Check prompt
        if (not self.app.pargs.no_prompt):
            start_upgrade = input("Do you want to continue:[y/N]")
            if start_upgrade != "Y" and start_upgrade != "y":
                Log.error(self, "Not starting PHP package update")

        if EEVariables.ee_platform_distro == "ubuntu":
            EERepo.remove(self, ppa="ppa:ondrej/php5")
            EERepo.add(self, ppa=EEVariables.ee_php_repo)
        else:
            EEAptGet.remove(self, ["php5-xdebug"])
            EEFileUtils.searchreplace(self, EEVariables.ee_repo_file_path,
                                      "php55", "php56")

        Log.info(self, "Updating apt-cache, please wait...")
        EEAptGet.update(self)
        Log.info(self, "Installing packages, please wait ...")
        if (EEVariables.ee_platform_codename == 'trusty'
                or EEVariables.ee_platform_codename == 'xenial'
                or EEVariables.ee_platform_codename == 'bionic'):
            EEAptGet.install(self,
                             EEVariables.ee_php5_6 + EEVariables.ee_php_extra)
        else:
            EEAptGet.install(self, EEVariables.ee_php)

        if EEVariables.ee_platform_distro == "debian":
            EEShellExec.cmd_exec(self, "pecl install xdebug")

            with open("/etc/php5/mods-available/xdebug.ini",
                      encoding='utf-8',
                      mode='a') as myfile:
                myfile.write(";zend_extension=/usr/lib/php5/20131226/"
                             "xdebug.so\n")

            EEFileUtils.create_symlink(self, [
                "/etc/php5/mods-available/"
                "xdebug.ini", "/etc/php5/fpm/conf.d"
                "/20-xedbug.ini"
            ])

        Log.info(self, "Successfully upgraded from PHP 5.5 to PHP 5.6")
Пример #3
0
    def upgrade_php56(self):
        if EEVariables.ee_platform_distro == "ubuntu":
            if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}."
                              "list".format(EEVariables.ee_platform_codename)):
                Log.error(self, "Unable to find PHP 5.5")
        else:
            if not(os.path.isfile(EEVariables.ee_repo_file_path) and
                   EEFileUtils.grep(self, EEVariables.ee_repo_file_path,
                                    "php55")):
                Log.error(self, "Unable to find PHP 5.5")

        Log.info(self, "During PHP update process non nginx-cached"
                 " parts of your site may remain down.")

        # Check prompt
        if (not self.app.pargs.no_prompt):
            start_upgrade = input("Do you want to continue:[y/N]")
            if start_upgrade != "Y" and start_upgrade != "y":
                Log.error(self, "Not starting PHP package update")

        if EEVariables.ee_platform_distro == "ubuntu":
            EERepo.remove(self, ppa="ppa:ondrej/php5")
            EERepo.add(self, ppa=EEVariables.ee_php_repo)
        else:
            EEAptGet.remove(self, ["php5-xdebug"])
            EEFileUtils.searchreplace(self, EEVariables.ee_repo_file_path,
                                      "php55", "php56")

        Log.info(self, "Updating apt-cache, please wait...")
        EEAptGet.update(self)
        Log.info(self, "Installing packages, please wait ...")
        if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial'):
            EEAptGet.install(self, EEVariables.ee_php5_6 + EEVariables.ee_php_extra)
        else:
            EEAptGet.install(self, EEVariables.ee_php)

        if EEVariables.ee_platform_distro == "debian":
            EEShellExec.cmd_exec(self, "pecl install xdebug")

            with open("/etc/php5/mods-available/xdebug.ini",
                      encoding='utf-8', mode='a') as myfile:
                myfile.write(";zend_extension=/usr/lib/php5/20131226/"
                             "xdebug.so\n")

            EEFileUtils.create_symlink(self, ["/etc/php5/mods-available/"
                                       "xdebug.ini", "/etc/php5/fpm/conf.d"
                                                     "/20-xedbug.ini"])

        Log.info(self, "Successfully upgraded from PHP 5.5 to PHP 5.6")
Пример #4
0
    def update(self):
        """
        Similar to `apt-get update`
        """
        try:
            with open('/var/log/ee/ee.log', 'a') as f:
                proc = subprocess.Popen('apt-get update',
                                        shell=True,
                                        stdin=None,
                                        stdout=f,
                                        stderr=subprocess.PIPE,
                                        executable="/bin/bash")
                proc.wait()
                output, error_output = proc.communicate()

                # Check what is error in error_output
                if "NO_PUBKEY" in str(error_output):
                    # Split the output
                    Log.info(self, "Fixing missing GPG keys, please wait...")
                    error_list = str(error_output).split("\\n")

                    # Use a loop to add misising keys
                    for single_error in error_list:
                        if "NO_PUBKEY" in single_error:
                            key = single_error.rsplit(None, 1)[-1]
                            EERepo.add_key(self,
                                           key,
                                           keyserver="hkp://pgp.mit.edu")

                    proc = subprocess.Popen('apt-get update',
                                            shell=True,
                                            stdin=None,
                                            stdout=f,
                                            stderr=f,
                                            executable="/bin/bash")
                    proc.wait()

                if proc.returncode == 0:
                    return True
                else:
                    Log.info(self, Log.FAIL + "Oops Something went wrong!!")
                    Log.error(
                        self, "Check logs for reason "
                        "`tail /var/log/ee/ee.log` & Try Again!!!")

        except Exception as e:
            Log.error(self, "apt-get update exited with error")
Пример #5
0
    def update(self):
        """
        Similar to `apt-get update`
        """
        try:
            with open('/var/log/ee/ee.log', 'a') as f:
                proc = subprocess.Popen('apt-get update',
                                        shell=True,
                                        stdin=None, stdout=f,
                                        stderr=subprocess.PIPE,
                                        executable="/bin/bash")
                proc.wait()
                output, error_output = proc.communicate()

                # Check what is error in error_output
                if "NO_PUBKEY" in str(error_output):
                    # Split the output
                    Log.info(self, "Fixing missing GPG keys, please wait...")
                    error_list = str(error_output).split("\\n")

                    # Use a loop to add misising keys
                    for single_error in error_list:
                        if "NO_PUBKEY" in single_error:
                            key = single_error.rsplit(None, 1)[-1]
                            EERepo.add_key(self, key, keyserver="hkp://pgp.mit.edu")

                    proc = subprocess.Popen('apt-get update',
                                            shell=True,
                                            stdin=None, stdout=f, stderr=f,
                                            executable="/bin/bash")
                    proc.wait()

                if proc.returncode == 0:
                    return True
                else:
                    Log.info(self, Log.FAIL + "Oops Something went wrong!!")
                    Log.error(self, "Check logs for reason "
                              "`tail /var/log/ee/ee.log` & Try Again!!!")

        except Exception as e:
            Log.error(self, "apt-get update exited with error")
Пример #6
0
    def download_only(self,package_name,repo_url=None,repo_key=None):
        """
        Similar to `apt-get install --download-only PACKAGE_NAME`
        """
        packages = ' '.join(package_name)
        try:
            with open('/var/log/ee/ee.log', 'a') as f:
                if repo_url is not None:
                    EERepo.add(self, repo_url=repo_url)
                if repo_key is not None:
                    EERepo.add_key(self, repo_key)
                proc = subprocess.Popen("apt-get update && DEBIAN_FRONTEND=noninteractive "
                                        "apt-get install -o "
                                        "Dpkg::Options::=\"--force-confdef\""
                                        " -o "
                                        "Dpkg::Options::=\"--force-confold\""
                                        " -y  --download-only {0}"
                                        .format(packages), shell=True,
                                        stdin=None, stdout=f, stderr=f,
                                        executable="/bin/bash")
                proc.wait()

            if proc.returncode == 0:
                return True
            else:
                Log.error(self,"Error in fetching dpkg package.\nReverting changes ..",False)
                if repo_url is not None:
                    EERepo.remove(self, repo_url=repo_url)
                return False
        except Exception as e:
            Log.error(self, "Error while downloading packages, "
                      "apt-get exited with error")
Пример #7
0
    def migrate_mariadb(self):
        # Backup all database
        EEMysql.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)

        EERepo.add(self, repo_url=EEVariables.ee_mysql_repo)
        Log.debug(self, 'Adding key for {0}'
                  .format(EEVariables.ee_mysql_repo))
        EERepo.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")
        EEShellExec.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")
        EEShellExec.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 = EEVariables.ee_mysql

        # If PHP is installed then install php5-mysql
        if EEAptGet.is_installed(self, "php5-fpm"):
            apt_packages = apt_packages + ["php5-mysql"]

        # If mail server is installed then install dovecot-sql and postfix-sql
        if EEAptGet.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...")
        EEAptGet.update(self)
        Log.info(self, "Installing MariaDB, please wait...")
        EEAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
        EEAptGet.auto_remove(self)
        EEAptGet.install(self, apt_packages)

        # Restart  dovecot and postfix if installed
        if EEAptGet.is_installed(self, "dovecot-core"):
            EEService.restart_service(self, 'dovecot')
            EEService.restart_service(self, 'postfix')
Пример #8
0
    def migrate_mariadb(self):
        # Backup all database
        EEMysql.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)

        EERepo.add(self, repo_url=EEVariables.ee_mysql_repo)
        Log.debug(self, 'Adding key for {0}'.format(EEVariables.ee_mysql_repo))
        EERepo.add_key(self,
                       '0xF1656F24C74CD1D8',
                       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")
        EEShellExec.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")
        EEShellExec.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 = EEVariables.ee_mysql

        # If PHP is installed then install php5-mysql
        if EEAptGet.is_installed(self, "php5-fpm"):
            apt_packages = apt_packages + ["php5-mysql"]

        # If mail server is installed then install dovecot-sql and postfix-sql
        if EEAptGet.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...")
        EEAptGet.update(self)
        Log.info(self, "Installing MariaDB, please wait...")
        EEAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
        EEAptGet.auto_remove(self)
        EEAptGet.install(self, apt_packages)

        # Restart  dovecot and postfix if installed
        if EEAptGet.is_installed(self, "dovecot-core"):
            EEService.restart_service(self, 'dovecot')
            EEService.restart_service(self, 'postfix')