Пример #1
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 WOShellExec.cmd_exec(
                    self, "mysql -e \"show variables like"
                    " \'slow_query_log\';\" | "
                    "grep ON"):
                Log.info(self, "Setting up MySQL slow log")
                WOMysql.execute(self, "set global slow_query_log = " "\'ON\';")
                WOMysql.execute(
                    self, "set global slow_query_log_file = "
                    "\'/var/log/mysql/mysql-slow.log\';")
                WOMysql.execute(self, "set global long_query_time = 2;")
                WOMysql.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 WOShellExec.cmd_exec(
                    self, "mysql -e \"show variables like \'"
                    "slow_query_log\';\" | grep ON"):
                Log.info(self, "Disabling MySQL slow log")
                WOMysql.execute(self, "set global slow_query_log = \'OFF\';")
                WOMysql.execute(
                    self, "set global slow_query_log_file = \'"
                    "/var/log/mysql/mysql-slow.log\';")
                WOMysql.execute(self, "set global long_query_time = 10;")
                WOMysql.execute(
                    self, "set global log_queries_not_using_index"
                    "es = \'OFF\';")
                WOShellExec.cmd_exec(
                    self, "crontab -l | sed \'/#WordOps "
                    "start/,/#WordOps end/d\' | crontab -")
            else:
                Log.info(self, "MySQL slow log already disabled")
Пример #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")
                WOMysql.execute(
                    self, "TRUNCATE TABLE  "
                    "slow_query_log.global_query_review_history")
                WOMysql.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/php/7.2/slow.log', 'a').close()
            open('/var/log/php7.2-fpm.log', 'a').close()
            self.msg = self.msg + [
                '/var/log/php/7.2/slow.log', '/var/log/php7.2-fpm.log'
            ]
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if WOVar.wo_mysql_host == "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, WordOps does not support"
                    "remote MySQL servers or log files")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(WOVar.wo_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(WOVar.wo_webroot,
                                                     self.app.pargs.site_name)
                ]
            if self.app.pargs.nginx:
                self.msg = self.msg + [
                    "{0}/{1}/logs/error.log".format(WOVar.wo_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()
                            WOShellExec.cmd_exec(
                                self, "chown {1}: {0}/htdocs/"
                                "wp-content/debug.log"
                                "".format(webroot, WOVar.wo_php_user))
                    # create symbolic link for debug log
                    WOFileUtils.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(
                            WOVar.wo_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()