Browse Source

ee debug done

bugfixes
gau1991 10 years ago
parent
commit
298049aaed
  1. 92
      ee/cli/plugins/debug.py

92
ee/cli/plugins/debug.py

@ -4,6 +4,7 @@ from cement.core.controller import CementBaseController, expose
from cement.core import handler, hook from cement.core import handler, hook
from ee.core.shellexec import EEShellExec from ee.core.shellexec import EEShellExec
from ee.core.mysql import EEMysql from ee.core.mysql import EEMysql
from ee.core.services import EEService
import os import os
@ -46,7 +47,6 @@ class EEDebugController(CementBaseController):
@expose(hide=True) @expose(hide=True)
def debug_nginx(self): def debug_nginx(self):
self.trigger_nginx = False
# start global debug # start global debug
if self.start and not self.app.pargs.site_name: if self.start and not self.app.pargs.site_name:
try: try:
@ -67,7 +67,7 @@ class EEDebugController(CementBaseController):
if not self.trigger_nginx: if not self.trigger_nginx:
print("NGINX debug connection already enabled") print("NGINX debug connection already enabled")
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 not self.start and not self.app.pargs.site_name:
@ -95,6 +95,9 @@ class EEDebugController(CementBaseController):
else: else:
print("Debug for site allready enabled") print("Debug for site allready enabled")
self.msg = self.msg + ['/var/www//logs/error.log'
.format(self.app.pargs.site_name)]
else: else:
print("{0} domain not valid".format(self.app.pargs.site_name)) print("{0} domain not valid".format(self.app.pargs.site_name))
@ -137,6 +140,8 @@ class EEDebugController(CementBaseController):
else: else:
print("PHP debug is allready enabled") print("PHP debug is allready enabled")
self.msg = self.msg + ['/var/log/php5/slow.log']
# PHP global debug stop # PHP global debug stop
else: else:
if EEShellExec.cmd_exec(self, "sed -n \"/upstream php {/,/}/p\" " if EEShellExec.cmd_exec(self, "sed -n \"/upstream php {/,/}/p\" "
@ -166,6 +171,8 @@ class EEDebugController(CementBaseController):
self.trigger_php = True self.trigger_php = True
else: else:
print("PHP5-FPM log_level = debug already setup") print("PHP5-FPM log_level = debug already setup")
self.msg = self.msg + ['/var/log/php5/fpm.log']
# PHP5-FPM stop global debug # PHP5-FPM stop global debug
else: else:
if EEShellExec.cmd_exec(self, "grep \"log_level = debug\" " if EEShellExec.cmd_exec(self, "grep \"log_level = debug\" "
@ -207,6 +214,9 @@ class EEDebugController(CementBaseController):
" }} | crontab -\"".format(cron_time)) " }} | crontab -\"".format(cron_time))
else: else:
print("MySQL slow log is allready enabled") print("MySQL slow log is allready enabled")
self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
# MySQL stop global debug # MySQL stop global debug
else: else:
if EEShellExec.cmd_exec(self, "mysql -e \"show variables like \'" if EEShellExec.cmd_exec(self, "mysql -e \"show variables like \'"
@ -283,20 +293,73 @@ class EEDebugController(CementBaseController):
@expose(hide=True) @expose(hide=True)
def debug_rewrite(self): def debug_rewrite(self):
# Start Nginx rewrite debug globally
if self.start and not self.app.pargs.site_name: if self.start and not self.app.pargs.site_name:
print("Start WP-Rewrite debug globally") if not EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" "
elif self.start and not self.app.pargs.site_name: "/etc/nginx/nginx.conf"):
print("Stop WP-Rewrite debug globally") print("Setting up Nginx rewrite logs")
elif self.start and self.app.pargs.site_name: EEShellExec.cmd_exec(self, "sed -i \'/http {/a \\\\t"
print("Start WP-Rewrite for site") "rewrite_log on;\' /etc/nginx/nginx.conf")
self.trigger_nginx = True
else:
print("NGINX rewrite logs already enabled")
if '/var/log/nginx/*.error.log' not in self.msg:
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 not self.start and not self.app.pargs.site_name:
print("Stop WP-Rewrite for site") if EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" "
"/etc/nginx/nginx.conf"):
print("Disabling Nginx rewrite logs")
EEShellExec.cmd_exec(self, "sed -i \"/rewrite_log.*/d\""
" /etc/nginx/nginx.conf")
self.trigger_nginx = True
else:
print("NGINX rewrite logs already disbaled")
# Start Nginx rewrite for site
elif self.start and self.app.pargs.site_name:
config_path = ("/etc/nginx/sites-available/{0}.conf"
.format(self.app.pargs.site_name))
if not EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}"
.format(config_path)):
print("Setting up NGINX rewrite logs for {0}"
.format(self.app.pargs.site_name))
EEShellExec.cmd_exec(self, "sed -i \"/access_log/i \\\\\\t"
"rewrite_log on;\" {0}"
.format(config_path))
self.trigger_nginx = True
else:
print("Nginx rewrite logs for {0} allready setup"
.format(self.app.pargs.site_name))
if ('/var/www/{0}/logs/error.log'.format(self.app.pargs.site_name)
not in self.msg):
self.msg = self.msg + ['/var/www/{0}/logs/error.log'
.format(self.app.pargs.site_name)]
# Stop Nginx rewrite for site
elif not self.start and self.app.pargs.site_name:
config_path = ("/etc/nginx/sites-available/{0}.conf"
.format(self.app.pargs.site_name))
if EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}"
.format(config_path)):
print("Disabling NGINX rewrite logs for {0}"
.format(self.app.pargs.site_name))
EEShellExec.cmd_exec(self, "sed -i \"/rewrite_log.*/d\" {0}"
.format(config_path))
self.trigger_nginx = True
else:
print("Nginx rewrite logs for {0} allready disbaled"
.format(self.app.pargs.site_name))
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
self.start = True self.start = True
self.interactive = False self.interactive = False
self.msg = "" self.msg = []
self.trigger_nginx = False
self.trigger_php = False
if self.app.pargs.stop: if self.app.pargs.stop:
self.start = False self.start = False
@ -327,6 +390,17 @@ class EEDebugController(CementBaseController):
if self.app.pargs.interactive: if self.app.pargs.interactive:
self.interactive = True self.interactive = True
# Reload Nginx
if self.trigger_nginx:
EEService.reload_service(self, ['nginx'])
# Reload PHP
if self.trigger_php:
EEService.reload_service(self, ['php5-fpm'])
if len(self.msg) > 0:
print("Use following command to check debug logs:\n{0}"
.format(self.msg.join()))
def load(app): def load(app):
# register the plugin class.. this only happens if the plugin is enabled # register the plugin class.. this only happens if the plugin is enabled

Loading…
Cancel
Save