Beispiel #1
0
 def _enable_mysql(self):
     """
     Enable MySQL services
     """
     if 7 == self.cl_version:
         exec_command_out("systemctl enable mysql.service")
         exec_command_out("systemctl enable mysqld.service")
Beispiel #2
0
    def _delete(self, installed_packages):
        """
        Remove installed packages
        """
        # through mysql --version cmd
        current_version = self._check_mysql_version()

        if os.path.exists("/etc/chkserv.d/db_governor"):
            os.remove("/etc/chkserv.d/db_governor")
        self._script("chek_mysql_rpms_local", "-d")
        self._script("cpanel-delete-hooks")

        if os.path.exists("/etc/mysqlupdisable"):
            os.remove("/etc/mysqlupdisable")

        if os.path.exists("/var/cpanel/rpm.versions.d/cloudlinux.versions"):
            os.remove("/var/cpanel/rpm.versions.d/cloudlinux.versions")

        if os.path.exists("/etc/cpupdate.conf.governor"):
            if os.path.exists("/etc/cpupdate.conf"):
                os.remove("/etc/cpupdate.conf")
            os.rename("/etc/cpupdate.conf.governor", "/etc/cpupdate.conf")

        service("stop", "mysql")
        # remove governor package
        exec_command_out("rpm -e governor-mysql")
        # delete installed packages
        remove_packages(installed_packages)

        self.restore_mysql_packages(current_version)
        exec_command_out("/scripts/upcp --force")
Beispiel #3
0
    def _delete(self, installed_packages):
        """
        Remove installed packages and install new
        """
        print "Removing mysql for db_governor start"

        # download standard packages
        self._load_new_packages(False, "auto")

        # if not os.path.exists("/etc/my.cnf.bkp"):
        # shutil.copy2("/etc/my.cnf", "/etc/my.cnf.prev")
        self.my_cnf_manager('backup')  # why without if exists?

        self._mysqlservice("stop")

        # remove governor package
        exec_command_out("rpm -e governor-mysql")

        # delete installed packages
        remove_packages(installed_packages)

        # install auto packages
        install_packages("new", False)

        print "Removing mysql for db_governor completed"
Beispiel #4
0
 def _enable_mysql(self):
     """
     Enable MySQL services
     """
     if 7 == self.cl_version:
         exec_command_out("systemctl enable mysql.service")
         exec_command_out("systemctl enable mysqld.service")
Beispiel #5
0
    def download_and_install_mysql_repo(self):
        """
        Download mysql57-community-release repository and install it locally
        """
        # download repo file
        url = 'https://dev.mysql.com/get/mysql57-community-release-el{v}-11.noarch.rpm'.format(v=self.cl_version)
        repo_file = os.path.join(self.SOURCE, 'mysql-community-release.rpm')
        repo_md5 = {
            6: 'afe0706ac68155bf91ade1c55058fd78',
            7: 'c070b754ce2de9f714ab4db4736c7e05'
        }
        opener = urllib2.build_opener()
        opener.addheaders = [('User-agent', 'Mozilla/5.0')]

        print 'Downloading %s' % url
        rpm = opener.open(url).read()
        with open(repo_file, 'wb') as f:
            f.write(rpm)

        if hashlib.md5(open(repo_file, 'rb').read()).hexdigest() != repo_md5[self.cl_version]:
            print 'Failed to download MySQL repository file. File is corrupted!'
            sys.exit(2)

        # install repo
        exec_command_out('yum localinstall -y --disableexcludes=all {}'.format(repo_file))
