diff --git a/config/bash_completion.d/ee_auto.rc b/config/bash_completion.d/ee_auto.rc index 0acc7fc8..d7238ba7 100644 --- a/config/bash_completion.d/ee_auto.rc +++ b/config/bash_completion.d/ee_auto.rc @@ -11,7 +11,7 @@ _ee_complete() # SETUP THE BASE LEVEL (everything after "ee") if [ $COMP_CWORD -eq 1 ]; then COMPREPLY=( $(compgen \ - -W "stack site debug clean secure import-slow-log" \ + -W "stack site debug clean secure import-slow-log log" \ -- $cur) ) @@ -57,6 +57,12 @@ _ee_complete() -- $cur) ) ;; + "log") + COMPREPLY=( $(compgen \ + -W "--mysql --php --nginx --all" \ + -- $cur) ) + ;; + # EVERYTHING ELSE *) ;; @@ -147,6 +153,9 @@ _ee_complete() retlist="--nginx --php --mysql --postfix --memcache --dovecot" elif [[ ${COMP_WORDS[1]} == "debug" ]]; then retlist="--start --nginx --php --fpm --mysql -i --interactive --stop" + if [[ $prev == '--mysql' ]]; then + retlist="--start --nginx --php --fpm --mysql -i --interactive --stop --import-slow-log" + fi fi ret="${retlist[@]/$prev}" COMPREPLY=( $(compgen \ 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) diff --git a/ee/cli/plugins/site.py b/ee/cli/plugins/site.py index dae89cda..1d3cbaa5 100644 --- a/ee/cli/plugins/site.py +++ b/ee/cli/plugins/site.py @@ -513,7 +513,7 @@ class EESiteCreateController(CementBaseController): setwebrootpermissions(self, data['webroot']) if ee_auth and len(ee_auth): for msg in ee_auth: - Log.info(self, Log.ENDC + msg) + Log.info(self, Log.ENDC + msg, log=False) if data['wp']: Log.info(self, Log.ENDC + "WordPress admin user :" @@ -976,12 +976,12 @@ class EESiteUpdateController(CementBaseController): for msg in ee_auth: Log.info(self, Log.ENDC + msg) + display_cache_settings(self, data) if data['wp'] and oldsitetype in ['html', 'php', 'mysql']: Log.info(self, "\n\n" + Log.ENDC + "WordPress admin user :" " {0}".format(ee_wp_creds['wp_user'])) Log.info(self, Log.ENDC + "WordPress admin password : {0}" .format(ee_wp_creds['wp_pass']) + "\n\n") - display_cache_settings(self, data) updateSiteInfo(self, ee_www_domain, stype=stype, cache=cache) Log.info(self, "Successfully updated site" " http://{0}".format(ee_domain)) @@ -1100,15 +1100,15 @@ class EESiteDeleteController(CementBaseController): 'DB_HOST').split(',')[1] .split(')')[0].strip().replace('\'', '')) try: - Log.debug(self, "dropping database {0}".format(ee_db_name)) + Log.debug(self, "dropping database `{0}`".format(ee_db_name)) EEMysql.execute(self, - "drop database {0}".format(ee_db_name), + "drop database `{0}`".format(ee_db_name), errormsg='Unable to drop database {0}' .format(ee_db_name)) if ee_db_user != 'root': - Log.debug(self, "dropping user {0}".format(ee_db_user)) + Log.debug(self, "dropping user `{0}`".format(ee_db_user)) EEMysql.execute(self, - "drop user {0}@{1}" + "drop user `{0}`@`{1}`" .format(ee_db_user, ee_db_host)) EEMysql.execute(self, "flush privileges") diff --git a/ee/cli/plugins/site_functions.py b/ee/cli/plugins/site_functions.py index 2812e61e..5ab34e44 100644 --- a/ee/cli/plugins/site_functions.py +++ b/ee/cli/plugins/site_functions.py @@ -184,7 +184,8 @@ def setupwordpress(self, data): Log.debug(self, "Generating wp-config for WordPress Single site") Log.debug(self, "bash -c \"php /usr/bin/wp --allow-root " + "core config " - + "--dbname={0} --dbprefix={1} --dbuser={2} --dbhost={3} " + + "--dbname=\'{0}\' --dbprefix=\'{1}\' --dbuser=\'{2}\' " + "--dbhost=\'{3}\' " .format(data['ee_db_name'], ee_wp_prefix, data['ee_db_user'], data['ee_db_host']) + "--dbpass= " @@ -193,22 +194,25 @@ def setupwordpress(self, data): "\n\ndefine(\'WP_DEBUG\', false);")) EEShellExec.cmd_exec(self, "bash -c \"php /usr/bin/wp --allow-root " + "core config " - + "--dbname={0} --dbprefix={1} --dbuser={2} --dbhost={3} " + + "--dbname=\'{0}\' --dbprefix=\'{1}\' " + "--dbuser=\'{2}\' --dbhost=\'{3}\' " .format(data['ee_db_name'], ee_wp_prefix, - data['ee_db_user'], data['ee_db_host']) - + "--dbpass={0} " + data['ee_db_user'], data['ee_db_host']) + + "--dbpass=\'{0}\' " "--extra-php<