Ejemplo n.º 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)
Ejemplo n.º 2
0
    def default(self):
        """Default function of log reset"""
        self.msg = []

        if self.app.pargs.php:
            self.app.pargs.nginx = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp) and (not self.app.pargs.site_name)
                and (not self.app.pargs.slow_log_db)):
            self.app.pargs.nginx = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.access = True
            self.app.pargs.slow_log_db = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp) and (self.app.pargs.site_name)
                and (not self.app.pargs.slow - log - db)):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.access = True
            self.app.pargs.mysql = True

        if self.app.pargs.slow_log_db:
            if os.path.isdir("/var/www/22222/htdocs/db/anemometer"):
                Log.info(self, "Resetting MySQL slow_query_log database table")
                EEMysql.execute(
                    self, "TRUNCATE TABLE  "
                    "slow_query_log.global_query_review_history")
                EEMysql.execute(
                    self, "TRUNCATE TABLE "
                    "slow_query_log.global_query_review")

        if self.app.pargs.nginx and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*error.log"]

        if self.app.pargs.access and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*access.log"]

        if self.app.pargs.fpm:
            open('/var/log/php5/slow.log', 'a').close()
            open('/var/log/php5/fpm.log', 'a').close()
            self.msg = self.msg + [
                '/var/log/php5/slow.log', '/var/log/php5/fpm.log'
            ]
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                if os.path.isfile('/var/log/mysql/mysql-slow.log'):
                    self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
                else:
                    Log.info(self, "MySQL slow-log not found, skipped")
            else:
                Log.warn(
                    self, "Remote MySQL found, EasyEngine is not able to"
                    "show MySQL log file")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(EEVariables.ee_webroot,
                                      self.app.pargs.site_name)

            if not os.path.isdir(webroot):
                Log.error(self, "Site not present, quitting")
            if self.app.pargs.access:
                self.msg = self.msg + [
                    "{0}/{1}/logs/access.log".format(EEVariables.ee_webroot,
                                                     self.app.pargs.site_name)
                ]
            if self.app.pargs.nginx:
                self.msg = self.msg + [
                    "{0}/{1}/logs/error.log".format(EEVariables.ee_webroot,
                                                    self.app.pargs.site_name)
                ]
            if self.app.pargs.wp:
                if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
                    if not os.path.isfile(
                            '{0}/logs/debug.log'.format(webroot)):
                        if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
                                              .format(webroot)):
                            open("{0}/htdocs/wp-content/debug.log".format(
                                webroot),
                                 encoding='utf-8',
                                 mode='a').close()
                            EEShellExec.cmd_exec(
                                self, "chown {1}: {0}/htdocs/"
                                "wp-content/debug.log"
                                "".format(webroot, EEVariables.ee_php_user))
                    # create symbolic link for debug log
                    EEFileUtils.create_symlink(self, [
                        "{0}/htdocs/wp-content/"
                        "debug.log".format(webroot),
                        '{0}/logs/debug.log'.format(webroot)
                    ])

                    self.msg = self.msg + [
                        "{0}/{1}/logs/debug.log".format(
                            EEVariables.ee_webroot, self.app.pargs.site_name)
                    ]
                else:
                    Log.info(
                        self, "Site is not WordPress site, skipping "
                        "WordPress logs")

        reset_list = []
        for r_list in self.msg:
            reset_list = reset_list + glob.glob(r_list)

        # Clearing content of file
        for r_list in reset_list:
            Log.info(self, "Resetting file {file}".format(file=r_list))
            open(r_list, 'w').close()