Beispiel #6
0
    def _before_install_new_packages(self):
        """
        Specific actions before new packages installation
        """
        print "The installation of MySQL for db_governor has started"

        check_file("/usr/local/directadmin/custombuild/build")
        check_file("/usr/local/directadmin/custombuild/options.conf")

        # MYSQL_DA_TYPE=`cat /usr/local/directadmin/custombuild/options.conf | grep mysql_inst= | cut -d= -f2`
        try:
            MYSQL_DA_TYPE = grep("/usr/local/directadmin/custombuild/options.conf", "mysql_inst=")[0].split("=")[1]
        except IndexError:
            MYSQL_DA_TYPE = ""

        if os.path.exists("/usr/share/lve/dbgovernor/da.tp.old"):
            if MYSQL_DA_TYPE == "no":
                MYSQL_DA_TYPE = read_file("/usr/share/lve/dbgovernor/da.tp.old")
            else:
                write_file("/usr/share/lve/dbgovernor/da.tp.old", MYSQL_DA_TYPE)
        else:
            write_file("/usr/share/lve/dbgovernor/da.tp.old", MYSQL_DA_TYPE)

        exec_command_out("/usr/local/directadmin/custombuild/build set mysql_inst no")

        self._mysqlservice("stop")
Beispiel #7
0
    def _delete(self, installed_packages):
        """
        Remove installed packages and install new
        """
        print "Removing mysql for db_governor start"

        # download standard packages
        self._load_new_packages(False, "auto")

        # if not os.path.exists("/etc/my.cnf.bkp"):
        # shutil.copy2("/etc/my.cnf", "/etc/my.cnf.prev")
        self.my_cnf_manager('backup')  # why without if exists?

        self._mysqlservice("stop")

        # remove governor package
        exec_command_out("rpm -e governor-mysql")

        # delete installed packages
        remove_packages(installed_packages)

        # install auto packages
        install_packages("new", False)

        print "Removing mysql for db_governor completed"
Beispiel #8
0
 def enable_mysql_monitor(enable=True):
     """
     Enable or disable mysql monitoring
     :param enable: if True - enable monitor
                    if False - disable monitor
     """
     exec_command_out(
         "whmapi1 configureservice service=mysql enabled=1 monitored={}".format(int(enable)))
Beispiel #9
0
 def _kill_mysql():
     """
     Kill mysqld processes.
     """
     if check_mysqld_is_alive():
         print "Stop hunging MySQL"
         exec_command_out("/usr/bin/killall -SIGTERM mysqld_safe")
         print "Waiting for mysqld_safe stop"
         time.sleep(10)
         exec_command_out("/usr/bin/killall -SIGTERM mysqld")
         print "Waiting for mysqld stop"
         time.sleep(10)
Beispiel #10
0
 def _kill_mysql():
     """
     Kill mysqld processes.
     """
     if check_mysqld_is_alive():
         print "Stop hunging MySQL"
         exec_command_out("/usr/bin/killall -SIGTERM mysqld_safe")
         print "Waiting for mysqld_safe stop"
         time.sleep(10)
         exec_command_out("/usr/bin/killall -SIGTERM mysqld")
         print "Waiting for mysqld stop"
         time.sleep(10)
Beispiel #11
0
 def _custom_rpm_installer(self, package_name, indicator=False):
     """
     Specific package installer
     :param package_name:
     :param indicator:
     :return:
     """
     if not indicator:
         exec_command_out("/bin/rpm --ihv --force --nodeps %s" % package_name)
         return ""
     else:
         return "yes"
Beispiel #12
0
    def _ld_fix():
        """
        Fix shared library problems
        """
        if os.path.exists("/usr/lib64/mysql/libmygcc.a"):
            os.rename("/usr/lib64/mysql/libmygcc.a",
                      "/usr/lib64/mysql/libmygcc.a.bak")

        if os.path.exists("/usr/lib/mysql/libmygcc.a"):
            os.rename("/usr/lib/mysql/libmygcc.a",
                      "/usr/lib/mysql/libmygcc.a.bak")

        if os.path.exists("/sbin/ldconfig"):
            exec_command_out("/sbin/ldconfig")
Beispiel #13
0
    def _ld_fix():
        """
        Fix shared library problems
        """
        if os.path.exists("/usr/lib64/mysql/libmygcc.a"):
            os.rename("/usr/lib64/mysql/libmygcc.a",
                      "/usr/lib64/mysql/libmygcc.a.bak")

        if os.path.exists("/usr/lib/mysql/libmygcc.a"):
            os.rename("/usr/lib/mysql/libmygcc.a",
                      "/usr/lib/mysql/libmygcc.a.bak")

        if os.path.exists("/sbin/ldconfig"):
            exec_command_out("/sbin/ldconfig")
