From 03e0165560ea07d50758ef1c8c1d976f3dc02cb1 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Thu, 5 Mar 2015 12:04:14 +0530 Subject: [PATCH 01/18] modified ee debug command optional arguments --- ee/cli/plugins/debug.py | 154 ++++++++++++++++++++++++++++++---------- 1 file changed, 117 insertions(+), 37 deletions(-) diff --git a/ee/cli/plugins/debug.py b/ee/cli/plugins/debug.py index 5440bb2b..42594862 100644 --- a/ee/cli/plugins/debug.py +++ b/ee/cli/plugins/debug.py @@ -27,22 +27,39 @@ class EEDebugController(CementBaseController): stacked_on = 'base' stacked_type = 'nested' arguments = [ - (['--stop'], - dict(help='Stop debug', action='store_true')), - (['--start'], - dict(help='Start debug', action='store_true')), + # (['--stop'], + # dict(help='Stop debug', action='store_true')), + # (['--start'], + # dict(help='Start debug', action='store_true')), (['--nginx'], - dict(help='Debug Nginx', action='store_true')), + dict(help='start/stop debugging nginx server ' + 'configuration for site', + action='store' or 'store_const', + choices=('on', 'off'), const='on', nargs='?')), (['--php'], - dict(help='Debug PHP', action='store_true')), + dict(help='start/stop debugging server php configuration', + action='store' or 'store_const', + choices=('on', 'off'), const='on', nargs='?')), (['--fpm'], - dict(help='Debug FastCGI', action='store_true')), + dict(help='start/stop debugging fastcgi configuration', + action='store' or 'store_const', + choices=('on', 'off'), const='on', nargs='?')), (['--mysql'], - dict(help='Debug MySQL', action='store_true')), + dict(help='start/stop debugging mysql server', + action='store' or 'store_const', + choices=('on', 'off'), const='on', nargs='?')), (['--wp'], - dict(help='Debug WordPress sites', action='store_true')), + dict(help='start/stop wordpress debugging for site', + action='store' or 'store_const', choices=('on', 'off'), + const='on', nargs='?')), (['--rewrite'], - dict(help='Debug Nginx rewrite rules', action='store_true')), + dict(help='start/stop debugging nginx rewrite rules for site', + action='store' or 'store_const', choices=('on', 'off'), + const='on', nargs='?')), + (['--all'], + dict(help='start/stop debugging all server parameters', + action='store' or 'store_const', choices=('on', 'off'), + const='on', nargs='?')), (['-i', '--interactive'], dict(help='Interactive debug', action='store_true')), (['--import-slow-log-interval'], @@ -56,7 +73,7 @@ class EEDebugController(CementBaseController): def debug_nginx(self): """Start/Stop Nginx debug""" # start global debug - if self.start and not self.app.pargs.site_name: + if (self.app.pargs.nginx == 'on' and not self.app.pargs.site_name): try: debug_address = (self.app.config.get('stack', 'ip-address') .split()) @@ -79,7 +96,7 @@ class EEDebugController(CementBaseController): self.msg = self.msg + ["/var/log/nginx/*.error.log"] # stop global debug - elif not self.start and not self.app.pargs.site_name: + elif (self.app.pargs.nginx == 'off' and not self.app.pargs.site_name): if "debug_connection " in open('/etc/nginx/nginx.conf', encoding='utf-8').read(): Log.info(self, "Disabling Nginx debug connections") @@ -90,7 +107,7 @@ class EEDebugController(CementBaseController): Log.info(self, "Nginx debug connection already disabled") # start site specific debug - elif self.start and self.app.pargs.site_name: + elif (self.app.pargs.nginx == 'on'and self.app.pargs.site_name): config_path = ("/etc/nginx/sites-available/{0}" .format(self.app.pargs.site_name)) if os.path.isfile(config_path): @@ -115,7 +132,7 @@ class EEDebugController(CementBaseController): .format(self.app.pargs.site_name)) # stop site specific debug - elif not self.start and self.app.pargs.site_name: + elif (self.app.pargs.nginx == 'off' and self.app.pargs.site_name): config_path = ("/etc/nginx/sites-available/{0}" .format(self.app.pargs.site_name)) if os.path.isfile(config_path): @@ -139,7 +156,7 @@ class EEDebugController(CementBaseController): def debug_php(self): """Start/Stop PHP debug""" # PHP global debug start - if self.start: + if (self.app.pargs.php == 'on' and not self.app.pargs.site_name): if not (EEShellExec.cmd_exec(self, "sed -n \"/upstream php" "{/,/}/p \" /etc/nginx/" "conf.d/upstream.conf " @@ -160,7 +177,7 @@ class EEDebugController(CementBaseController): self.msg = self.msg + ['/var/log/php5/slow.log'] # PHP global debug stop - else: + elif (self.app.pargs.php == 'off' and not self.app.pargs.site_name): if EEShellExec.cmd_exec(self, " sed -n \"/upstream php {/,/}/p\" " "/etc/nginx/conf.d/upstream.conf " "| grep 9001"): @@ -181,7 +198,7 @@ class EEDebugController(CementBaseController): def debug_fpm(self): """Start/Stop PHP5-FPM debug""" # PHP5-FPM start global debug - if self.start: + if (self.app.pargs.php == 'on'and not self.app.pargs.site_name): if not EEShellExec.cmd_exec(self, "grep \"log_level = debug\" " "/etc/php5/fpm/php-fpm.conf"): Log.info(self, "Setting up PHP5-FPM log_level = debug") @@ -202,7 +219,7 @@ class EEDebugController(CementBaseController): self.msg = self.msg + ['/var/log/php5/fpm.log'] # PHP5-FPM stop global debug - else: + elif (self.app.pargs.php == 'on' and not self.app.pargs.site_name): if EEShellExec.cmd_exec(self, "grep \"log_level = debug\" " "/etc/php5/fpm/php-fpm.conf"): Log.info(self, "Disabling PHP5-FPM log_level = debug") @@ -225,7 +242,7 @@ class EEDebugController(CementBaseController): def debug_mysql(self): """Start/Stop MySQL debug""" # MySQL start global debug - if self.start: + 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"): @@ -258,7 +275,7 @@ class EEDebugController(CementBaseController): self.msg = self.msg + ['/var/log/mysql/mysql-slow.log'] # MySQL stop global debug - else: + 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") @@ -276,7 +293,7 @@ class EEDebugController(CementBaseController): @expose(hide=True) def debug_wp(self): """Start/Stop WordPress debug""" - if self.start and self.app.pargs.site_name: + if (self.app.pargs.wp == 'on' and self.app.pargs.site_name): wp_config = ("{0}/{1}/wp-config.php" .format(EEVariables.ee_webroot, self.app.pargs.site_name)) @@ -316,7 +333,7 @@ class EEDebugController(CementBaseController): Log.info(self, "{0} domain not valid" .format(self.app.pargs.site_name)) - elif not self.start and self.app.pargs.site_name: + elif (self.app.pargs.wp == 'off' and self.app.pargs.site_name): wp_config = ("{0}{1}/wp-config.php" .format(EEVariables.ee_webroot, self.app.pargs.site_name)) @@ -347,7 +364,7 @@ class EEDebugController(CementBaseController): def debug_rewrite(self): """Start/Stop Nginx rewrite rules debug""" # Start Nginx rewrite debug globally - if self.start and not self.app.pargs.site_name: + if (self.app.pargs.rewrite == 'on' and not self.app.pargs.site_name): if not EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" " "/etc/nginx/nginx.conf"): Log.info(self, "Setting up Nginx rewrite logs") @@ -361,7 +378,8 @@ class EEDebugController(CementBaseController): self.msg = self.msg + ['/var/log/nginx/*.error.log'] # Stop Nginx rewrite debug globally - elif not self.start and not self.app.pargs.site_name: + elif (self.app.pargs.rewrite == 'off' + and not self.app.pargs.site_name): if EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" " "/etc/nginx/nginx.conf"): Log.info(self, "Disabling Nginx rewrite logs") @@ -371,7 +389,7 @@ class EEDebugController(CementBaseController): else: Log.info(self, "Nginx rewrite logs already disabled") # Start Nginx rewrite for site - elif self.start and self.app.pargs.site_name: + elif (self.app.pargs.rewrite == 'on' and self.app.pargs.site_name): config_path = ("/etc/nginx/sites-available/{0}" .format(self.app.pargs.site_name)) if not EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}" @@ -394,7 +412,7 @@ class EEDebugController(CementBaseController): self.app.pargs.site_name)] # Stop Nginx rewrite for site - elif not self.start and self.app.pargs.site_name: + elif (self.app.pargs.rewrite == 'off' and self.app.pargs.site_name): config_path = ("/etc/nginx/sites-available/{0}" .format(self.app.pargs.site_name)) if EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}" @@ -442,32 +460,94 @@ class EEDebugController(CementBaseController): @expose(hide=True) def default(self): """Default function of debug""" - self.start = True + # self.start = True self.interactive = False self.msg = [] self.trigger_nginx = False self.trigger_php = False - if self.app.pargs.stop: - self.start = False + # if self.app.pargs.stop: + # self.start = False if ((not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) + and (not self.app.pargs.all) and (not self.app.pargs.site_name)): - self.app.pargs.nginx = True - self.app.pargs.php = True - self.app.pargs.fpm = True - self.app.pargs.mysql = True - self.app.pargs.rewrite = True + print(""" +Usage: ee debug {} {arguments} +arguments : +--all [{on,off}] start/stop debugging all server parameters. +--nginx [{on,off}] start/stop debugging nginx server configuration for site +--rewrite [{on,off}] start/stop debugging nginx rewrite rules for site +--php [{on,off}] start/stop debugging server php configuration +--fpm [{on,off}] start/stop debugging fastcgi configuration +--mysql [{on,off}] start/stop debugging mysql server +--wp [{on,off}] start/stop wordpress debugging + + +Usage example: +# This is global option will affect all sites +# start debugging all server parameters + +ee debug --all / --all=on +# stop debugging for all server parameters + +ee debug --all=off + +#This is site specific option will affect specific site mentioned +# start debugging all server parameters for example.com + +ee debug example.com --all / --all=on + +# stop debugging for all server parameters available for example.com + +ee debug example.com --all=off + """) + + if self.app.pargs.all == 'on': + if self.app.pargs.site_name: + self.app.pargs.wp = 'on' + self.app.pargs.nginx = 'on' + self.app.pargs.php = 'on' + self.app.pargs.fpm = 'on' + self.app.pargs.mysql = 'on' + self.app.pargs.rewrite = 'on' + + if self.app.pargs.all == 'off': + if self.app.pargs.site_name: + self.app.pargs.wp = 'off' + self.app.pargs.nginx = 'off' + self.app.pargs.php = 'off' + self.app.pargs.fpm = 'off' + self.app.pargs.mysql = 'off' + self.app.pargs.rewrite = 'off' if ((not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) and self.app.pargs.site_name): - self.app.pargs.nginx = True - self.app.pargs.wp = True - self.app.pargs.rewrite = True + print(""" +usage: ee debug {arguments} +arguments : +--all [{on,off}] start/stop debugging all server parameters +--nginx [{on,off}] start/stop debugging nginx server configuration for site +--rewrite [{on,off}] start/stop debugging nginx rewrite rules for site +--wp [{on,off}] start/stop wordpress debugging for site + +Usage example: +#This is site specific option will affect specific site mentioned +# start debugging all server parameters for example.com + +ee debug example.com --all / --all=on + +# stop debugging for all server parameters available for example.com + +ee debug example.com --all=off + """) + # self.app.pargs.nginx = 'on' + # self.app.pargs.wp = 'on' + # self.app.pargs.rewrite = 'on' if self.app.pargs.nginx: self.debug_nginx() From 7f0b191ee6484fc07abb6ad4bc8ec2af0185aee5 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Thu, 5 Mar 2015 12:32:53 +0530 Subject: [PATCH 02/18] updated travis file --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 60399471..46c38ee8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,10 +64,10 @@ script: - sudo ee site create site12.in --wpfc --wpsubdomain - sudo ee site create site12.net --wpfc --wpsubdomain - - sudo ee debug - - sudo ee debug --stop + - sudo ee debug --all + - sudo ee debug --all=off - sudo ee debug site12.net - - sudo ee debug site12.net --stop + - sudo ee debug site12.net --all=off - sudo ee site create 1.com --html - sudo ee site create 2.com --php - sudo ee site create 3.com --mysql From 08badcf0166d7516c1ecf3491ccd0db3d88cf018 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Thu, 5 Mar 2015 12:36:13 +0530 Subject: [PATCH 03/18] updated autocompletion for ee debug command --- config/bash_completion.d/ee_auto.rc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/config/bash_completion.d/ee_auto.rc b/config/bash_completion.d/ee_auto.rc index dcd33dc8..735c0328 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) --start --nginx --php --fpm --mysql -i --interactive --stop " \ + -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 " \ -- $cur) ) ;; @@ -110,7 +110,7 @@ _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="--start --stop --wp --rewrite -i" + retlist="--all --wp --rewrite -i --all=off --wp=off --rewrite=off" ret="${retlist[@]/$prev}" COMPREPLY=( $(compgen \ -W "$(echo $ret)" \ @@ -145,9 +145,16 @@ _ee_complete() case "$prev" in "--wp" | "--wpsubdir" | "--wpsubdomain") - COMPREPLY=( $(compgen \ - -W "--w3tc --wpfc --wpsc" \ - -- $cur) ) + if [ ${COMP_WORDS[1]} != "debug" ]; then + retlist="--w3tc --wpfc --wpsc" + else + retlist="--wp=off --rewrite --rewrite=off -i --interactive" + fi + + ret="${retlist[@]/$prev}" + COMPREPLY=( $(compgen \ + -W "$(echo $ret)" \ + -- $cur) ) ;; "--web" | "--admin" | "--mail" | "--nginx" | "--php" | "--mysql" | "--postfix" | "--wpcli" | "--phpmyadmin" | "--adminer" | "--utils" | "--memcache" | "--dovecot") From 9b5c2068f2169ba570cba4d8b5097cd337a0f7bb Mon Sep 17 00:00:00 2001 From: gau1991 Date: Thu, 5 Mar 2015 13:15:46 +0530 Subject: [PATCH 04/18] Fixed dependency of Postfix and Dovecot with MySQL in stack migration --- ee/cli/plugins/stack_migrate.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ee/cli/plugins/stack_migrate.py b/ee/cli/plugins/stack_migrate.py index c00460bb..3f29f970 100644 --- a/ee/cli/plugins/stack_migrate.py +++ b/ee/cli/plugins/stack_migrate.py @@ -75,6 +75,16 @@ class EEStackMigrateController(CementBaseController): 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"] + apt_packages = EEVariables.ee_mysql + ["php5-mysql"] Log.info(self, "Updating apt-cache, please wait ...") EEAptGet.update(self) From 6b1f824640787aa62e8e7bdec1b4fc670a519588 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Thu, 5 Mar 2015 14:34:55 +0530 Subject: [PATCH 05/18] added --start/stop options as deprecated in ee debug command --- ee/cli/plugins/debug.py | 97 +++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 56 deletions(-) diff --git a/ee/cli/plugins/debug.py b/ee/cli/plugins/debug.py index 42594862..1372649b 100644 --- a/ee/cli/plugins/debug.py +++ b/ee/cli/plugins/debug.py @@ -14,6 +14,37 @@ import glob import signal import subprocess +usage = """ +Usage: ee debug {} {arguments} +arguments : +--all [{on,off}] start/stop debugging all server parameters. +--nginx [{on,off}] start/stop debugging nginx server configuration for site +--rewrite [{on,off}] start/stop debugging nginx rewrite rules for site +--php [{on,off}] start/stop debugging server php configuration +--fpm [{on,off}] start/stop debugging fastcgi configuration +--mysql [{on,off}] start/stop debugging mysql server +--wp [{on,off}] start/stop wordpress debugging + + +Usage example: +# This is global option will affect all sites +# start debugging all server parameters + +ee debug --all / --all=on +# stop debugging for all server parameters + +ee debug --all=off + +#This is site specific option will affect specific site mentioned +# start debugging all server parameters for example.com + +ee debug example.com --all / --all=on + +# stop debugging for all server parameters available for example.com + +ee debug example.com --all=off +""" + def debug_plugin_hook(app): # do something with the ``app`` object here. @@ -27,10 +58,10 @@ class EEDebugController(CementBaseController): stacked_on = 'base' stacked_type = 'nested' arguments = [ - # (['--stop'], - # dict(help='Stop debug', action='store_true')), - # (['--start'], - # dict(help='Start debug', action='store_true')), + (['--stop'], + dict(help='Stop debug', action='store_true')), + (['--start'], + dict(help='Start debug', action='store_true')), (['--nginx'], dict(help='start/stop debugging nginx server ' 'configuration for site', @@ -466,45 +497,16 @@ class EEDebugController(CementBaseController): self.trigger_nginx = False self.trigger_php = False - # if self.app.pargs.stop: - # self.start = False - if ((not self.app.pargs.nginx) and (not self.app.pargs.php) and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) and (not self.app.pargs.all) and (not self.app.pargs.site_name)): - print(""" -Usage: ee debug {} {arguments} -arguments : ---all [{on,off}] start/stop debugging all server parameters. ---nginx [{on,off}] start/stop debugging nginx server configuration for site ---rewrite [{on,off}] start/stop debugging nginx rewrite rules for site ---php [{on,off}] start/stop debugging server php configuration ---fpm [{on,off}] start/stop debugging fastcgi configuration ---mysql [{on,off}] start/stop debugging mysql server ---wp [{on,off}] start/stop wordpress debugging - - -Usage example: -# This is global option will affect all sites -# start debugging all server parameters - -ee debug --all / --all=on -# stop debugging for all server parameters - -ee debug --all=off - -#This is site specific option will affect specific site mentioned -# start debugging all server parameters for example.com - -ee debug example.com --all / --all=on - -# stop debugging for all server parameters available for example.com - -ee debug example.com --all=off - """) - + if self.app.pargs.stop or self.app.pargs.start: + print("--start/stop option is deprecated in ee3.0.5", usage) + else: + print(usage) + if self.app.pargs.all == 'on': if self.app.pargs.site_name: self.app.pargs.wp = 'on' @@ -527,24 +529,7 @@ ee debug example.com --all=off and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) and self.app.pargs.site_name): - print(""" -usage: ee debug {arguments} -arguments : ---all [{on,off}] start/stop debugging all server parameters ---nginx [{on,off}] start/stop debugging nginx server configuration for site ---rewrite [{on,off}] start/stop debugging nginx rewrite rules for site ---wp [{on,off}] start/stop wordpress debugging for site - -Usage example: -#This is site specific option will affect specific site mentioned -# start debugging all server parameters for example.com - -ee debug example.com --all / --all=on - -# stop debugging for all server parameters available for example.com - -ee debug example.com --all=off - """) + print(usage) # self.app.pargs.nginx = 'on' # self.app.pargs.wp = 'on' # self.app.pargs.rewrite = 'on' From 8eecc88ad4491d9763c5ee632ab6cedbd1090136 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Thu, 5 Mar 2015 18:26:55 +0530 Subject: [PATCH 06/18] updated autocompletion for ee log command --- config/bash_completion.d/ee_auto.rc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/config/bash_completion.d/ee_auto.rc b/config/bash_completion.d/ee_auto.rc index 735c0328..8f8608bd 100644 --- a/config/bash_completion.d/ee_auto.rc +++ b/config/bash_completion.d/ee_auto.rc @@ -59,7 +59,7 @@ _ee_complete() "log") COMPREPLY=( $(compgen \ - -W "--mysql --php --nginx --all" \ + -W "$(command find /etc/nginx/sites-enabled/ -type l -printf "%P " 2> /dev/null) --mysql --php --nginx --all" \ -- $cur) ) ;; @@ -117,6 +117,15 @@ _ee_complete() -- $cur) ) fi + if [ ${COMP_WORDS[1]} == "log" ] && ([ "$prev" != "--access" ] || [ "$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" + ret="${retlist[@]/$prev}" + COMPREPLY=( $(compgen \ + -W "$(echo $ret)" \ + -- $cur) ) + fi + + elif [ $COMP_CWORD -eq 4 ]; then case "$mprev" in # HANDLE EVERYTHING AFTER THE THIRD LEVEL NAMESPACE From 0262df2820404df04780bfa8fccc42db5dda0e7b Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Thu, 5 Mar 2015 18:28:39 +0530 Subject: [PATCH 07/18] updated debug usage --- ee/cli/plugins/debug.py | 42 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/ee/cli/plugins/debug.py b/ee/cli/plugins/debug.py index 1372649b..58c267b6 100644 --- a/ee/cli/plugins/debug.py +++ b/ee/cli/plugins/debug.py @@ -16,33 +16,23 @@ import subprocess usage = """ Usage: ee debug {} {arguments} -arguments : ---all [{on,off}] start/stop debugging all server parameters. ---nginx [{on,off}] start/stop debugging nginx server configuration for site ---rewrite [{on,off}] start/stop debugging nginx rewrite rules for site ---php [{on,off}] start/stop debugging server php configuration ---fpm [{on,off}] start/stop debugging fastcgi configuration ---mysql [{on,off}] start/stop debugging mysql server ---wp [{on,off}] start/stop wordpress debugging +arguments usage: +--all --all=on start debugging all server parameters. +--all=off stop debugging all server parameters +--nginx --nginx=on start debugging nginx server configuration for site +--nginx=off stop debugging nginx server configuration for site +--rewrite --rewrite=on start debugging nginx rewrite rules for site +--rewrite=off stop debugging nginx rewrite rules for site +--php --php=on start debugging server php configuration +--php=off stop debugging server php configuration +--fpm --fpm=on start debugging fastcgi configuration +--fpm=off stop debugging fastcgi configuration +--mysql --mysql=on start debugging mysql server +--mysql=off stop debugging mysql server +--wp --wp=on start wordpress debugging +--wp=off stop wordpress debugging -Usage example: -# This is global option will affect all sites -# start debugging all server parameters - -ee debug --all / --all=on -# stop debugging for all server parameters - -ee debug --all=off - -#This is site specific option will affect specific site mentioned -# start debugging all server parameters for example.com - -ee debug example.com --all / --all=on - -# stop debugging for all server parameters available for example.com - -ee debug example.com --all=off """ @@ -506,7 +496,7 @@ class EEDebugController(CementBaseController): print("--start/stop option is deprecated in ee3.0.5", usage) else: print(usage) - + if self.app.pargs.all == 'on': if self.app.pargs.site_name: self.app.pargs.wp = 'on' From ff4a8e39702f1f6feef9961ddae513cda46606ce Mon Sep 17 00:00:00 2001 From: gau1991 Date: Thu, 5 Mar 2015 19:16:38 +0530 Subject: [PATCH 08/18] Fix for Dovecot after MariaDB migration --- ee/cli/plugins/stack_migrate.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ee/cli/plugins/stack_migrate.py b/ee/cli/plugins/stack_migrate.py index 3f29f970..fb68dc18 100644 --- a/ee/cli/plugins/stack_migrate.py +++ b/ee/cli/plugins/stack_migrate.py @@ -6,6 +6,7 @@ from ee.core.variables import EEVariables from ee.core.aptget import EEAptGet from ee.core.shellexec import EEShellExec from ee.core.apt_repo import EERepo +from ee.core.services import EEService import configparser import os @@ -83,7 +84,8 @@ class EEStackMigrateController(CementBaseController): # 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"] + apt_packages = apt_packages + ["dovecot-mysql", "postfix-mysql", + "libclass-dbi-mysql-perl"] apt_packages = EEVariables.ee_mysql + ["php5-mysql"] Log.info(self, "Updating apt-cache, please wait ...") @@ -93,6 +95,11 @@ class EEStackMigrateController(CementBaseController): 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') + @expose(hide=True) def default(self): if ((not self.app.pargs.mariadb)): From b660a3c69b538cdccc463b1f42a54876c4fb51ea Mon Sep 17 00:00:00 2001 From: gau1991 Date: Fri, 6 Mar 2015 12:17:44 +0530 Subject: [PATCH 09/18] Removed unwanted package in migration --- ee/cli/plugins/stack_migrate.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ee/cli/plugins/stack_migrate.py b/ee/cli/plugins/stack_migrate.py index fb68dc18..e5cfa38c 100644 --- a/ee/cli/plugins/stack_migrate.py +++ b/ee/cli/plugins/stack_migrate.py @@ -87,7 +87,6 @@ class EEStackMigrateController(CementBaseController): apt_packages = apt_packages + ["dovecot-mysql", "postfix-mysql", "libclass-dbi-mysql-perl"] - 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 ...") From 37a0059803dc430752412930eb65e9a7f687d13b Mon Sep 17 00:00:00 2001 From: gau1991 Date: Fri, 6 Mar 2015 18:41:18 +0530 Subject: [PATCH 10/18] Fixed auth-sql-conf issue in mail --- ee/cli/plugins/stack.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index b694d3fb..7a319068 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -546,6 +546,14 @@ class EEStackController(CementBaseController): "/dovecot.pem") # Custom Dovecot configuration by EasyEngine + Log.debug(self, "Writting configuration into file" + "/etc/dovecot/conf.d/auth-sql.conf.ext ") + ee_dovecot = open('/etc/dovecot/conf.d/auth-sql.conf.ext', + encoding='utf-8', mode='w') + self.app.render((data), 'auth-sql-conf.mustache', + out=ee_dovecot) + ee_dovecot.close() + data = dict(email=EEVariables.ee_email) Log.debug(self, "Writting configuration into file" "/etc/dovecot/conf.d/99-ee.conf ") From 864c17cb869c294d0aeeb6082beac5a07b4948f2 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Fri, 6 Mar 2015 19:21:11 +0530 Subject: [PATCH 11/18] Fixed data not available --- ee/cli/plugins/stack.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index 7a319068..b2bfb952 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -546,6 +546,7 @@ class EEStackController(CementBaseController): "/dovecot.pem") # Custom Dovecot configuration by EasyEngine + data = dict() Log.debug(self, "Writting configuration into file" "/etc/dovecot/conf.d/auth-sql.conf.ext ") ee_dovecot = open('/etc/dovecot/conf.d/auth-sql.conf.ext', From 6a79d452b7a3e2e63fbd1cdbbb30cd4e9b075e41 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Wed, 11 Mar 2015 17:43:53 +0530 Subject: [PATCH 12/18] moved custom handler to ext/ --- ee/cli/ext/ee_outputhandler.py | 19 +++++++++++++++++++ ee/cli/main.py | 24 ++++++++---------------- 2 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 ee/cli/ext/ee_outputhandler.py diff --git a/ee/cli/ext/ee_outputhandler.py b/ee/cli/ext/ee_outputhandler.py new file mode 100644 index 00000000..32e1af8e --- /dev/null +++ b/ee/cli/ext/ee_outputhandler.py @@ -0,0 +1,19 @@ +# Based on https://github.com/datafolklabs/cement/issues/295 +# To avoid encoding releated error,we defined our custom output handler +# I hope we will remove this when we upgarde to Cement 2.6 (Not released yet) + +from cement.ext.ext_mustache import MustacheOutputHandler + + +class EEOutputHandler(MustacheOutputHandler): + class Meta: + label = 'ee_output_handler' + + def _load_template_from_file(self, path): + for templ_dir in self.app._meta.template_dirs: + full_path = fs.abspath(os.path.join(templ_dir, path)) + if os.path.exists(full_path): + self.app.log.debug('loading template file %s' % full_path) + return open(full_path, encoding='utf-8', mode='r').read() + else: + continue diff --git a/ee/cli/main.py b/ee/cli/main.py index ef828f51..9a89406f 100644 --- a/ee/cli/main.py +++ b/ee/cli/main.py @@ -14,9 +14,9 @@ from cement.core import foundation from cement.utils.misc import init_defaults from cement.core.exc import FrameworkError, CaughtSignal from cement.utils import fs -from cement.ext.ext_mustache import MustacheOutputHandler +from cement.ext.ext_argparse import ArgParseArgumentHandler from ee.core import exc - +from ee.cli.ext.ee_outputhandler import EEOutputHandler # Application default. Should update config/ee.conf to reflect any # changes, or additions here. @@ -31,22 +31,12 @@ defaults['ee']['plugin_dir'] = '/var/lib/ee/plugins' # External templates (generally, do not ship with application code) defaults['ee']['template_dir'] = '/var/lib/ee/templates' - -# Based on https://github.com/datafolklabs/cement/issues/295 -# To avoid encoding releated error,we defined our custom output handler -# I hope we will remove this when we upgarde to Cement 2.6 (Not released yet) -class EEOutputHandler(MustacheOutputHandler): +class EEArgHandler(ArgParseArgumentHandler): class Meta: - label = 'ee_output_handler' + label = 'ee_args_handler' - def _load_template_from_file(self, path): - for templ_dir in self.app._meta.template_dirs: - full_path = fs.abspath(os.path.join(templ_dir, path)) - if os.path.exists(full_path): - self.app.log.debug('loading template file %s' % full_path) - return open(full_path, encoding='utf-8', mode='r').read() - else: - continue + def error(self, message): + super(EEArgHandler, self).error("unknown args") class EEApp(foundation.CementApp): @@ -72,6 +62,8 @@ class EEApp(foundation.CementApp): # default output handler output_handler = EEOutputHandler + arg_handler = EEArgHandler + debug = TOGGLE_DEBUG From 8da13a161cb14176763cabbd328d081b19060406 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Wed, 11 Mar 2015 18:20:32 +0530 Subject: [PATCH 13/18] Error: global name 'fs' is not defined fixed --- ee/cli/ext/ee_outputhandler.py | 2 +- ee/cli/main.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ee/cli/ext/ee_outputhandler.py b/ee/cli/ext/ee_outputhandler.py index 32e1af8e..ec4e906d 100644 --- a/ee/cli/ext/ee_outputhandler.py +++ b/ee/cli/ext/ee_outputhandler.py @@ -1,7 +1,7 @@ # Based on https://github.com/datafolklabs/cement/issues/295 # To avoid encoding releated error,we defined our custom output handler # I hope we will remove this when we upgarde to Cement 2.6 (Not released yet) - +from cement.utils import fs from cement.ext.ext_mustache import MustacheOutputHandler diff --git a/ee/cli/main.py b/ee/cli/main.py index 9a89406f..f3b89d88 100644 --- a/ee/cli/main.py +++ b/ee/cli/main.py @@ -13,7 +13,6 @@ else: from cement.core import foundation from cement.utils.misc import init_defaults from cement.core.exc import FrameworkError, CaughtSignal -from cement.utils import fs from cement.ext.ext_argparse import ArgParseArgumentHandler from ee.core import exc from ee.cli.ext.ee_outputhandler import EEOutputHandler From be3cd0540a00bde936671f55e787a51649fc03f1 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Wed, 11 Mar 2015 18:33:29 +0530 Subject: [PATCH 14/18] fixed global name 'os' is not defined --- ee/cli/ext/ee_outputhandler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ee/cli/ext/ee_outputhandler.py b/ee/cli/ext/ee_outputhandler.py index ec4e906d..89e397d4 100644 --- a/ee/cli/ext/ee_outputhandler.py +++ b/ee/cli/ext/ee_outputhandler.py @@ -1,6 +1,7 @@ # Based on https://github.com/datafolklabs/cement/issues/295 # To avoid encoding releated error,we defined our custom output handler # I hope we will remove this when we upgarde to Cement 2.6 (Not released yet) +import os from cement.utils import fs from cement.ext.ext_mustache import MustacheOutputHandler From 64ddec56b44b9150775d3769664006b596316042 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Wed, 11 Mar 2015 18:48:00 +0530 Subject: [PATCH 15/18] Changed apt-get function to Popen --- ee/core/aptget.py | 84 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 26 deletions(-) diff --git a/ee/core/aptget.py b/ee/core/aptget.py index fd64a7c9..be596a8f 100644 --- a/ee/core/aptget.py +++ b/ee/core/aptget.py @@ -2,6 +2,7 @@ import apt import apt_pkg import sys +import subprocess from ee.core.logging import Log from sh import apt_get from sh import ErrorReturnCode @@ -14,14 +15,24 @@ class EEAptGet(): """ Similar to `apt-get upgrade` """ - global apt_get - apt_get = apt_get.bake("-y") try: - for line in apt_get.update(_iter=True): - Log.info(self, Log.ENDC+line+Log.OKBLUE, end=' ') - except ErrorReturnCode as e: - Log.debug(self, "{0}".format(e)) - Log.error(self, "Unable to run apt-get update") + with open('/var/log/ee/ee.log', 'a') as f: + proc = subprocess.Popen('apt-get update {0}' + .format(all_packages), shell=True, + stdin=None, stdout=f, stderr=f, + executable="/bin/bash") + proc.wait() + + if proc.returncode == 0: + return True + else: + Log.debug(self, "Command Output: {0}, Command Error: {1}" + .format(cmd_stdout, cmd_stderr)) + + except Exception as e: + Log.error(self, "Error, while installing packages, " + "apt-get exited with status %s" + % e) def dist_upgrade(): """ @@ -44,30 +55,51 @@ class EEAptGet(): Log.error(self, 'Unable to Fetch update') def install(self, packages): - global apt_get - apt_get = apt_get.bake("-y") + all_packages = ' '.join(packages) try: - for line in apt_get.install("-o", - "Dpkg::Options::=--force-confold", - *packages, _iter=True): - Log.info(self, Log.ENDC+line+Log.OKBLUE, end=' ') - except ErrorReturnCode as e: - Log.debug(self, "{0}".format(e)) - Log.error(self, "Unable to run apt-get install") + with open('/var/log/ee/ee.log', 'a') as f: + proc = subprocess.Popen('apt-get install -y {0}' + .format(all_packages), shell=True, + stdin=None, stdout=f, stderr=f, + executable="/bin/bash") + proc.wait() + + if proc.returncode == 0: + return True + else: + Log.debug(self, "Command Output: {0}, Command Error: {1}" + .format(cmd_stdout, cmd_stderr)) + + except Exception as e: + Log.error(self, "Error, while installing packages, " + "apt-get exited with status %s" + % e) def remove(self, packages, auto=False, purge=False): - global apt_get - apt_get = apt_get.bake("-y") + all_packages = ' '.join(packages) try: - if purge: - for line in apt_get.purge(*packages, _iter=True): - Log.info(self, Log.ENDC+line+Log.OKBLUE, end=' ') + with open('/var/log/ee/ee.log', 'a') as f: + if purge: + proc = subprocess.Popen('apt-get purge -y {0}' + .format(all_packages), shell=True, + stdin=None, stdout=f, stderr=f, + executable="/bin/bash") + else: + proc = subprocess.Popen('apt-get remove -y {0}' + .format(all_packages), shell=True, + stdin=None, stdout=f, stderr=f, + executable="/bin/bash") + proc.wait() + if proc.returncode == 0: + return True else: - for line in apt_get.remove(*packages, _iter=True): - Log.info(self, Log.ENDC+line+Log.OKBLUE, end=' ') - except ErrorReturnCode as e: - Log.debug(self, "{0}".format(e)) - Log.error(self, "Unable to remove packages") + Log.debug(self, "Command Output: {0}, Command Error: {1}" + .format(cmd_stdout, cmd_stderr)) + + except Exception as e: + Log.error(self, "Error, while installing packages, " + "apt-get exited with status %s" + % e) def auto_clean(self): """ From e543c95c3c5db98a3bc2f54915117a134e06c4a9 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Wed, 11 Mar 2015 19:02:10 +0530 Subject: [PATCH 16/18] Fixed global not defined --- ee/core/aptget.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ee/core/aptget.py b/ee/core/aptget.py index be596a8f..57c060f2 100644 --- a/ee/core/aptget.py +++ b/ee/core/aptget.py @@ -17,8 +17,8 @@ class EEAptGet(): """ try: with open('/var/log/ee/ee.log', 'a') as f: - proc = subprocess.Popen('apt-get update {0}' - .format(all_packages), shell=True, + proc = subprocess.Popen('apt-get update', + shell=True, stdin=None, stdout=f, stderr=f, executable="/bin/bash") proc.wait() From c8d2ef49ddbde0157f4879c2201e5b4e1faa7d6e Mon Sep 17 00:00:00 2001 From: gau1991 Date: Wed, 11 Mar 2015 19:16:30 +0530 Subject: [PATCH 17/18] Improved error message --- ee/core/aptget.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/ee/core/aptget.py b/ee/core/aptget.py index 57c060f2..12883fd3 100644 --- a/ee/core/aptget.py +++ b/ee/core/aptget.py @@ -26,13 +26,11 @@ class EEAptGet(): if proc.returncode == 0: return True else: - Log.debug(self, "Command Output: {0}, Command Error: {1}" - .format(cmd_stdout, cmd_stderr)) + Log.error(self, "Unable to run apt-get update") except Exception as e: - Log.error(self, "Error, while installing packages, " - "apt-get exited with status %s" - % e) + Log.error(self, "Error while installing packages, " + "apt-get exited with error") def dist_upgrade(): """ @@ -67,13 +65,11 @@ class EEAptGet(): if proc.returncode == 0: return True else: - Log.debug(self, "Command Output: {0}, Command Error: {1}" - .format(cmd_stdout, cmd_stderr)) + Log.error(self, "Unable to run apt-get install") except Exception as e: - Log.error(self, "Error, while installing packages, " - "apt-get exited with status %s" - % e) + Log.error(self, "Error while installing packages, " + "apt-get exited with error") def remove(self, packages, auto=False, purge=False): all_packages = ' '.join(packages) @@ -93,13 +89,11 @@ class EEAptGet(): if proc.returncode == 0: return True else: - Log.debug(self, "Command Output: {0}, Command Error: {1}" - .format(cmd_stdout, cmd_stderr)) + Log.error(self, "Unable to run apt-get remove/purge") except Exception as e: - Log.error(self, "Error, while installing packages, " - "apt-get exited with status %s" - % e) + Log.error(self, "Error while installing packages, " + "apt-get exited with error") def auto_clean(self): """ From 6d4b103dd4d1798391cd367ae04a2dbc897877e5 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Mon, 16 Mar 2015 17:06:00 +0530 Subject: [PATCH 18/18] Added Dpkg::Options::=--force-confold to apt-get install --- ee/core/aptget.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ee/core/aptget.py b/ee/core/aptget.py index 12883fd3..5eff0cf7 100644 --- a/ee/core/aptget.py +++ b/ee/core/aptget.py @@ -56,7 +56,8 @@ class EEAptGet(): all_packages = ' '.join(packages) try: with open('/var/log/ee/ee.log', 'a') as f: - proc = subprocess.Popen('apt-get install -y {0}' + proc = subprocess.Popen("apt-get install -o Dpkg::Options::=--" + "force-confold -y {0}" .format(all_packages), shell=True, stdin=None, stdout=f, stderr=f, executable="/bin/bash")