Ejemplo n.º 3
0
    def debug_mysql(self):
        """Start/Stop MySQL debug"""
        # MySQL start global debug
        if self.start:
            if not EEShellExec.cmd_exec(self, "mysql -e \"show variables like"
                                              " \'slow_query_log\';\" | "
                                              "grep ON"):
                Log.info(self, "Setting up MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = "
                                      "\'ON\';")
                EEMysql.execute(self, "set global slow_query_log_file = "
                                      "\'/var/log/mysql/mysql-slow.log\';")
                EEMysql.execute(self, "set global long_query_time = 2;")
                EEMysql.execute(self, "set global log_queries_not_using"
                                      "_indexes = \'ON\';")
                if self.app.pargs.interval:
                    try:
                        cron_time = int(self.app.pargs.interval)
                    except Exception as e:
                        cron_time = 5
                    EEShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l 2> "
                                         "/dev/null | {{ cat; echo -e"
                                         " \\\"#EasyEngine start MySQL slow"
                                         " log \\n*/{0} * * * * "
                                         "/usr/local/sbin/ee import-slow-log\\"
                                         "n#EasyEngine end MySQL slow log\\\";"
                                         " }} | crontab -\"".format(cron_time))
            else:
                Log.info(self, "MySQL slow log is already enabled")

            self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']

        # MySQL stop global debug
        else:
            if EEShellExec.cmd_exec(self, "mysql -e \"show variables like \'"
                                    "slow_query_log\';\" | grep ON"):
                Log.info(self, "Disabling MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = \'OFF\';")
                EEMysql.execute(self, "set global slow_query_log_file = \'"
                                "/var/log/mysql/mysql-slow.log\';")
                EEMysql.execute(self, "set global long_query_time = 10;")
                EEMysql.execute(self, "set global log_queries_not_using_index"
                                "es = \'OFF\';")
                EEShellExec.cmd_exec(self, "crontab -l | sed \'/#EasyEngine "
                                     "start/,/#EasyEngine end/d\' | crontab -")
            else:
                Log.info(self, "MySQL slow log already disabled")
Ejemplo n.º 4
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')
Ejemplo n.º 5
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')
Ejemplo n.º 6
0
    def debug_mysql(self):
        """Start/Stop MySQL debug"""
        # MySQL start global debug
        if (self.app.pargs.mysql == 'on' and not self.app.pargs.site_name):
            if not EEShellExec.cmd_exec(self, "mysql -e \"show variables like"
                                              " \'slow_query_log\';\" | "
                                              "grep ON"):
                Log.info(self, "Setting up MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = "
                                      "\'ON\';")
                EEMysql.execute(self, "set global slow_query_log_file = "
                                      "\'/var/log/mysql/mysql-slow.log\';")
                EEMysql.execute(self, "set global long_query_time = 2;")
                EEMysql.execute(self, "set global log_queries_not_using"
                                      "_indexes = \'ON\';")
            else:
                Log.info(self, "MySQL slow log is already enabled")

            self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']

        # MySQL stop global debug
        elif (self.app.pargs.mysql == 'off' and not self.app.pargs.site_name):
            if EEShellExec.cmd_exec(self, "mysql -e \"show variables like \'"
                                    "slow_query_log\';\" | grep ON"):
                Log.info(self, "Disabling MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = \'OFF\';")
                EEMysql.execute(self, "set global slow_query_log_file = \'"
                                "/var/log/mysql/mysql-slow.log\';")
                EEMysql.execute(self, "set global long_query_time = 10;")
                EEMysql.execute(self, "set global log_queries_not_using_index"
                                "es = \'OFF\';")
                EEShellExec.cmd_exec(self, "crontab -l | sed \'/#EasyEngine "
                                     "start/,/#EasyEngine end/d\' | crontab -")
            else:
                Log.info(self, "MySQL slow log already disabled")