Beispiel #14
0
 def set_fs_suid_dumpable():
     """
     Run this code in spec file
     """
     print "Set FS suid_dumpable for governor to work correctly"
     exec_command_out("sysctl -w fs.suid_dumpable=1")
     if os.path.exists("/etc/sysctl.conf"):
         if not grep("/etc/sysctl.conf", "fs.suid_dumpable=1"):
             print "Add to /etc/sysctl.conf suid_dumpable instruction " \
                   "for governor to work correctly"
             shutil.copy("/etc/sysctl.conf", "/etc/sysctl.conf.bak")
             add_line("/etc/sysctl.conf", "fs.suid_dumpable=1")
         else:
             print "Everything is present in /etc/sysctl.conf " \
                   "for governor to work correctly"
     else:
         print "Create /etc/sysctl.conf for governor to work correctly"
         add_line("/etc/sysctl.conf", "fs.suid_dumpable=1")
Beispiel #15
0
 def set_fs_suid_dumpable():
     """
     Run this code in spec file
     """
     print "Set FS suid_dumpable for governor to work correctly"
     exec_command_out("sysctl -w fs.suid_dumpable=1")
     if os.path.exists("/etc/sysctl.conf"):
         if not grep("/etc/sysctl.conf", "fs.suid_dumpable=1"):
             print "Add to /etc/sysctl.conf suid_dumpable instruction " \
                   "for governor to work correctly"
             shutil.copy("/etc/sysctl.conf", "/etc/sysctl.conf.bak")
             add_line("/etc/sysctl.conf", "fs.suid_dumpable=1")
         else:
             print "Everything is present in /etc/sysctl.conf " \
                   "for governor to work correctly"
     else:
         print "Create /etc/sysctl.conf for governor to work correctly"
         add_line("/etc/sysctl.conf", "fs.suid_dumpable=1")
Beispiel #16
0
 def run_mysql_upgrade(self):
     """
     Run mysql_upgrade and mysql_fix_privilege_tables scripts if it is needed
     """
     print 'Check for the need of mysql_upgrade...'
     if self.check_need_for_mysql_upgrade():
         print 'Tables should be upgraded!'
         if self.MYSQLPASSWORD:
             cmd_upgrade = "/usr/bin/mysql_upgrade --user='******' --password='******'".format(user=self.MYSQLUSER, passwd=self.MYSQLPASSWORD)
             cmd_fix = "/usr/bin/mysql_fix_privilege_tables --user='******' --password='******'".format(user=self.MYSQLUSER, passwd=self.MYSQLPASSWORD)
         else:
             cmd_upgrade = '/usr/bin/mysql_upgrade'
             cmd_fix = '/usr/bin/mysql_fix_privilege_tables'
         exec_command_out(cmd_upgrade)
         if os.path.exists('/usr/bin/mysql_fix_privilege_tables'):
             exec_command_out(cmd_fix)
     else:
         print 'No need for upgrading tables'
Beispiel #17
0
 def run_mysql_upgrade(self):
     """
     Run mysql_upgrade and mysql_fix_privilege_tables scripts if it is needed
     """
     print 'Check for the need of mysql_upgrade...'
     if self.check_need_for_mysql_upgrade():
         print 'Tables should be upgraded!'
         if self.MYSQLPASSWORD:
             cmd_upgrade = "/usr/bin/mysql_upgrade --user='******' --password='******'".format(
                 user=self.MYSQLUSER, passwd=self.MYSQLPASSWORD)
             cmd_fix = "/usr/bin/mysql_fix_privilege_tables --user='******' --password='******'".format(
                 user=self.MYSQLUSER, passwd=self.MYSQLPASSWORD)
         else:
             cmd_upgrade = '/usr/bin/mysql_upgrade'
             cmd_fix = '/usr/bin/mysql_fix_privilege_tables'
         exec_command_out(cmd_upgrade)
         if os.path.exists('/usr/bin/mysql_fix_privilege_tables'):
             exec_command_out(cmd_fix)
     else:
         print 'No need for upgrading tables'
