|
@ -27,22 +27,39 @@ class EEDebugController(CementBaseController): |
|
|
stacked_on = 'base' |
|
|
stacked_on = 'base' |
|
|
stacked_type = 'nested' |
|
|
stacked_type = 'nested' |
|
|
arguments = [ |
|
|
arguments = [ |
|
|
(['--stop'], |
|
|
# (['--stop'], |
|
|
dict(help='Stop debug', action='store_true')), |
|
|
# dict(help='Stop debug', action='store_true')), |
|
|
(['--start'], |
|
|
# (['--start'], |
|
|
dict(help='Start debug', action='store_true')), |
|
|
# dict(help='Start debug', action='store_true')), |
|
|
(['--nginx'], |
|
|
(['--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'], |
|
|
(['--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'], |
|
|
(['--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'], |
|
|
(['--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'], |
|
|
(['--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'], |
|
|
(['--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'], |
|
|
(['-i', '--interactive'], |
|
|
dict(help='Interactive debug', action='store_true')), |
|
|
dict(help='Interactive debug', action='store_true')), |
|
|
(['--import-slow-log-interval'], |
|
|
(['--import-slow-log-interval'], |
|
@ -56,7 +73,7 @@ class EEDebugController(CementBaseController): |
|
|
def debug_nginx(self): |
|
|
def debug_nginx(self): |
|
|
"""Start/Stop Nginx debug""" |
|
|
"""Start/Stop Nginx debug""" |
|
|
# start global 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: |
|
|
try: |
|
|
debug_address = (self.app.config.get('stack', 'ip-address') |
|
|
debug_address = (self.app.config.get('stack', 'ip-address') |
|
|
.split()) |
|
|
.split()) |
|
@ -79,7 +96,7 @@ class EEDebugController(CementBaseController): |
|
|
self.msg = self.msg + ["/var/log/nginx/*.error.log"] |
|
|
self.msg = self.msg + ["/var/log/nginx/*.error.log"] |
|
|
|
|
|
|
|
|
# stop global debug |
|
|
# 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', |
|
|
if "debug_connection " in open('/etc/nginx/nginx.conf', |
|
|
encoding='utf-8').read(): |
|
|
encoding='utf-8').read(): |
|
|
Log.info(self, "Disabling Nginx debug connections") |
|
|
Log.info(self, "Disabling Nginx debug connections") |
|
@ -90,7 +107,7 @@ class EEDebugController(CementBaseController): |
|
|
Log.info(self, "Nginx debug connection already disabled") |
|
|
Log.info(self, "Nginx debug connection already disabled") |
|
|
|
|
|
|
|
|
# start site specific debug |
|
|
# 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}" |
|
|
config_path = ("/etc/nginx/sites-available/{0}" |
|
|
.format(self.app.pargs.site_name)) |
|
|
.format(self.app.pargs.site_name)) |
|
|
if os.path.isfile(config_path): |
|
|
if os.path.isfile(config_path): |
|
@ -115,7 +132,7 @@ class EEDebugController(CementBaseController): |
|
|
.format(self.app.pargs.site_name)) |
|
|
.format(self.app.pargs.site_name)) |
|
|
|
|
|
|
|
|
# stop site specific debug |
|
|
# 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}" |
|
|
config_path = ("/etc/nginx/sites-available/{0}" |
|
|
.format(self.app.pargs.site_name)) |
|
|
.format(self.app.pargs.site_name)) |
|
|
if os.path.isfile(config_path): |
|
|
if os.path.isfile(config_path): |
|
@ -139,7 +156,7 @@ class EEDebugController(CementBaseController): |
|
|
def debug_php(self): |
|
|
def debug_php(self): |
|
|
"""Start/Stop PHP debug""" |
|
|
"""Start/Stop PHP debug""" |
|
|
# PHP global debug start |
|
|
# 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" |
|
|
if not (EEShellExec.cmd_exec(self, "sed -n \"/upstream php" |
|
|
"{/,/}/p \" /etc/nginx/" |
|
|
"{/,/}/p \" /etc/nginx/" |
|
|
"conf.d/upstream.conf " |
|
|
"conf.d/upstream.conf " |
|
@ -160,7 +177,7 @@ class EEDebugController(CementBaseController): |
|
|
self.msg = self.msg + ['/var/log/php5/slow.log'] |
|
|
self.msg = self.msg + ['/var/log/php5/slow.log'] |
|
|
|
|
|
|
|
|
# PHP global debug stop |
|
|
# 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\" " |
|
|
if EEShellExec.cmd_exec(self, " sed -n \"/upstream php {/,/}/p\" " |
|
|
"/etc/nginx/conf.d/upstream.conf " |
|
|
"/etc/nginx/conf.d/upstream.conf " |
|
|
"| grep 9001"): |
|
|
"| grep 9001"): |
|
@ -181,7 +198,7 @@ class EEDebugController(CementBaseController): |
|
|
def debug_fpm(self): |
|
|
def debug_fpm(self): |
|
|
"""Start/Stop PHP5-FPM debug""" |
|
|
"""Start/Stop PHP5-FPM debug""" |
|
|
# PHP5-FPM start global 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\" " |
|
|
if not EEShellExec.cmd_exec(self, "grep \"log_level = debug\" " |
|
|
"/etc/php5/fpm/php-fpm.conf"): |
|
|
"/etc/php5/fpm/php-fpm.conf"): |
|
|
Log.info(self, "Setting up PHP5-FPM log_level = debug") |
|
|
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'] |
|
|
self.msg = self.msg + ['/var/log/php5/fpm.log'] |
|
|
|
|
|
|
|
|
# PHP5-FPM stop global debug |
|
|
# 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\" " |
|
|
if EEShellExec.cmd_exec(self, "grep \"log_level = debug\" " |
|
|
"/etc/php5/fpm/php-fpm.conf"): |
|
|
"/etc/php5/fpm/php-fpm.conf"): |
|
|
Log.info(self, "Disabling PHP5-FPM log_level = debug") |
|
|
Log.info(self, "Disabling PHP5-FPM log_level = debug") |
|
@ -225,7 +242,7 @@ class EEDebugController(CementBaseController): |
|
|
def debug_mysql(self): |
|
|
def debug_mysql(self): |
|
|
"""Start/Stop MySQL debug""" |
|
|
"""Start/Stop MySQL debug""" |
|
|
# MySQL start global 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" |
|
|
if not EEShellExec.cmd_exec(self, "mysql -e \"show variables like" |
|
|
" \'slow_query_log\';\" | " |
|
|
" \'slow_query_log\';\" | " |
|
|
"grep ON"): |
|
|
"grep ON"): |
|
@ -258,7 +275,7 @@ class EEDebugController(CementBaseController): |
|
|
self.msg = self.msg + ['/var/log/mysql/mysql-slow.log'] |
|
|
self.msg = self.msg + ['/var/log/mysql/mysql-slow.log'] |
|
|
|
|
|
|
|
|
# MySQL stop global debug |
|
|
# 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 \'" |
|
|
if EEShellExec.cmd_exec(self, "mysql -e \"show variables like \'" |
|
|
"slow_query_log\';\" | grep ON"): |
|
|
"slow_query_log\';\" | grep ON"): |
|
|
Log.info(self, "Disabling MySQL slow log") |
|
|
Log.info(self, "Disabling MySQL slow log") |
|
@ -276,7 +293,7 @@ class EEDebugController(CementBaseController): |
|
|
@expose(hide=True) |
|
|
@expose(hide=True) |
|
|
def debug_wp(self): |
|
|
def debug_wp(self): |
|
|
"""Start/Stop WordPress debug""" |
|
|
"""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" |
|
|
wp_config = ("{0}/{1}/wp-config.php" |
|
|
.format(EEVariables.ee_webroot, |
|
|
.format(EEVariables.ee_webroot, |
|
|
self.app.pargs.site_name)) |
|
|
self.app.pargs.site_name)) |
|
@ -316,7 +333,7 @@ class EEDebugController(CementBaseController): |
|
|
Log.info(self, "{0} domain not valid" |
|
|
Log.info(self, "{0} domain not valid" |
|
|
.format(self.app.pargs.site_name)) |
|
|
.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" |
|
|
wp_config = ("{0}{1}/wp-config.php" |
|
|
.format(EEVariables.ee_webroot, |
|
|
.format(EEVariables.ee_webroot, |
|
|
self.app.pargs.site_name)) |
|
|
self.app.pargs.site_name)) |
|
@ -347,7 +364,7 @@ class EEDebugController(CementBaseController): |
|
|
def debug_rewrite(self): |
|
|
def debug_rewrite(self): |
|
|
"""Start/Stop Nginx rewrite rules debug""" |
|
|
"""Start/Stop Nginx rewrite rules debug""" |
|
|
# Start Nginx rewrite debug globally |
|
|
# 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;\" " |
|
|
if not EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" " |
|
|
"/etc/nginx/nginx.conf"): |
|
|
"/etc/nginx/nginx.conf"): |
|
|
Log.info(self, "Setting up Nginx rewrite logs") |
|
|
Log.info(self, "Setting up Nginx rewrite logs") |
|
@ -361,7 +378,8 @@ class EEDebugController(CementBaseController): |
|
|
self.msg = self.msg + ['/var/log/nginx/*.error.log'] |
|
|
self.msg = self.msg + ['/var/log/nginx/*.error.log'] |
|
|
|
|
|
|
|
|
# Stop Nginx rewrite debug globally |
|
|
# 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;\" " |
|
|
if EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" " |
|
|
"/etc/nginx/nginx.conf"): |
|
|
"/etc/nginx/nginx.conf"): |
|
|
Log.info(self, "Disabling Nginx rewrite logs") |
|
|
Log.info(self, "Disabling Nginx rewrite logs") |
|
@ -371,7 +389,7 @@ class EEDebugController(CementBaseController): |
|
|
else: |
|
|
else: |
|
|
Log.info(self, "Nginx rewrite logs already disabled") |
|
|
Log.info(self, "Nginx rewrite logs already disabled") |
|
|
# Start Nginx rewrite for site |
|
|
# 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}" |
|
|
config_path = ("/etc/nginx/sites-available/{0}" |
|
|
.format(self.app.pargs.site_name)) |
|
|
.format(self.app.pargs.site_name)) |
|
|
if not EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}" |
|
|
if not EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}" |
|
@ -394,7 +412,7 @@ class EEDebugController(CementBaseController): |
|
|
self.app.pargs.site_name)] |
|
|
self.app.pargs.site_name)] |
|
|
|
|
|
|
|
|
# Stop Nginx rewrite for site |
|
|
# 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}" |
|
|
config_path = ("/etc/nginx/sites-available/{0}" |
|
|
.format(self.app.pargs.site_name)) |
|
|
.format(self.app.pargs.site_name)) |
|
|
if EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}" |
|
|
if EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}" |
|
@ -442,32 +460,94 @@ class EEDebugController(CementBaseController): |
|
|
@expose(hide=True) |
|
|
@expose(hide=True) |
|
|
def default(self): |
|
|
def default(self): |
|
|
"""Default function of debug""" |
|
|
"""Default function of debug""" |
|
|
self.start = True |
|
|
# self.start = True |
|
|
self.interactive = False |
|
|
self.interactive = False |
|
|
self.msg = [] |
|
|
self.msg = [] |
|
|
self.trigger_nginx = False |
|
|
self.trigger_nginx = False |
|
|
self.trigger_php = False |
|
|
self.trigger_php = False |
|
|
|
|
|
|
|
|
if self.app.pargs.stop: |
|
|
# if self.app.pargs.stop: |
|
|
self.start = False |
|
|
# self.start = False |
|
|
|
|
|
|
|
|
if ((not self.app.pargs.nginx) and (not self.app.pargs.php) |
|
|
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.fpm) and (not self.app.pargs.mysql) |
|
|
and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) |
|
|
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)): |
|
|
and (not self.app.pargs.site_name)): |
|
|
self.app.pargs.nginx = True |
|
|
print(""" |
|
|
self.app.pargs.php = True |
|
|
Usage: ee debug {<sitename>} {arguments} |
|
|
self.app.pargs.fpm = True |
|
|
arguments : |
|
|
self.app.pargs.mysql = True |
|
|
--all [{on,off}] start/stop debugging all server parameters. |
|
|
self.app.pargs.rewrite = True |
|
|
--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) |
|
|
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.fpm) and (not self.app.pargs.mysql) |
|
|
and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) |
|
|
and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) |
|
|
and self.app.pargs.site_name): |
|
|
and self.app.pargs.site_name): |
|
|
self.app.pargs.nginx = True |
|
|
print(""" |
|
|
self.app.pargs.wp = True |
|
|
usage: ee debug <sitename> {arguments} |
|
|
self.app.pargs.rewrite = True |
|
|
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: |
|
|
if self.app.pargs.nginx: |
|
|
self.debug_nginx() |
|
|
self.debug_nginx() |
|
|