Ejemplo n.º 7
0
    def debug_mysql(self):
        """Start/Stop MySQL debug"""
        # MySQL start global debug
        if (self.app.pargs.mysql == 'on' and not self.app.pargs.site_name):
            if not EEShellExec.cmd_exec(self, "mysql -e \"show variables like"
                                              " \'slow_query_log\';\" | "
                                              "grep ON"):
                Log.info(self, "Setting up MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = "
                                      "\'ON\';")
                EEMysql.execute(self, "set global slow_query_log_file = "
                                      "\'/var/log/mysql/mysql-slow.log\';")
                EEMysql.execute(self, "set global long_query_time = 2;")
                EEMysql.execute(self, "set global log_queries_not_using"
                                      "_indexes = \'ON\';")
                if self.app.pargs.interval:
                    try:
                        cron_time = int(self.app.pargs.interval)
                    except Exception as e:
                        cron_time = 5

                    EEShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l "
                                         "2> /dev/null | {{ cat; echo -e"
                                         " \\\"#EasyEngine start MySQL "
                                         "slow log \\n*/{0} * * * * "
                                         "/usr/local/bin/ee "
                                         "import-slow-log\\n"
                                         "#EasyEngine end MySQL slow log"
                                         "\\\"; }} | crontab -\""
                                         .format(cron_time))
            else:
                Log.info(self, "MySQL slow log is already enabled")

            self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']

        # MySQL stop global debug
        elif (self.app.pargs.mysql == 'off' and not self.app.pargs.site_name):
            if EEShellExec.cmd_exec(self, "mysql -e \"show variables like \'"
                                    "slow_query_log\';\" | grep ON"):
                Log.info(self, "Disabling MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = \'OFF\';")
                EEMysql.execute(self, "set global slow_query_log_file = \'"
                                "/var/log/mysql/mysql-slow.log\';")
                EEMysql.execute(self, "set global long_query_time = 10;")
                EEMysql.execute(self, "set global log_queries_not_using_index"
                                "es = \'OFF\';")
                EEShellExec.cmd_exec(self, "crontab -l | sed \'/#EasyEngine "
                                     "start/,/#EasyEngine end/d\' | crontab -")
            else:
                Log.info(self, "MySQL slow log already disabled")
Ejemplo n.º 8
0
    def debug_mysql(self):
        """Start/Stop MySQL debug"""
        # MySQL start global debug
        if self.start:
            if not EEShellExec.cmd_exec(self, 'mysql -e "show variables like' " 'slow_query_log';\" | " "grep ON"):
                Log.info(self, "Setting up MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = " "'ON';")
                EEMysql.execute(self, "set global slow_query_log_file = " "'/var/log/mysql/mysql-slow.log';")
                EEMysql.execute(self, "set global long_query_time = 2;")
                EEMysql.execute(self, "set global log_queries_not_using" "_indexes = 'ON';")
                if self.app.pargs.interval:
                    try:
                        cron_time = int(self.app.pargs.interval)
                    except Exception as e:
                        cron_time = 5

                    EEShellExec.cmd_exec(
                        self,
                        '/bin/bash -c "crontab -l '
                        "2> /dev/null | {{ cat; echo -e"
                        ' \\"#EasyEngine start MySQL '
                        "slow log \\n*/{0} * * * * "
                        "/usr/local/bin/ee "
                        "import-slow-log\\n"
                        "#EasyEngine end MySQL slow log"
                        '\\"; }} | crontab -"'.format(cron_time),
                    )
            else:
                Log.info(self, "MySQL slow log is already enabled")

            self.msg = self.msg + ["/var/log/mysql/mysql-slow.log"]

        # MySQL stop global debug
        else:
            if EEShellExec.cmd_exec(self, "mysql -e \"show variables like '" "slow_query_log';\" | grep ON"):
                Log.info(self, "Disabling MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = 'OFF';")
                EEMysql.execute(self, "set global slow_query_log_file = '" "/var/log/mysql/mysql-slow.log';")
                EEMysql.execute(self, "set global long_query_time = 10;")
                EEMysql.execute(self, "set global log_queries_not_using_index" "es = 'OFF';")
                EEShellExec.cmd_exec(self, "crontab -l | sed '/#EasyEngine " "start/,/#EasyEngine end/d' | crontab -")
            else:
                Log.info(self, "MySQL slow log already disabled")
