From 98ca2600698dcb8f57fd757caf8864903360846c Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Fri, 17 Apr 2015 16:46:51 +0530 Subject: [PATCH] Fixed #322 --- config/bash_completion.d/ee_auto.rc | 20 +++++++---- ee/cli/plugins/debug.py | 54 ++++++++++++++++++----------- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/config/bash_completion.d/ee_auto.rc b/config/bash_completion.d/ee_auto.rc index 6c1db025..b09b517e 100644 --- a/config/bash_completion.d/ee_auto.rc +++ b/config/bash_completion.d/ee_auto.rc @@ -29,7 +29,7 @@ _ee_complete() # IF YOU HAD ANOTHER CONTROLLER, YOU'D HANDLE THAT HERE "debug") COMPREPLY=( $(compgen \ - -W "$(command find /etc/nginx/sites-enabled/ -type l -printf "%P " 2> /dev/null) --nginx --php --fpm --mysql -i --interactive --all --nginx=off --php=off --fpm=off --mysql=off --all=off " \ + -W "$(command find /etc/nginx/sites-enabled/ -type l -printf "%P " 2> /dev/null) --nginx --php --fpm --mysql -i --interactive --all --import-slow-log --import-slow-log-interval= --nginx=off --php=off --fpm=off --mysql=off --all=off " \ -- $cur) ) ;; @@ -133,8 +133,14 @@ _ee_complete() ;; esac - if [ ${COMP_WORDS[1]} == "debug" ] && ([ "$prev" != "--start" ] || [ "$prev" != "--nginx" ] || [ "$prev" != "--php" ] || [ "$prev" != "--fpm" ] || [ "$prev" != "--mysql" ] || [ "$prev" != "-i" ] || ["$prev" != "--interactive" ] || ["$prev" != "--stop" ]); then - retlist="--all --wp --rewrite -i --all=off --wp=off --rewrite=off" + if [ ${COMP_WORDS[1]} == "debug" ] && ([ "$prev" != "--start" ] && [ "$prev" != "--nginx" ] && [ "$prev" != "--php" ] && [ "$prev" != "--fpm" ] && [ "$prev" != "--mysql" ] && [ "$prev" != "-i" ] && [ "$prev" != "--interactive" ] && [ "$prev" != "--import-slow-log" ] && [ "$prev" != "--stop" ]); then + retlist="--all --wp --rewrite -i --all=off --wp=off --rewrite=off" + ret="${retlist[@]/$prev}" + COMPREPLY=( $(compgen \ + -W "$(echo $ret)" \ + -- $cur) ) + else + retlist="--start --nginx --php --fpm --mysql -i --interactive --stop --import-slow-log --import-slow-log-interval=" ret="${retlist[@]/$prev}" COMPREPLY=( $(compgen \ -W "$(echo $ret)" \ @@ -196,10 +202,10 @@ _ee_complete() elif [[ ${COMP_WORDS[2]} == "start" || ${COMP_WORDS[2]} == "reload" || ${COMP_WORDS[2]} == "restart" || ${COMP_WORDS[2]} == "stop" ]]; then 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 + retlist="--start --nginx --php --fpm --mysql -i --interactive --stop --import-slow-log --import-slow-log-interval=" + #if [[ $prev == '--mysql' ]]; then + # retlist="--start --nginx --php --fpm --mysql -i --interactive --stop --import-slow-log --import-slow-log-interval=" + #fi fi ret="${retlist[@]/$prev}" COMPREPLY=( $(compgen \ diff --git a/ee/cli/plugins/debug.py b/ee/cli/plugins/debug.py index ae2c0f22..217f12ce 100644 --- a/ee/cli/plugins/debug.py +++ b/ee/cli/plugins/debug.py @@ -493,27 +493,39 @@ class EEDebugController(CementBaseController): try: if not EEShellExec.cmd_exec(self, "crontab -l | grep " "'ee debug --import-slow-log'"): - 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 debug" - " --import-slow-log\\n" - "#EasyEngine end MySQL slow log" - "\\\"; }} | crontab -\"" - .format(cron_time)) + if not cron_time == 0: + 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 debug" + " --import-slow-log\\n" + "#EasyEngine end MySQL slow log" + "\\\"; }} | crontab -\"" + .format(cron_time)) else: - if not EEShellExec.cmd_exec(self, "/bin/bash -c \"crontab " - "-l | sed '/EasyEngine start " - "MySQL slow " - "log/!b;n;c\*\/{0} \* \* \* " - "\* \/usr" - "\/local\/bin\/ee debug " - "--import\-slow\-log' " - "| crontab -\"" - .format(cron_time)): - Log.error(self, "cron not updated") - + if not cron_time == 0: + if not EEShellExec.cmd_exec(self, "/bin/bash -c " + "\"crontab " + "-l | sed '/EasyEngine " + "start MySQL slow " + "log/!b;n;c\*\/{0} " + "\* \* \* " + "\* \/usr" + "\/local\/bin\/ee debug " + "--import\-slow\-log' " + "| crontab -\"" + .format(cron_time)): + Log.error(self, "failed to update crontab entry") + else: + if not EEShellExec.cmd_exec(self, "/bin/bash -c " + "\"crontab " + "-l | sed '/EasyEngine " + "start MySQL slow " + "log/,+2d'" + "| crontab -\"" + .format(cron_time)): + Log.error(self, "failed to remove crontab entry") except CommandExecutionError as e: Log.debug(self, str(e)) @@ -632,7 +644,7 @@ class EEDebugController(CementBaseController): Log.error(self, "MySQL slow log file not found," " so not imported slow logs") else: - Log.error(self, " Anemometer is not installed," + + Log.error(self, " Anemometer is not installed." + Log.ENDC + " You can install Anemometer with " "this command " + Log.BOLD + "\n `ee stack install --utils`"