Skip to content

Commit c0801f3

Browse files
committed
Merge branch 'python' of github.com:rtCamp/easyengine into python
2 parents 0792b36 + ffb3527 commit c0801f3

File tree

4 files changed

+104
-9
lines changed

4 files changed

+104
-9
lines changed

config/bash_completion.d/ee_auto.rc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ _ee_complete()
5757
-- $cur) )
5858
;;
5959

60+
"log")
61+
COMPREPLY=( $(compgen \
62+
-W "--mysql --php --nginx --all" \
63+
-- $cur) )
64+
;;
65+
6066
# EVERYTHING ELSE
6167
*)
6268
;;

config/plugins.d/log.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### Example Plugin Configuration for EasyEngine
2+
3+
[log]
4+
5+
### If enabled, load a plugin named `example` either from the Python module
6+
### `ee.cli.plugins.example` or from the file path
7+
### `/var/lib/ee/plugins/example.py`
8+
enable_plugin = true

ee/cli/plugins/debug.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import configparser
1313
import glob
1414
import signal
15+
import subprocess
1516

1617

1718
def debug_plugin_hook(app):
@@ -160,7 +161,7 @@ def debug_php(self):
160161

161162
# PHP global debug stop
162163
else:
163-
if EEShellExec.cmd_exec(self, "sed -n \"/upstream php {/,/}/p\" "
164+
if EEShellExec.cmd_exec(self, " sed -n \"/upstream php {/,/}/p\" "
164165
"/etc/nginx/conf.d/upstream.conf "
165166
"| grep 9001"):
166167
Log.info(self, "Disabling PHP debug")
@@ -241,13 +242,16 @@ def debug_mysql(self):
241242
cron_time = int(self.app.pargs.interval)
242243
except Exception as e:
243244
cron_time = 5
244-
EEShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l 2> "
245-
"/dev/null | {{ cat; echo -e"
246-
" \\\"#EasyEngine start MySQL slow"
247-
" log \\n*/{0} * * * * "
248-
"/usr/local/sbin/ee import-slow-log\\"
249-
"n#EasyEngine end MySQL slow log\\\";"
250-
" }} | crontab -\"".format(cron_time))
245+
246+
EEShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l "
247+
"2> /dev/null | {{ cat; echo -e"
248+
" \\\"#EasyEngine start MySQL "
249+
"slow log \\n*/{0} * * * * "
250+
"/usr/local/bin/ee "
251+
"import-slow-log\\n"
252+
"#EasyEngine end MySQL slow log"
253+
"\\\"; }} | crontab -\""
254+
.format(cron_time))
251255
else:
252256
Log.info(self, "MySQL slow log is already enabled")
253257

@@ -296,7 +300,8 @@ def debug_wp(self):
296300
" {0}".format(wp_config))
297301
EEShellExec.cmd_exec(self, "cd {0}/htdocs/ && wp"
298302
" plugin --allow-root install "
299-
"developer".format(webroot))
303+
"developer query-monitor"
304+
.format(webroot))
300305
EEShellExec.cmd_exec(self, "chown -R {1}: {0}/htdocs/"
301306
"wp-content/plugins"
302307
.format(webroot,

ee/cli/plugins/log.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""Debug Plugin for EasyEngine"""
2+
3+
from cement.core.controller import CementBaseController, expose
4+
from cement.core import handler, hook
5+
from ee.core.logging import Log
6+
from ee.cli.plugins.site_functions import logwatch
7+
from ee.core.variables import EEVariables
8+
import os
9+
import glob
10+
11+
12+
def log_plugin_hook(app):
13+
# do something with the ``app`` object here.
14+
pass
15+
16+
17+
class EELogController(CementBaseController):
18+
class Meta:
19+
label = 'log'
20+
description = 'Show Nginx, PHP, MySQL log file'
21+
stacked_on = 'base'
22+
stacked_type = 'nested'
23+
arguments = [
24+
(['--all'],
25+
dict(help='Show All logs file', action='store_true')),
26+
(['--nginx'],
27+
dict(help='Show Nginx logs file', action='store_true')),
28+
(['--php'],
29+
dict(help='Show PHP logs file', action='store_true')),
30+
(['--mysql'],
31+
dict(help='Show MySQL logs file', action='store_true')),
32+
]
33+
34+
@expose(hide=True)
35+
def default(self):
36+
"""Default function of debug"""
37+
self.msg = []
38+
39+
if ((not self.app.pargs.nginx) and (not self.app.pargs.php)
40+
and (not self.app.pargs.mysql)):
41+
self.app.pargs.nginx = True
42+
self.app.pargs.php = True
43+
self.app.pargs.mysql = True
44+
45+
if self.app.pargs.nginx:
46+
self.msg = self.msg + ["/var/log/nginx/*error.log"]
47+
if self.app.pargs.php:
48+
open('/var/log/php5/slow.log', 'a').close()
49+
open('/var/log/php5/fpm.log', 'a').close()
50+
self.msg = self.msg + ['/var/log/php5/slow.log',
51+
'/var/log/php5/fpm.log']
52+
if self.app.pargs.mysql:
53+
# MySQL debug will not work for remote MySQL
54+
if EEVariables.ee_mysql_host is "localhost":
55+
if os.path.isfile('/var/log/mysql/mysql-slow.log'):
56+
self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
57+
else:
58+
Log.error(self, "Unable to find MySQL slow log file,"
59+
"Please generate it using commnad ee debug "
60+
"--mysql")
61+
else:
62+
Log.warn(self, "Remote MySQL found, EasyEngine is not able to"
63+
"show MySQL log file")
64+
65+
watch_list = []
66+
for w_list in self.msg:
67+
watch_list = watch_list + glob.glob(w_list)
68+
69+
logwatch(self, watch_list)
70+
71+
72+
def load(app):
73+
# register the plugin class.. this only happens if the plugin is enabled
74+
handler.register(EELogController)
75+
# register a hook (function) to run after arguments are parsed.
76+
hook.register('post_argument_parsing', log_plugin_hook)

0 commit comments

Comments
 (0)