Skip to content

Commit 89a76b6

Browse files
author
gau1991
committed
Merge branch 'master' into stable
2 parents ad08cfd + a8e1f1e commit 89a76b6

File tree

11 files changed

+346
-161
lines changed

11 files changed

+346
-161
lines changed

CHANGELOG.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
v 3.1.1 - April 21, 2015
2+
- Feature: update all site at once #491
3+
- Tweaked import-slow-log command #322
4+
- Fixed HHVM installation without Nginx #492
5+
- Fixed HHVM not running after reboot #498
6+
- Fixed Nginx config on Debian causing failure in site creation #499
7+
- Now support for existing HHVM on server
8+
- Minor fixes and improvements
9+
110
v 3.1.0 - April 16, 2015
211
- Added HHVM support #199
312
- Added Pagespeed support #473

config/bash_completion.d/ee_auto.rc

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ _ee_complete()
2929
# IF YOU HAD ANOTHER CONTROLLER, YOU'D HANDLE THAT HERE
3030
"debug")
3131
COMPREPLY=( $(compgen \
32-
-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 " \
32+
-W "$(command find /etc/nginx/sites-enabled/ -type l -printf "%P " 2> /dev/null) --nginx --php --fpm --mysql -i --interactive --all --import-slow-log --import-slow-log-interval= --nginx=off --php=off --fpm=off --mysql=off --all=off " \
3333
-- $cur) )
3434
;;
3535

@@ -93,7 +93,7 @@ _ee_complete()
9393
-- $cur) )
9494
;;
9595