Ejemplo n.º 9
0
    def debug_mysql(self):
        """Start/Stop MySQL debug"""
        # MySQL start global debug
        if (self.app.pargs.mysql == 'on' and not self.app.pargs.site_name):
            if not EEShellExec.cmd_exec(
                    self, "mysql -e \"show variables like"
                    " \'slow_query_log\';\" | "
                    "grep ON"):
                Log.info(self, "Setting up MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = " "\'ON\';")
                EEMysql.execute(
                    self, "set global slow_query_log_file = "
                    "\'/var/log/mysql/mysql-slow.log\';")
                EEMysql.execute(self, "set global long_query_time = 2;")
                EEMysql.execute(
                    self, "set global log_queries_not_using"
                    "_indexes = \'ON\';")
            else:
                Log.info(self, "MySQL slow log is already enabled")

            self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']

        # MySQL stop global debug
        elif (self.app.pargs.mysql == 'off' and not self.app.pargs.site_name):
            if EEShellExec.cmd_exec(
                    self, "mysql -e \"show variables like \'"
                    "slow_query_log\';\" | grep ON"):
                Log.info(self, "Disabling MySQL slow log")
                EEMysql.execute(self, "set global slow_query_log = \'OFF\';")
                EEMysql.execute(
                    self, "set global slow_query_log_file = \'"
                    "/var/log/mysql/mysql-slow.log\';")
                EEMysql.execute(self, "set global long_query_time = 10;")
                EEMysql.execute(
                    self, "set global log_queries_not_using_index"
                    "es = \'OFF\';")
                EEShellExec.cmd_exec(
                    self, "crontab -l | sed \'/#EasyEngine "
                    "start/,/#EasyEngine end/d\' | crontab -")
            else:
                Log.info(self, "MySQL slow log already disabled")
Ejemplo n.º 10
0
    def default(self):
        """Default function of log reset"""
        self.msg = []

        if self.app.pargs.php:
            self.app.pargs.nginx = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
           and (not self.app.pargs.mysql) and (not self.app.pargs.access)
           and (not self.app.pargs.wp) and (not self.app.pargs.site_name)
           and (not self.app.pargs.slow_log_db)):
            self.app.pargs.nginx = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.access = True
            self.app.pargs.slow_log_db = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
           and (not self.app.pargs.mysql) and (not self.app.pargs.access)
           and (not self.app.pargs.wp) and (self.app.pargs.site_name)
           and (not self.app.pargs.slow-log-db)):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.access = True
            self.app.pargs.mysql = True

        if self.app.pargs.slow_log_db:
            if os.path.isdir("/var/www/22222/htdocs/db/anemometer"):
                Log.info(self, "Resetting MySQL slow_query_log database table")
                EEMysql.execute(self, "TRUNCATE TABLE  "
                                "slow_query_log.global_query_review_history")
                EEMysql.execute(self, "TRUNCATE TABLE "
                                "slow_query_log.global_query_review")

        if self.app.pargs.nginx and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*error.log"]

        if self.app.pargs.access and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*access.log"]

        if self.app.pargs.fpm:
            open('/var/log/php5/slow.log', 'a').close()
            open('/var/log/php5/fpm.log', 'a').close()
            self.msg = self.msg + ['/var/log/php5/slow.log',
                                   '/var/log/php5/fpm.log']
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                if os.path.isfile('/var/log/mysql/mysql-slow.log'):
                    self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
                else:
                    Log.info(self, "MySQL slow-log not found, skipped")
            else:
                Log.warn(self, "Remote MySQL found, EasyEngine is not able to"
                         "show MySQL log file")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(EEVariables.ee_webroot,
                                      self.app.pargs.site_name)

            if not os.path.isdir(webroot):
                Log.error(self, "Site not present, quitting")
            if self.app.pargs.access:
                self.msg = self.msg + ["{0}/{1}/logs/access.log"
                                       .format(EEVariables.ee_webroot,
                                               self.app.pargs.site_name)]
            if self.app.pargs.nginx:
                self.msg = self.msg + ["{0}/{1}/logs/error.log"
                                       .format(EEVariables.ee_webroot,
                                               self.app.pargs.site_name)]
            if self.app.pargs.wp:
                if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
                    if not os.path.isfile('{0}/logs/debug.log'
                                          .format(webroot)):
                        if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
                                              .format(webroot)):
                            open("{0}/htdocs/wp-content/debug.log"
                                 .format(webroot),
                                 encoding='utf-8', mode='a').close()
                            EEShellExec.cmd_exec(self, "chown {1}: {0}/htdocs/"
                                                 "wp-content/debug.log"
                                                 "".format(webroot,
                                                           EEVariables
                                                           .ee_php_user)
                                                 )
                    # create symbolic link for debug log
                    EEFileUtils.create_symlink(self, ["{0}/htdocs/wp-content/"
                                                      "debug.log"
                                                      .format(webroot),
                                                      '{0}/logs/debug.log'
                                                      .format(webroot)])

                    self.msg = self.msg + ["{0}/{1}/logs/debug.log"
                                           .format(EEVariables.ee_webroot,
                                                   self.app.pargs.site_name)]
                else:
                    Log.info(self, "Site is not WordPress site, skipping "
                             "WordPress logs")

        reset_list = []
        for r_list in self.msg:
            reset_list = reset_list + glob.glob(r_list)

        # Clearing content of file
        for r_list in reset_list:
            Log.info(self, "Resetting file {file}".format(file=r_list))
            open(r_list, 'w').close()