Beispiel #18
0
    def _after_install_new_packages(self):
        """
        cPanel triggers after install new packages to system
        """
        # cpanel script for restart mysql service
        exec_command_out("/scripts/restartsrv_mysql")

        print "db_governor checking: "
        if is_package_installed("governor-mysql"):
            exec_command_out("chkconfig --level 35 db_governor on")
            service("restart", "db_governor")
            print "OK"
        else:
            print "FAILED"

        # print "The installation of MySQL for db_governor completed"

        if os.path.exists("/usr/local/cpanel/cpanel"):
            if os.path.exists(
                    "/usr/local/cpanel/scripts/update_local_rpm_versions"):
                shutil.copy2(self._rel("utils/cloudlinux.versions"), "/var/cpanel/rpm.versions.d/cloudlinux.versions")
            else:
                if not os.path.exists("/etc/cpupdate.conf.governor"):
                    self._get_mysqlup()
                touch("/etc/mysqlupdisable")

        self._script("cpanel-install-hooks")

        if os.path.exists("/usr/local/cpanel/cpanel") and \
                os.path.exists(
                    "/usr/local/cpanel/scripts/update_local_rpm_versions"):
            if os.path.exists("/etc/mysqlupdisable"):
                os.unlink("/etc/mysqlupdisable")
            remove_lines("/etc/cpupdate.conf", "MYSQLUP=never")
        if os.path.exists("/etc/chkserv.d") and os.path.exists(
                self._rel("utils/db_governor")):
            shutil.copy2(self._rel("utils/db_governor"),
                         "/etc/chkserv.d/db_governor")
        # call parent after_install
        InstallManager._after_install_new_packages(self)
Beispiel #19
0
 def _enable_mariadb(self):
     """
     Enable mariaDB services
     """
     if 7 == self.cl_version:
         exec_command_out("systemctl enable mariadb.service")
         exec_command_out("systemctl enable mysql.service")
         exec_command_out("systemctl enable mysqld.service")
Beispiel #20
0
 def _enable_mariadb(self):
     """
     Enable mariaDB services
     """
     if 7 == self.cl_version:
         exec_command_out("systemctl enable mariadb.service")
         exec_command_out("systemctl enable mysql.service")
         exec_command_out("systemctl enable mysqld.service")
Beispiel #21
0
    def restore_mysql_packages(self, current_version):
        """
        Install legacy packages after --delete procedure
        """
        print 'Restoring known packages for {}'.format(current_version['full'])
        targets = {
            'mysql55': 'MySQL55',
            'mysql56': 'MySQL56',
            'mariadb100': 'MariaDB100',
            'mariadb101': 'MariaDB101',
            'mariadb102': 'MariaDB102',
        }
        # clear rpm management for all known targets
        for t in targets.values():
            exec_command('/usr/local/cpanel/scripts/update_local_rpm_versions --del target_settings.%(target)s' % {'target': t})
        # disable mysql targets for upcp not to fix them!
        for k in filter(lambda x: 'mariadb' not in x and x != current_version['full'], targets.keys()):
            exec_command('/usr/local/cpanel/scripts/update_local_rpm_versions --edit target_settings.%(target)s uninstalled' % {'target': targets[k]})

        if current_version['mysql_type'] == 'mariadb':
            # add repo, yum install mariadb pkgs
            self.install_mariadb(current_version['full'])
        elif current_version['full'] == 'mysql57':
            # add repo, yum install mysql57
            self.install_mysql57(current_version['full'])
            # create mysql alias for mysqld service
            self.mysql_service_symlink()
        else:
            # enable current mysql target to rpm management
            t = targets.get(current_version['full'])
            if not t:
                raise RuntimeError('unknown target for RPM management: {}'.format(current_version['full']))
            exec_command('/usr/local/cpanel/scripts/update_local_rpm_versions --edit target_settings.%(target)s installed' % {'target': t})
            # fix legacy RPMs (works for mysql55 and mysql56 only)
            if os.path.exists("/scripts/check_cpanel_rpms"):
                exec_command_out("/scripts/check_cpanel_rpms --fix --targets="
                                 "MySQL50,MySQL51,MySQL55,MySQL56,MariaDB,"
                                 "MariaDB100,MariaDB101")