96-
"edit" | "enable" | "info" | "log" | "show" | "cd" | "update" | "delete")
96+
"edit" | "enable" | "info" | "log" | "show" | "cd" | "delete")
9797
if [ ${COMP_WORDS[1]} == "log" ]; then
9898
COMPREPLY=( $(compgen \
9999
-W "$(find /etc/nginx/sites-available/ -type f -printf "%P " 2> /dev/null) --nginx --php --fpm --mysql --access" \
@@ -104,7 +104,11 @@ _ee_complete()
104104
-- $cur) )
105105
fi
106106
;;
107-
107+
"update")
108+
COMPREPLY=( $(compgen \
109+
-W "$(find /etc/nginx/sites-available/ -type f -printf "%P " 2> /dev/null) --all" \
110+
-- $cur) )
111+
;;
108112
"gzip")
109113
COMPREPLY=( $(compgen \
110114
-W "$(find /etc/nginx/sites-available/ -type f -printf "%P " 2> /dev/null) --nginx --php --fpm --mysql --access" \
@@ -133,12 +137,12 @@ _ee_complete()
133137
;;
134138
esac
135139

136-
if [ ${COMP_WORDS[1]} == "debug" ] && ([ "$prev" != "--start" ] || [ "$prev" != "--nginx" ] || [ "$prev" != "--php" ] || [ "$prev" != "--fpm" ] || [ "$prev" != "--mysql" ] || [ "$prev" != "-i" ] || ["$prev" != "--interactive" ] || ["$prev" != "--stop" ]); then
137-
retlist="--all --wp --rewrite -i --all=off --wp=off --rewrite=off"
138-
ret="${retlist[@]/$prev}"
139-
COMPREPLY=( $(compgen \
140-
-W "$(echo $ret)" \
141-
-- $cur) )
140+
if [ ${COMP_WORDS[1]} == "debug" ] && ([ "$prev" != "--start" ] && [ "$prev" != "--nginx" ] && [ "$prev" != "--php" ] && [ "$prev" != "--fpm" ] && [ "$prev" != "--mysql" ] && [ "$prev" != "-i" ] && [ "$prev" != "--interactive" ] && [ "$prev" != "--import-slow-log" ] && [ "$prev" != "--stop" ]); then
141+
retlist="--all --wp --rewrite -i --all=off --wp=off --rewrite=off"
142+
ret="${retlist[@]/$prev}"
143+
COMPREPLY=( $(compgen \
144+
-W "$(echo $ret)" \
145+
-- $cur) )
142146
fi
143147

144148
#if [ ${COMP_WORDS[1]} == "log" ] && ([ "$prev" != "--access" ] || [ "$prev" != "--nginx" ] || [ "$prev" != "--php" ] || [ "$prev" != "--fpm" ] || [ "$prev" != "--mysql" ] || [ "$prev" != "-i" ] || ["$prev" != "--interactive" ] || ["$prev" != "--stop" ]); then
@@ -224,7 +228,7 @@ _ee_complete()
224228
elif [[ ${COMP_WORDS[2]} == "start" || ${COMP_WORDS[2]} == "reload" || ${COMP_WORDS[2]} == "restart" || ${COMP_WORDS[2]} == "stop" ]]; then
225229
retlist="--nginx --php --mysql --postfix --memcache --dovecot"
226230
elif [[ ${COMP_WORDS[1]} == "debug" ]]; then
227-
retlist="--start --nginx --php --fpm --mysql -i --interactive --stop"
231+
retlist="--start --nginx --php --fpm --mysql -i --interactive -stop --import-slow-log --import-slow-log-interval= -"
228232
if [[ $prev == '--mysql' ]]; then
229233
retlist="--start --nginx --php --fpm --mysql -i --interactive --stop --import-slow-log"
230234
fi
@@ -235,7 +239,6 @@ _ee_complete()
235239
elif [ ${COMP_WORDS[2]} == "reset" ]; then
236240
retlist="--access --nginx --php --mysql --fpm --wp --slow-log-db"
237241

238-
239242
elif [ ${COMP_WORDS[2]} == "mail" ]; then
240243
retlist="--access --nginx --php --mysql --fpm --wp --to="
241244

@@ -258,9 +261,12 @@ _ee_complete()
258261
"--all")
259262
if [ ${COMP_WORDS[1]} == "clean" ]; then
260263
retlist="--memcache --opcache --fastcgi"
261-
else
264+
elif [ ${COMP_WORDS[2]} == "delete" ]; then
262265
retlist="--db --files"
263-
266+
elif [ ${COMP_WORDS[2]} == "update" ]; then
267+
retlist="--password --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --hhvm=off --pagespeed --pagespeed=off"
268+
else
269+
retlist=""
264270
fi
265271
ret="${retlist[@]/$prev}"
266272
COMPREPLY=( $(compgen \

ee/cli/plugins/debug.py

Lines changed: 125 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from cement.core.controller import CementBaseController, expose
44
from cement.core import handler, hook
5-
from ee.core.shellexec import EEShellExec
5+
from ee.core.shellexec import *
66
from ee.core.mysql import EEMysql
77
from ee.core.services import EEService
88
from ee.core.logging import Log
@@ -32,6 +32,9 @@ class Meta:
3232
dict(help='Stop debug', action='store_true')),
3333
(['--start'],
3434
dict(help='Start debug', action='store_true')),
35+
(['--import-slow-log'],
36+
dict(help='Import MySQL slow log to Anemometer database',
37+
action='store_true')),
3538
(['--nginx'],
3639
dict(help='start/stop debugging nginx server '
3740
'configuration for site',
@@ -268,21 +271,6 @@ def debug_mysql(self):
268271
EEMysql.execute(self, "set global long_query_time = 2;")
269272
EEMysql.execute(self, "set global log_queries_not_using"
270273
"_indexes = \'ON\';")
271-
if self.app.pargs.interval:
272-
try:
273-
cron_time = int(self.app.pargs.interval)
274-
except Exception as e:
275-
cron_time = 5
276-
277-
EEShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l "
278-
"2> /dev/null | {{ cat; echo -e"
279-
" \\\"#EasyEngine start MySQL "
280-
"slow log \\n*/{0} * * * * "
281-
"/usr/local/bin/ee "
282-
"import-slow-log\\n"
283-
"#EasyEngine end MySQL slow log"
284-
"\\\"; }} | crontab -\""
285-
.format(cron_time))
286274
else:
287275
Log.info(self, "MySQL slow log is already enabled")
288276

@@ -313,6 +301,11 @@ def debug_wp(self):
313301
self.app.pargs.site_name))
314302
webroot = "{0}{1}".format(EEVariables.ee_webroot,
315303
self.app.pargs.site_name)
304+
# Check wp-config.php file into htdocs folder
305+
if not os.path.isfile(wp_config):
306+
wp_config = ("{0}/{1}/htdocs/wp-config.php"
307+
.format(EEVariables.ee_webroot,
308+
self.app.pargs.site_name))
316309
if os.path.isfile(wp_config):
317310
if not EEShellExec.cmd_exec(self, "grep \"\'WP_DEBUG\'\" {0} |"
318311
" grep true".format(wp_config)):
@@ -344,7 +337,7 @@ def debug_wp(self):
344337
self.app.pargs.site_name)]
345338