Ejemplo n.º 11
0
def setupdatabase(self, data):
    ee_domain_name = data['site_name']
    ee_random = (''.join(
        random.sample(
            string.ascii_uppercase + string.ascii_lowercase + string.digits,
            15)))
    ee_replace_dot = ee_domain_name.replace('.', '_')
    prompt_dbname = self.app.config.get('mysql', 'db-name')
    prompt_dbuser = self.app.config.get('mysql', 'db-user')
    ee_mysql_grant_host = self.app.config.get('mysql', 'grant-host')
    ee_db_name = ''
    ee_db_username = ''
    ee_db_password = ''

    if prompt_dbname == 'True' or prompt_dbname == 'true':
        try:
            ee_db_name = input(
                'Enter the MySQL database name [{0}]: '.format(ee_replace_dot))
        except EOFError as e:
            Log.debug(self, "{0}".format(e))
            Log.error(self, "Unable to input database name")

    if not ee_db_name:
        ee_db_name = ee_replace_dot

    if prompt_dbuser == 'True' or prompt_dbuser == 'true':
        try:
            ee_db_username = input(
                'Enter the MySQL database user name [{0}]: '.format(
                    ee_replace_dot))
            ee_db_password = getpass.getpass(
                prompt='Enter the MySQL database'
                ' password [{0}]: '.format(ee_random))
        except EOFError as e:
            Log.debug(self, "{0}".format(e))
            Log.error(self, "Unable to input database credentials")

    if not ee_db_username:
        ee_db_username = ee_replace_dot
    if not ee_db_password:
        ee_db_password = ee_random

    if len(ee_db_username) > 16:
        Log.debug(
            self, 'Autofix MySQL username (ERROR 1470 (HY000)),'
            ' please wait')
        ee_random10 = (''.join(
            random.sample(
                string.ascii_uppercase + string.ascii_lowercase +
                string.digits, 10)))
        ee_db_username = (ee_db_name[0:6] + ee_random10)
    # create MySQL database
    Log.info(self, "Setting up database\t\t", end='')
    Log.debug(self, "Creating databse {0}".format(ee_db_name))
    EEMysql.execute(self,
                    "create database `{0}`".format(ee_db_name),
                    errormsg="Cannot create database")

    # Create MySQL User
    Log.debug(self, "Creating user {0}".format(ee_db_username))
    Log.debug(
        self, "create user `{0}`@`{1}` identified by ''".format(
            ee_db_username, ee_mysql_grant_host))
    EEMysql.execute(self,
                    "create user `{0}`@`{1}` identified by '{2}'".format(
                        ee_db_username, ee_mysql_grant_host, ee_db_password),
                    errormsg="Cannot setup database user",
                    log=False)

    # Grant permission
    Log.debug(self, "Setting up user privileges")
    EEMysql.execute(self,
                    "grant all privileges on `{0}`.* to `{1}`@`{2}`".format(
                        ee_db_name, ee_db_username, ee_mysql_grant_host),
                    errormsg="Cannot setup database user privileges")
    Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")

    data['ee_db_name'] = ee_db_name
    data['ee_db_user'] = ee_db_username
    data['ee_db_pass'] = ee_db_password
    data['ee_db_host'] = EEVariables.ee_mysql_host
    return (data)