Beispiel #22
0
    def _delete(self, installed_packages):
        """
        Remove installed packages
        """
        check_file("/usr/local/directadmin/custombuild/build")

        print "Removing mysql for db_governor start"

        self._mysqlservice("stop")
        # remove governor package
        exec_command_out("rpm -e governor-mysql")
        # delete installed packages
        remove_packages(installed_packages)

        param = "mysql"
        if os.path.exists("/usr/share/lve/dbgovernor/da.tp.old"):
            param = read_file("/usr/share/lve/dbgovernor/da.tp.old")

        exec_command_out("/usr/local/directadmin/custombuild/build set mysql_inst %s" % param)
        exec_command_out("/usr/local/directadmin/custombuild/build mysql update")

        print "Removing mysql for db_governor completed"
Beispiel #23
0
 def _enable_percona(self):
     """
     Enable Percona service
     """
     if 7 == self.cl_version:
         exec_command_out("systemctl enable mysql.service")
Beispiel #24
0
        repo_url = "http://repo.cloudlinux.com/other/cl%s/mysqlmeta/%s" % (
            self.cl_version, repo)
        try:
            content = urllib2.urlopen(repo_url).read()
        except Exception, e:
            print >> sys.stderr, "Can`t download repo file: %s" % e
            sys.exit(2)
        else:
            if os.path.exists("/etc/yum.repos.d/cl-mysql.repo"):
                shutil.copy2("/etc/yum.repos.d/cl-mysql.repo",
                             "/etc/yum.repos.d/cl-mysql.repo.bak")
            write_file("/etc/yum.repos.d/cl-mysql.repo", content)

        # update repositories
        exec_command_out("yum clean all")

        # Add requires to packages list
        for name in requires:
            # query only for non-installed packages
            packages += exec_command("repoquery --requires %s" % name)
            # query for installed package
            # exec_command("rpm -q --requires cl-MySQL-meta")

        if not download_packages(packages, folder, beta):
            self.ALL_PACKAGES_NEW_NOT_DOWNLOADED = True

        return packages

    def get_mysql_user(self):
        """
Beispiel #25
0
 def _script(self, path, args=None):
     """
     Execute package script which locate in SOURCE directory
     """
     exec_command_out("%s %s" %
                      (self._rel("scripts/%s" % path), args or ""))
Beispiel #26
0
        repo_url = "http://repo.cloudlinux.com/other/cl%s/mysqlmeta/%s" % (
            self.cl_version, repo)
        try:
            content = urllib2.urlopen(repo_url).read()
        except Exception, e:
            print >> sys.stderr, "Can`t download repo file: %s" % e
            sys.exit(2)
        else:
            if os.path.exists("/etc/yum.repos.d/cl-mysql.repo"):
                shutil.copy2("/etc/yum.repos.d/cl-mysql.repo",
                             "/etc/yum.repos.d/cl-mysql.repo.bak")
            write_file("/etc/yum.repos.d/cl-mysql.repo", content)

        # update repositories
        exec_command_out("yum clean all")

        # Add requires to packages list
        for name in requires:
            # query only for non-installed packages
            packages += exec_command("repoquery --requires %s" % name)
            # query for installed package
            # exec_command("rpm -q --requires cl-MySQL-meta")

        if not download_packages(packages, folder, beta):
            self.ALL_PACKAGES_NEW_NOT_DOWNLOADED = True

        return packages

    def get_mysql_user(self):
        """
Beispiel #27
0
 def _enable_percona(self):
     """
     Enable Percona service
     """
     if 7 == self.cl_version:
         exec_command_out("systemctl enable mysql.service")
Beispiel #28
0
 def _script(self, path, args=None):
     """
     Execute package script which locate in SOURCE directory
     """
     exec_command_out("%s %s" % (self._rel("scripts/%s" % path), args or ""))