diff --git a/config/bash_completion.d/ee_auto.rc b/config/bash_completion.d/ee_auto.rc index 0acc7fc8..7b4a8155 100644 --- a/config/bash_completion.d/ee_auto.rc +++ b/config/bash_completion.d/ee_auto.rc @@ -57,6 +57,12 @@ _ee_complete() -- $cur) ) ;; + "log") + COMPREPLY=( $(compgen \ + -W "--mysql --php --nginx --all" \ + -- $cur) ) + ;; + # EVERYTHING ELSE *) ;; diff --git a/config/plugins.d/log.conf b/config/plugins.d/log.conf new file mode 100644 index 00000000..a17893f5 --- /dev/null +++ b/config/plugins.d/log.conf @@ -0,0 +1,8 @@ +### Example Plugin Configuration for EasyEngine + +[log] + +### If enabled, load a plugin named `example` either from the Python module +### `ee.cli.plugins.example` or from the file path +### `/var/lib/ee/plugins/example.py` +enable_plugin = true diff --git a/ee/cli/plugins/debug.py b/ee/cli/plugins/debug.py index a99b1a2b..5440bb2b 100644 --- a/ee/cli/plugins/debug.py +++ b/ee/cli/plugins/debug.py @@ -12,6 +12,7 @@ import os import configparser import glob import signal +import subprocess def debug_plugin_hook(app): @@ -160,7 +161,7 @@ class EEDebugController(CementBaseController): # PHP global debug stop else: - if EEShellExec.cmd_exec(self, "sed -n \"/upstream php {/,/}/p\" " + if EEShellExec.cmd_exec(self, " sed -n \"/upstream php {/,/}/p\" " "/etc/nginx/conf.d/upstream.conf " "| grep 9001"): Log.info(self, "Disabling PHP debug") @@ -241,13 +242,16 @@ class EEDebugController(CementBaseController): 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)) + + 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") @@ -296,7 +300,8 @@ class EEDebugController(CementBaseController): " {0}".format(wp_config)) EEShellExec.cmd_exec(self, "cd {0}/htdocs/ && wp" " plugin --allow-root install " - "developer".format(webroot)) + "developer query-monitor" + .format(webroot)) EEShellExec.cmd_exec(self, "chown -R {1}: {0}/htdocs/" "wp-content/plugins" .format(webroot, diff --git a/ee/cli/plugins/log.py b/ee/cli/plugins/log.py new file mode 100644 index 00000000..aa253cbd --- /dev/null +++ b/ee/cli/plugins/log.py @@ -0,0 +1,76 @@ +"""Debug Plugin for EasyEngine""" + +from cement.core.controller import CementBaseController, expose +from cement.core import handler, hook +from ee.core.logging import Log +from ee.cli.plugins.site_functions import logwatch +from ee.core.variables import EEVariables +import os +import glob + + +def log_plugin_hook(app): + # do something with the ``app`` object here. + pass + + +class EELogController(CementBaseController): + class Meta: + label = 'log' + description = 'Show Nginx, PHP, MySQL log file' + stacked_on = 'base' + stacked_type = 'nested' + arguments = [ + (['--all'], + dict(help='Show All logs file', action='store_true')), + (['--nginx'], + dict(help='Show Nginx logs file', action='store_true')), + (['--php'], + dict(help='Show PHP logs file', action='store_true')), + (['--mysql'], + dict(help='Show MySQL logs file', action='store_true')), + ] + + @expose(hide=True) + def default(self): + """Default function of debug""" + self.msg = [] + + if ((not self.app.pargs.nginx) and (not self.app.pargs.php) + and (not self.app.pargs.mysql)): + self.app.pargs.nginx = True + self.app.pargs.php = True + self.app.pargs.mysql = True + + if self.app.pargs.nginx: + self.msg = self.msg + ["/var/log/nginx/*error.log"] + if self.app.pargs.php: + 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.error(self, "Unable to find MySQL slow log file," + "Please generate it using commnad ee debug " + "--mysql") + else: + Log.warn(self, "Remote MySQL found, EasyEngine is not able to" + "show MySQL log file") + + watch_list = [] + for w_list in self.msg: + watch_list = watch_list + glob.glob(w_list) + + logwatch(self, watch_list) + + +def load(app): + # register the plugin class.. this only happens if the plugin is enabled + handler.register(EELogController) + # register a hook (function) to run after arguments are parsed. + hook.register('post_argument_parsing', log_plugin_hook)