|
|
@ -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 {<sitename>} {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 <sitename> {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() |
|
|
|