346339
else:
347-
Log.info(self, "{0} domain not valid"
340+
Log.info(self, "Unable to find wp-config.php for site: {0}"
348341
.format(self.app.pargs.site_name))
349342

350343
elif (self.app.pargs.wp == 'off' and self.app.pargs.site_name):
@@ -353,6 +346,11 @@ def debug_wp(self):
353346
self.app.pargs.site_name))
354347
webroot = "{0}{1}".format(EEVariables.ee_webroot,
355348
self.app.pargs.site_name)
349+
# Check wp-config.php file into htdocs folder
350+
if not os.path.isfile(wp_config):
351+
wp_config = ("{0}/{1}/htdocs/wp-config.php"
352+
.format(EEVariables.ee_webroot,
353+
self.app.pargs.site_name))
356354
if os.path.isfile(wp_config):
357355
if EEShellExec.cmd_exec(self, "grep \"\'WP_DEBUG\'\" {0} | "
358356
"grep true".format(wp_config)):
@@ -484,13 +482,69 @@ def default(self):
484482
and (not self.app.pargs.fpm) and (not self.app.pargs.mysql)
485483
and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
486484
and (not self.app.pargs.all)
487-
and (not self.app.pargs.site_name)):
485+
and (not self.app.pargs.site_name)
486+
and (not self.app.pargs.import_slow_log)
487+
and (not self.app.pargs.interval)):
488488
if self.app.pargs.stop or self.app.pargs.start:
489489
print("--start/stop option is deprecated since ee3.0.5")
490490
self.app.args.print_help()
491491
else:
492492
self.app.args.print_help()
493493

494+
if self.app.pargs.import_slow_log:
495+
self.import_slow_log()
496+
497+
if self.app.pargs.interval:
498+
try:
499+
cron_time = int(self.app.pargs.interval)
500+
except Exception as e:
501+
cron_time = 5
502+
503+
try:
504+
if not EEShellExec.cmd_exec(self, "crontab -l | grep "
505+
"'ee debug --import-slow-log'"):
506+
if not cron_time == 0:
507+
Log.info(self, "setting up crontab entry,"
508+
" please wait ...")
509+
EEShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l "
510+
"2> /dev/null | {{ cat; echo -e"
511+
" \\\"#EasyEngine start MySQL "
512+
"slow log \\n*/{0} * * * * "
513+
"/usr/local/bin/ee debug"
514+
" --import-slow-log\\n"
515+
"#EasyEngine end MySQL slow log"
516+
"\\\"; }} | crontab -\""
517+
.format(cron_time))
518+
else:
519+
if not cron_time == 0:
520+
Log.info(self, "updating crontab entry,"
521+
" please wait ...")
522+
if not EEShellExec.cmd_exec(self, "/bin/bash -c "
523+
"\"crontab "
524+
"-l | sed '/EasyEngine "
525+
"start MySQL slow "
526+
"log/!b;n;c\*\/{0} "
527+
"\* \* \* "
528+
"\* \/usr"
529+
"\/local\/bin\/ee debug "
530+
"--import\-slow\-log' "
531+
"| crontab -\""
532+
.format(cron_time)):
533+
Log.error(self, "failed to update crontab entry")
534+
else:
535+
Log.info(self, "removing crontab entry,"
536+
" please wait ...")
537+
if not EEShellExec.cmd_exec(self, "/bin/bash -c "
538+
"\"crontab "
539+
"-l | sed '/EasyEngine "
540+
"start MySQL slow "
541+
"log/,+2d'"
542+
"| crontab -\""
543+
.format(cron_time)):
544+
Log.error(self, "failed to remove crontab entry")
545+
except CommandExecutionError as e:
546+
Log.debug(self, str(e))
547+
494548
if self.app.pargs.all == 'on':
495549
if self.app.pargs.site_name:
496550
self.app.pargs.wp = 'on'
@@ -559,6 +613,59 @@ def default(self):
559613

560614
logwatch(self, watch_list)
561615