Ejemplo n.º 12
0
def setupdatabase(self, data):
    ee_domain_name = data['site_name']
    ee_random = (''.join(random.sample(string.ascii_uppercase +
                 string.ascii_lowercase + string.digits, 15)))
    ee_replace_dot = ee_domain_name.replace('.', '_')
    prompt_dbname = self.app.config.get('mysql', 'db-name')
    prompt_dbuser = self.app.config.get('mysql', 'db-user')
    ee_mysql_grant_host = self.app.config.get('mysql', 'grant-host')
    ee_db_name = ''
    ee_db_username = ''
    ee_db_password = ''

    if prompt_dbname == 'True' or prompt_dbname == 'true':
        try:
            ee_db_name = input('Enter the MySQL database name [{0}]: '
                               .format(ee_replace_dot))
        except EOFError as e:
            Log.debug(self, "{0}".format(e))
            Log.error(self, "Unable to input database name")

    if not ee_db_name:
        ee_db_name = ee_replace_dot

    if prompt_dbuser == 'True' or prompt_dbuser == 'true':
        try:
            ee_db_username = input('Enter the MySQL database user name [{0}]: '
                                   .format(ee_replace_dot))
            ee_db_password = getpass.getpass(prompt='Enter the MySQL database'
                                             ' password [{0}]: '
                                             .format(ee_random))
        except EOFError as e:
            Log.debug(self, "{0}".format(e))
            Log.error(self, "Unable to input database credentials")

    if not ee_db_username:
        ee_db_username = ee_replace_dot
    if not ee_db_password:
        ee_db_password = ee_random

    if len(ee_db_username) > 16:
        Log.debug(self, 'Autofix MySQL username (ERROR 1470 (HY000)),'
                  ' please wait')
        ee_random10 = (''.join(random.sample(string.ascii_uppercase +
                       string.ascii_lowercase + string.digits, 10)))
        ee_db_username = (ee_db_name[0:6] + ee_random10)
    # create MySQL database
    Log.info(self, "Setting up database\t\t", end='')
    Log.debug(self, "Creating databse {0}".format(ee_db_name))
    EEMysql.execute(self, "create database `{0}`"
                    .format(ee_db_name), errormsg="Cannot create database")

    # Create MySQL User
    Log.debug(self, "Creating user {0}".format(ee_db_username))
    Log.debug(self, "create user `{0}`@`{1}` identified by ''"
              .format(ee_db_username, ee_mysql_grant_host))
    EEMysql.execute(self,
                    "create user `{0}`@`{1}` identified by '{2}'"
                    .format(ee_db_username, ee_mysql_grant_host,
                            ee_db_password),
                    errormsg="Cannot setup database user", log=False)

    # Grant permission
    Log.debug(self, "Setting up user privileges")
    EEMysql.execute(self,
                    "grant all privileges on `{0}`.* to `{1}`@`{2}`"
                    .format(ee_db_name, ee_db_username, ee_mysql_grant_host),
                    errormsg="Cannot setup database user privileges")
    Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")

    data['ee_db_name'] = ee_db_name
    data['ee_db_user'] = ee_db_username
    data['ee_db_pass'] = ee_db_password
    data['ee_db_host'] = EEVariables.ee_mysql_host
    return(data)