616+
@expose(hide=True)
617+
def import_slow_log(self):
618+
"""Default function for import slow log"""
619+
if os.path.isdir("{0}22222/htdocs/db/anemometer"
620+
.format(EEVariables.ee_webroot)):
621+
if os.path.isfile("/var/log/mysql/mysql-slow.log"):
622+
# Get Anemometer user name and password
623+
Log.info(self, "Importing MySQL slow log to Anemometer")
624+
host = os.popen("grep -e \"\'host\'\" {0}22222/htdocs/"
625+
.format(EEVariables.ee_webroot)
626+
+ "db/anemometer/conf/config.inc.php "
627+
"| head -1 | cut -d\\\' -f4 | "
628+
"tr -d '\n'").read()
629+
user = os.popen("grep -e \"\'user\'\" {0}22222/htdocs/"
630+
.format(EEVariables.ee_webroot)
631+
+ "db/anemometer/conf/config.inc.php "
632+
"| head -1 | cut -d\\\' -f4 | "
633+
"tr -d '\n'").read()
634+
password = os.popen("grep -e \"\'password\'\" {0}22222/"
635+
.format(EEVariables.ee_webroot)
636+
+ "htdocs/db/anemometer/conf"
637+
"/config.inc.php "
638+
"| head -1 | cut -d\\\' -f4 | "
639+
"tr -d '\n'").read()
640+
641+
# Import slow log Anemometer using pt-query-digest
642+
try:
643+
EEShellExec.cmd_exec(self, "pt-query-digest --user={0} "
644+
"--password={1} "
645+
"--review D=slow_query_log,"
646+
"t=global_query_review "
647+
"--history D=slow_query_log,t="
648+
"global_query_review_history "
649+
"--no-report --limit=0% "
650+
"--filter=\" \\$event->{{Bytes}} = "
651+
"length(\\$event->{{arg}}) "
652+
"and \\$event->{{hostname}}=\\\""
653+
"{2}\\\"\" "
654+
"/var/log/mysql/mysql-slow.log"
655+
.format(user, password, host))
656+
except CommandExecutionError as e:
657+
Log.debug(self, str(e))
658+
Log.error(self, "MySQL slow log import failed.")
659+
else:
660+
Log.error(self, "MySQL slow log file not found,"
661+
" so not imported slow logs")
662+
else:
663+
Log.error(self, "Anemometer is not installed." +
664+
Log.ENDC + "\nYou can install Anemometer with "
665+
"this command "
666+
+ Log.BOLD + "\n `ee stack install --utils`"
667+
+ Log.ENDC)
668+
562669

563670
def load(app):
564671
# register the plugin class.. this only happens if the plugin is enabled

ee/cli/plugins/import_slow_log.py

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,10 @@ class Meta:
2020

2121
@expose(hide=True)
2222
def default(self):
23-
"""Default function for import slow log"""
24-
if os.path.isdir("{0}22222/htdocs/db/anemometer"
25-
.format(EEVariables.ee_webroot)):
26-
if os.path.isfile("/var/log/mysql/mysql-slow.log"):
27-
# Get Anemometer user name and password
28-
Log.info(self, "Importing MySQL slow log to Anemometer")
29-
host = os.popen("grep -e \"\'host\'\" {0}22222/htdocs/"
30-
.format(EEVariables.ee_webroot)
31-
+ "db/anemometer/conf/config.inc.php "
32-
"| head -1 | cut -d\\\' -f4 | "
33-
"tr -d '\n'").read()
34-
user = os.popen("grep -e \"\'user\'\" {0}22222/htdocs/"
35-
.format(EEVariables.ee_webroot)
36-
+ "db/anemometer/conf/config.inc.php "
37-
"| head -1 | cut -d\\\' -f4 | "
38-
"tr -d '\n'").read()
39-
password = os.popen("grep -e \"\'password\'\" {0}22222/"
40-
.format(EEVariables.ee_webroot)
41-
+ "htdocs/db/anemometer/conf"
42-
"/config.inc.php "
43-
"| head -1 | cut -d\\\' -f4 | "
44-
"tr -d '\n'").read()
45-
46-
# Import slow log Anemometer using pt-query-digest
47-
EEShellExec.cmd_exec(self, "pt-query-digest --user={0} "
48-
"--password={1} "
49-
"--review D=slow_query_log,"
50-
"t=global_query_review "
51-
"--history D=slow_query_log,t="
52-
"global_query_review_history "
53-
"--no-report --limit=0% "
54-
"--filter=\" \\$event->{{Bytes}} = "
55-
"length(\\$event->{{arg}}) "
56-
"and \\$event->{{hostname}}=\\\""
57-
"{2}\\\"\" "
58-
"/var/log/mysql/mysql-slow.log"
59-
.format(user, password, host))
60-
else:
61-
Log.error(self, "Unable to find MySQL slow log file")
62-
else:
63-
Log.error(self, "Anemometer is not installed")
23+
Log.info(self, "This command is deprecated."
24+
" You can use this command instead, " +
25+
Log.ENDC + Log.BOLD + "\n`ee debug --import-slow-log`" +
26+
Log.ENDC)
6427

6528

6629
def load(app):

0 commit comments

Comments
 (0)