Browse Source

Merge branch 'master' into stable

stable v3.1.0
gau1991 10 years ago
parent
commit
ad08cfddba
  1. 17
      .travis.yml
  2. 7
      CHANGELOG.txt
  3. 107
      config/bash_completion.d/ee_auto.rc
  4. 5
      ee/cli/main.py
  5. 19
      ee/cli/plugins/clean.py
  6. 8
      ee/cli/plugins/debug.py
  7. 463
      ee/cli/plugins/log.py
  8. 378
      ee/cli/plugins/site.py
  9. 92
      ee/cli/plugins/site_functions.py
  10. 14
      ee/cli/plugins/sitedb.py
  11. 200
      ee/cli/plugins/stack.py
  12. 52
      ee/cli/plugins/stack_services.py
  13. 1
      ee/cli/templates/fastcgi.mustache
  14. 44
      ee/cli/templates/pagespeed-common.mustache
  15. 21
      ee/cli/templates/pagespeed-global.mustache
  16. 10
      ee/cli/templates/php-hhvm.mustache
  17. 2
      ee/cli/templates/siteinfo.mustache
  18. 5
      ee/cli/templates/upstream.mustache
  19. 3
      ee/cli/templates/virtualconf.mustache
  20. 31
      ee/cli/templates/w3tc-hhvm.mustache
  21. 36
      ee/cli/templates/wpfc-hhvm.mustache
  22. 31
      ee/cli/templates/wpsc-hhvm.mustache
  23. 1
      ee/core/fileutils.py
  24. 33
      ee/core/sendmail.py
  25. 18
      ee/core/variables.py
  26. 7
      install
  27. 2
      setup.py

17
.travis.yml

@ -64,6 +64,18 @@ script:
- sudo ee site create site12.in --wpfc --wpsubdomain - sudo ee site create site12.in --wpfc --wpsubdomain
- sudo ee site create site12.net --wpfc --wpsubdomain - sudo ee site create site12.net --wpfc --wpsubdomain
- sudo ee site create site.hhvm.pagespeed2.com --wpsc --hhvm --pagespeed
- sudo ee site create site.hhvm.pagespeed3.com --w3tc --hhvm --pagespeed
- sudo ee site create site.hhvm.pagespeed4.com --wpfc --hhvm --pagespeed
- sudo ee site create site.hhvm.pagespeed5.com --wpsubdir --hhvm --pagespeed
- sudo ee site create site.hhvm.pagespeed6.com --wpsubdir --wpsc --hhvm --pagespeed
- sudo ee site create site.hhvm.pagespeed7.com --wpsubdir --w3tc --hhvm --pagespeed
- sudo ee site create site.hhvm.pagespeed8.com --wpsubdir --wpfc --hhvm --pagespeed
- sudo ee site create site.hhvm.pagespeed9.com --wpsubdomain --hhvm --pagespeed
- sudo ee site create site.hhvm.pagespeed10.org --wpsubdomain --wpsc --hhvm --pagespeed
- sudo ee site create site.hhvm.pagespeed11.in --w3tc --wpsubdomain --hhvm --pagespeed
- sudo ee site create site.hhvm.pagespeed12.in --wpfc --wpsubdomain --hhvm --pagespeed
- sudo ee debug --all - sudo ee debug --all
- sudo ee debug --all=off - sudo ee debug --all=off
- sudo ee debug site12.net - sudo ee debug site12.net
@ -87,6 +99,10 @@ script:
- sudo ee site update site9.com --wpsubdomain --wpfc - sudo ee site update site9.com --wpsubdomain --wpfc
- sudo ee site update site9.com --wpsubdomain --w3tc - sudo ee site update site9.com --wpsubdomain --w3tc
- sudo ee site update site9.com --wpsubdomain --wpsc - sudo ee site update site9.com --wpsubdomain --wpsc
- sudo ee site update site.hhvm.pagespeed12.in --pagespeed=off --hhvm=off
- sudo ee site update site9.com --hhvm --pagespeed
- sudo ee site info site.hhvm.pagespeed12.in
- sudo ee site info site9.com
- sudo ee site create www.site-1.com --wp - sudo ee site create www.site-1.com --wp
- sudo ee site create www.subsite.site-1.com --wpfc - sudo ee site create www.subsite.site-1.com --wpfc
@ -96,6 +112,7 @@ script:
- sudo ee site delete site12.in --all --no-prompt - sudo ee site delete site12.in --all --no-prompt
- sudo ee site delete site12.net --no-prompt - sudo ee site delete site12.net --no-prompt
- sudo ee site delete site12.org --no-prompt - sudo ee site delete site12.org --no-prompt
- sudo ee site delete site9.com --no-prompt
- sudo ee stack install --mail - sudo ee stack install --mail
- sudo ls /var/www/ - sudo ls /var/www/

7
CHANGELOG.txt

@ -1,3 +1,10 @@
v 3.1.0 - April 16, 2015
- Added HHVM support #199
- Added Pagespeed support #473
- EasyEngine log command now suppots more subcommand #448
- Before stack purge or remove, EasyEngine now asks confirmation #485
- Minor fixes and improvements
v 3.0.10 - April 10, 2015 v 3.0.10 - April 10, 2015
- Fixed regression issue introduced in 3.0.9 - Fixed regression issue introduced in 3.0.9

107
config/bash_completion.d/ee_auto.rc

@ -22,7 +22,7 @@ _ee_complete()
# HANDLE EVERYTHING AFTER THE SECOND LEVEL NAMESPACE # HANDLE EVERYTHING AFTER THE SECOND LEVEL NAMESPACE
"clean") "clean")
COMPREPLY=( $(compgen \ COMPREPLY=( $(compgen \
-W "--memcache --opcache --fastcgi --all" \ -W "--memcache --opcache --fastcgi --pagespeed --all" \
-- $cur) ) -- $cur) )
;; ;;
@ -59,7 +59,7 @@ _ee_complete()
"log") "log")
COMPREPLY=( $(compgen \ COMPREPLY=( $(compgen \
-W "$(command find /etc/nginx/sites-enabled/ -type l -printf "%P " 2> /dev/null) --mysql --php --nginx --all" \ -W "show reset gzip mail" \
-- $cur) ) -- $cur) )
;; ;;
@ -74,7 +74,7 @@ _ee_complete()
# HANDLE EVERYTHING AFTER THE THIRD LEVEL NAMESPACE # HANDLE EVERYTHING AFTER THE THIRD LEVEL NAMESPACE
"install" | "purge" | "remove" ) "install" | "purge" | "remove" )
COMPREPLY=( $(compgen \ COMPREPLY=( $(compgen \
-W "--web --admin --mail --nginx --php --mysql --postfix --wpcli --phpmyadmin --adminer --utils --memcache --dovecot --all --mailscanner" \ -W "--web --admin --mail --nginx --php --mysql --postfix --wpcli --phpmyadmin --adminer --utils --memcache --dovecot --all --mailscanner --hhvm" \
-- $cur) ) -- $cur) )
;; ;;
"start" | "stop" | "reload" | "restart" | "status") "start" | "stop" | "reload" | "restart" | "status")
@ -94,9 +94,33 @@ _ee_complete()
;; ;;
"edit" | "enable" | "info" | "log" | "show" | "cd" | "update" | "delete") "edit" | "enable" | "info" | "log" | "show" | "cd" | "update" | "delete")
if [ ${COMP_WORDS[1]} == "log" ]; then
COMPREPLY=( $(compgen \
-W "$(find /etc/nginx/sites-available/ -type f -printf "%P " 2> /dev/null) --nginx --php --fpm --mysql --access" \
-- $cur) )
else
COMPREPLY=( $(compgen \ COMPREPLY=( $(compgen \
-W "$(find /etc/nginx/sites-available/ -type f -printf "%P " 2> /dev/null)" \ -W "$(find /etc/nginx/sites-available/ -type f -printf "%P " 2> /dev/null)" \
-- $cur) ) -- $cur) )
fi
;;
"gzip")
COMPREPLY=( $(compgen \
-W "$(find /etc/nginx/sites-available/ -type f -printf "%P " 2> /dev/null) --nginx --php --fpm --mysql --access" \
-- $cur) )
;;
"mail")
COMPREPLY=( $(compgen \
-W "$(find /etc/nginx/sites-available/ -type f -printf "%P " 2> /dev/null) --nginx --php --fpm --mysql --access --to=" \
-- $cur) )
;;
"reset")
COMPREPLY=( $(compgen \
-W "$(find /etc/nginx/sites-available/ -type f -printf "%P " 2> /dev/null) --nginx --php --fpm --mysql --wp --access --slow-log-db" \
-- $cur) )
;; ;;
"disable") "disable")
@ -117,13 +141,13 @@ _ee_complete()
-- $cur) ) -- $cur) )
fi fi
if [ ${COMP_WORDS[1]} == "log" ] && ([ "$prev" != "--access" ] || [ "$prev" != "--nginx" ] || [ "$prev" != "--php" ] || [ "$prev" != "--fpm" ] || [ "$prev" != "--mysql" ] || [ "$prev" != "-i" ] || ["$prev" != "--interactive" ] || ["$prev" != "--stop" ]); then #if [ ${COMP_WORDS[1]} == "log" ] && ([ "$prev" != "--access" ] || [ "$prev" != "--nginx" ] || [ "$prev" != "--php" ] || [ "$prev" != "--fpm" ] || [ "$prev" != "--mysql" ] || [ "$prev" != "-i" ] || ["$prev" != "--interactive" ] || ["$prev" != "--stop" ]); then
retlist="--all --wp --rewrite -i --all=off --wp=off --rewrite=off" # retlist="--all --wp --rewrite -i --all=off --wp=off --rewrite=off"
ret="${retlist[@]/$prev}" # ret="${retlist[@]/$prev}"
COMPREPLY=( $(compgen \ # COMPREPLY=( $(compgen \
-W "$(echo $ret)" \ # -W "$(echo $ret)" \
-- $cur) ) # -- $cur) )
fi #fi
elif [ $COMP_CWORD -eq 4 ]; then elif [ $COMP_CWORD -eq 4 ]; then
@ -132,13 +156,13 @@ _ee_complete()
"create") "create")
COMPREPLY=( $(compgen \ COMPREPLY=( $(compgen \
-W "--html --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc" \ -W "--html --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --pagespeed" \
-- $cur) ) -- $cur) )
;; ;;
"update") "update")
COMPREPLY=( $(compgen \ COMPREPLY=( $(compgen \
-W "--password --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc" \ -W "--password --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --hhvm=off --pagespeed --pagespeed=off" \
-- $cur) ) -- $cur) )
;; ;;
"delete") "delete")
@ -146,6 +170,34 @@ _ee_complete()
-W "--db --files --all --no-prompt" \ -W "--db --files --all --no-prompt" \
-- $cur) ) -- $cur) )
;; ;;
"show")
COMPREPLY=( $(compgen \
-W "--wp --nginx --php --fpm --mysql --access" \
-- $cur) )
;;
"gzip")
COMPREPLY=( $(compgen \
-W "--wp --nginx --php --fpm --mysql --access" \
-- $cur) )
;;
"mail")
COMPREPLY=( $(compgen \
-W "--wp --nginx --php --fpm --mysql --access --to=" \
-- $cur) )
;;
"reset")
COMPREPLY=( $(compgen \
-W "--wp --nginx --php --fpm --mysql --wp --access --slow-log-db" \
-- $cur) )
;;
edit)
COMPREPLY=( $(compgen \
-W "--pagespeed" \
-- $cur) )
;;
*) *)
;; ;;
esac esac
@ -176,6 +228,18 @@ _ee_complete()
if [[ $prev == '--mysql' ]]; then if [[ $prev == '--mysql' ]]; then
retlist="--start --nginx --php --fpm --mysql -i --interactive --stop --import-slow-log" retlist="--start --nginx --php --fpm --mysql -i --interactive --stop --import-slow-log"
fi fi
elif [[ ${COMP_WORDS[1]} == "log" ]]; then
if [ ${COMP_WORDS[2]} == "show" ]; then
retlist="--access --nginx --php --mysql --fpm --wp"
elif [ ${COMP_WORDS[2]} == "reset" ]; then
retlist="--access --nginx --php --mysql --fpm --wp --slow-log-db"
elif [ ${COMP_WORDS[2]} == "mail" ]; then
retlist="--access --nginx --php --mysql --fpm --wp --to="
fi
fi fi
ret="${retlist[@]/$prev}" ret="${retlist[@]/$prev}"
COMPREPLY=( $(compgen \ COMPREPLY=( $(compgen \
@ -218,6 +282,25 @@ _ee_complete()
-W "$(echo $ret)" \ -W "$(echo $ret)" \
-- $cur) ) -- $cur) )
;; ;;
"--access" | "--fpm" | "--wp" | "--slow-log-db")
if [[ ${COMP_WORDS[1]} == "log" ]]; then
if [ ${COMP_WORDS[2]} == "show" ]; then
retlist="--access --nginx --php --mysql --fpm --wp"
elif [ ${COMP_WORDS[2]} == "reset" ]; then
retlist="--access --nginx --php --mysql --fpm --wp --slow-log-db"
elif [ ${COMP_WORDS[2]} == "mail" ]; then
retlist="--access --nginx --php --mysql --fpm --wp --to="
fi
fi
ret="${retlist[@]/$prev}"
COMPREPLY=( $(compgen \
-W "$(echo $ret)" \
-- $cur) )
;;
*) *)
;; ;;
esac esac

5
ee/cli/main.py

@ -30,6 +30,7 @@ defaults['ee']['plugin_dir'] = '/var/lib/ee/plugins'
# External templates (generally, do not ship with application code) # External templates (generally, do not ship with application code)
defaults['ee']['template_dir'] = '/var/lib/ee/templates' defaults['ee']['template_dir'] = '/var/lib/ee/templates'
class EEArgHandler(ArgParseArgumentHandler): class EEArgHandler(ArgParseArgumentHandler):
class Meta: class Meta:
label = 'ee_args_handler' label = 'ee_args_handler'
@ -80,6 +81,7 @@ app = EEApp()
def main(): def main():
try: try:
global sys
# Default our exit status to 0 (non-error) # Default our exit status to 0 (non-error)
code = 0 code = 0
@ -91,6 +93,9 @@ def main():
# Setup the application # Setup the application
app.setup() app.setup()
# Dump all arguments into ee log
app.log.debug(sys.argv)
# Run the application # Run the application
app.run() app.run()
except exc.EEError as e: except exc.EEError as e:

19
ee/cli/plugins/clean.py

@ -29,25 +29,31 @@ class EECleanController(CementBaseController):
(['--memcache'], (['--memcache'],
dict(help='Clean MemCache', action='store_true')), dict(help='Clean MemCache', action='store_true')),
(['--opcache'], (['--opcache'],
dict(help='Clean OpCache', action='store_true')) dict(help='Clean OpCache', action='store_true')),
(['--pagespeed'],
dict(help='Clean Pagespeed Cache', action='store_true')),
] ]
usage = "ee clean [options]" usage = "ee clean [options]"
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
if (not (self.app.pargs.all or self.app.pargs.fastcgi or if (not (self.app.pargs.all or self.app.pargs.fastcgi or
self.app.pargs.memcache or self.app.pargs.opcache)): self.app.pargs.memcache or self.app.pargs.opcache or
self.app.pargs.pagespeed)):
self.clean_fastcgi() self.clean_fastcgi()
if self.app.pargs.all: if self.app.pargs.all:
self.clean_memcache() self.clean_memcache()
self.clean_fastcgi() self.clean_fastcgi()
self.clean_opcache() self.clean_opcache()
self.clean_pagespeed()
if self.app.pargs.fastcgi: if self.app.pargs.fastcgi:
self.clean_fastcgi() self.clean_fastcgi()
if self.app.pargs.memcache: if self.app.pargs.memcache:
self.clean_memcache() self.clean_memcache()
if self.app.pargs.opcache: if self.app.pargs.opcache:
self.clean_opcache() self.clean_opcache()
if self.app.pargs.pagespeed:
self.clean_pagespeed()
@expose(hide=True) @expose(hide=True)
def clean_memcache(self): def clean_memcache(self):
@ -82,6 +88,15 @@ class EECleanController(CementBaseController):
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to clean OpCache") Log.error(self, "Unable to clean OpCache")
@expose(hide=True)
def clean_pagespeed(self):
"""This function clears Pagespeed cache"""
if(os.path.isdir("/var/ngx_pagespeed_cache")):
Log.info(self, "Cleaning PageSpeed cache")
EEShellExec.cmd_exec(self, "rm -rf /var/ngx_pagespeed_cache/*")
else:
Log.error(self, "Unable to clean Pagespeed cache")
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

8
ee/cli/plugins/debug.py

@ -164,9 +164,9 @@ class EEDebugController(CementBaseController):
"conf.d/upstream.conf " "conf.d/upstream.conf "
"| grep 9001")): "| grep 9001")):
Log.info(self, "Enabling PHP debug") Log.info(self, "Enabling PHP debug")
data = dict(php="9001", debug="9001") data = dict(php="9001", debug="9001", hhvm="9001")
Log.info(self, 'Writting the Nginx debug configration to file ' Log.debug(self, 'Writting the Nginx debug configration to file'
'/etc/nginx/conf.d/upstream.conf ') ' /etc/nginx/conf.d/upstream.conf ')
ee_nginx = open('/etc/nginx/conf.d/upstream.conf', ee_nginx = open('/etc/nginx/conf.d/upstream.conf',
encoding='utf-8', mode='w') encoding='utf-8', mode='w')
self.app.render((data), 'upstream.mustache', out=ee_nginx) self.app.render((data), 'upstream.mustache', out=ee_nginx)
@ -190,7 +190,7 @@ class EEDebugController(CementBaseController):
"/etc/nginx/conf.d/upstream.conf " "/etc/nginx/conf.d/upstream.conf "
"| grep 9001"): "| grep 9001"):
Log.info(self, "Disabling PHP debug") Log.info(self, "Disabling PHP debug")
data = dict(php="9000", debug="9001") data = dict(php="9000", debug="9001", hhvm="8000")
Log.debug(self, 'Writting the Nginx debug configration to file' Log.debug(self, 'Writting the Nginx debug configration to file'
' /etc/nginx/conf.d/upstream.conf ') ' /etc/nginx/conf.d/upstream.conf ')
ee_nginx = open('/etc/nginx/conf.d/upstream.conf', ee_nginx = open('/etc/nginx/conf.d/upstream.conf',

463
ee/cli/plugins/log.py

@ -7,8 +7,11 @@ from ee.cli.plugins.site_functions import logwatch
from ee.core.variables import EEVariables from ee.core.variables import EEVariables
from ee.core.fileutils import EEFileUtils from ee.core.fileutils import EEFileUtils
from ee.core.shellexec import EEShellExec from ee.core.shellexec import EEShellExec
from ee.core.sendmail import EESendMail
from ee.core.mysql import EEMysql
import os import os
import glob import glob
import gzip
def ee_log_hook(app): def ee_log_hook(app):
@ -19,9 +22,22 @@ def ee_log_hook(app):
class EELogController(CementBaseController): class EELogController(CementBaseController):
class Meta: class Meta:
label = 'log' label = 'log'
description = 'Show Nginx, PHP, MySQL log file' description = 'Perform operations on Nginx, PHP, MySQL log file'
stacked_on = 'base' stacked_on = 'base'
stacked_type = 'nested' stacked_type = 'nested'
usage = "ee log [<site_name>] [options]"
@expose(hide=True)
def default(self):
self.app.args.print_help()
class EELogShowController(CementBaseController):
class Meta:
label = 'show'
description = 'Show Nginx, PHP, MySQL log file'
stacked_on = 'log'
stacked_type = 'nested'
arguments = [ arguments = [
(['--all'], (['--all'],
dict(help='Show All logs file', action='store_true')), dict(help='Show All logs file', action='store_true')),
@ -43,11 +59,11 @@ class EELogController(CementBaseController):
(['site_name'], (['site_name'],
dict(help='Website Name', nargs='?', default=None)) dict(help='Website Name', nargs='?', default=None))
] ]
usage = "ee log [<site_name>] [options]" usage = "ee log show [<site_name>] [options]"
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
"""Default function of debug""" """Default function of log show"""
self.msg = [] self.msg = []
if self.app.pargs.php: if self.app.pargs.php:
@ -86,14 +102,17 @@ class EELogController(CementBaseController):
if os.path.isfile('/var/log/mysql/mysql-slow.log'): if os.path.isfile('/var/log/mysql/mysql-slow.log'):
self.msg = self.msg + ['/var/log/mysql/mysql-slow.log'] self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
else: else:
Log.error(self, "Unable to find MySQL slow log file," Log.info(self, "MySQL slow-log not found, skipped")
"Please generate it using commnad ee debug "
"--mysql")
else: else:
Log.warn(self, "Remote MySQL found, EasyEngine is not able to" Log.warn(self, "Remote MySQL found, EasyEngine is not able to"
"show MySQL log file") "show MySQL log file")
if self.app.pargs.site_name: if self.app.pargs.site_name:
webroot = "{0}{1}".format(EEVariables.ee_webroot,
self.app.pargs.site_name)
if not os.path.isdir(webroot):
Log.error(self, "Site not present, quitting")
if self.app.pargs.access: if self.app.pargs.access:
self.msg = self.msg + ["{0}/{1}/logs/access.log" self.msg = self.msg + ["{0}/{1}/logs/access.log"
.format(EEVariables.ee_webroot, .format(EEVariables.ee_webroot,
@ -103,20 +122,20 @@ class EELogController(CementBaseController):
.format(EEVariables.ee_webroot, .format(EEVariables.ee_webroot,
self.app.pargs.site_name)] self.app.pargs.site_name)]
if self.app.pargs.wp: if self.app.pargs.wp:
webroot = "{0}{1}".format(EEVariables.ee_webroot, if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
self.app.pargs.site_name)
if not os.path.isfile('{0}/logs/debug.log' if not os.path.isfile('{0}/logs/debug.log'
.format(webroot)): .format(webroot)):
if not os.path.isfile('{0}/htdocs/wp-content/debug.log' if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
.format(webroot)): .format(webroot)):
open("{0}/htdocs/wp-content/debug.log".format(webroot), open("{0}/htdocs/wp-content/debug.log"
.format(webroot),
encoding='utf-8', mode='a').close() encoding='utf-8', mode='a').close()
EEShellExec.cmd_exec(self, "chown {1}: {0}/htdocs/wp-" EEShellExec.cmd_exec(self, "chown {1}: {0}/htdocs/"
"content/debug.log" "wp-content/debug.log"
"".format(webroot, "".format(webroot,
EEVariables.ee_php_user) EEVariables
.ee_php_user)
) )
# create symbolic link for debug log # create symbolic link for debug log
EEFileUtils.create_symlink(self, ["{0}/htdocs/wp-content/" EEFileUtils.create_symlink(self, ["{0}/htdocs/wp-content/"
"debug.log" "debug.log"
@ -127,6 +146,10 @@ class EELogController(CementBaseController):
self.msg = self.msg + ["{0}/{1}/logs/debug.log" self.msg = self.msg + ["{0}/{1}/logs/debug.log"
.format(EEVariables.ee_webroot, .format(EEVariables.ee_webroot,
self.app.pargs.site_name)] self.app.pargs.site_name)]
else:
Log.info(self, "Site is not WordPress site, skipping "
"WordPress logs")
watch_list = [] watch_list = []
for w_list in self.msg: for w_list in self.msg:
watch_list = watch_list + glob.glob(w_list) watch_list = watch_list + glob.glob(w_list)
@ -134,8 +157,422 @@ class EELogController(CementBaseController):
logwatch(self, watch_list) logwatch(self, watch_list)
class EELogResetController(CementBaseController):
class Meta:
label = 'reset'
description = 'Reset Nginx, PHP, MySQL log file'
stacked_on = 'log'
stacked_type = 'nested'
arguments = [
(['--all'],
dict(help='Reset All logs file', action='store_true')),
(['--nginx'],
dict(help='Reset Nginx Error logs file', action='store_true')),
(['--php'],
dict(help='Reset PHP Error logs file', action='store_true')),
(['--fpm'],
dict(help='Reset PHP5-fpm slow logs file',
action='store_true')),
(['--mysql'],
dict(help='Reset MySQL logs file', action='store_true')),
(['--wp'],
dict(help='Reset Site specific WordPress logs file',
action='store_true')),
(['--access'],
dict(help='Reset Nginx access log file',
action='store_true')),
(['--slow-log-db'],
dict(help='Drop all rows from slowlog table in database',
action='store_true')),
(['site_name'],
dict(help='Website Name', nargs='?', default=None))
]
usage = "ee log reset [<site_name>] [options]"
@expose(hide=True)
def default(self):
"""Default function of log reset"""
self.msg = []
if self.app.pargs.php:
self.app.pargs.nginx = True
if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
and (not self.app.pargs.mysql) and (not self.app.pargs.access)
and (not self.app.pargs.wp) and (not self.app.pargs.site_name)
and (not self.app.pargs.slow_log_db)):
self.app.pargs.nginx = True
self.app.pargs.fpm = True
self.app.pargs.mysql = True
self.app.pargs.access = True
self.app.pargs.slow_log_db = True
if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
and (not self.app.pargs.mysql) and (not self.app.pargs.access)
and (not self.app.pargs.wp) and (self.app.pargs.site_name)
and (not self.app.pargs.slow-log-db)):
self.app.pargs.nginx = True
self.app.pargs.wp = True
self.app.pargs.access = True
self.app.pargs.mysql = True
if self.app.pargs.slow_log_db:
if os.path.isdir("/var/www/22222/htdocs/db/anemometer"):
Log.info(self, "Resetting MySQL slow_query_log database table")
EEMysql.execute(self, "TRUNCATE TABLE "
"slow_query_log.global_query_review_history")
EEMysql.execute(self, "TRUNCATE TABLE "
"slow_query_log.global_query_review")
if self.app.pargs.nginx and (not self.app.pargs.site_name):
self.msg = self.msg + ["/var/log/nginx/*error.log"]
if self.app.pargs.access and (not self.app.pargs.site_name):
self.msg = self.msg + ["/var/log/nginx/*access.log"]
if self.app.pargs.fpm:
open('/var/log/php5/slow.log', 'a').close()
open('/var/log/php5/fpm.log', 'a').close()
self.msg = self.msg + ['/var/log/php5/slow.log',
'/var/log/php5/fpm.log']
if self.app.pargs.mysql:
# MySQL debug will not work for remote MySQL
if EEVariables.ee_mysql_host is "localhost":
if os.path.isfile('/var/log/mysql/mysql-slow.log'):
self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
else:
Log.info(self, "MySQL slow-log not found, skipped")
else:
Log.warn(self, "Remote MySQL found, EasyEngine is not able to"
"show MySQL log file")
if self.app.pargs.site_name:
webroot = "{0}{1}".format(EEVariables.ee_webroot,
self.app.pargs.site_name)
if not os.path.isdir(webroot):
Log.error(self, "Site not present, quitting")
if self.app.pargs.access:
self.msg = self.msg + ["{0}/{1}/logs/access.log"
.format(EEVariables.ee_webroot,
self.app.pargs.site_name)]
if self.app.pargs.nginx:
self.msg = self.msg + ["{0}/{1}/logs/error.log"
.format(EEVariables.ee_webroot,
self.app.pargs.site_name)]
if self.app.pargs.wp:
if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
if not os.path.isfile('{0}/logs/debug.log'
.format(webroot)):
if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
.format(webroot)):
open("{0}/htdocs/wp-content/debug.log"
.format(webroot),
encoding='utf-8', mode='a').close()
EEShellExec.cmd_exec(self, "chown {1}: {0}/htdocs/"
"wp-content/debug.log"
"".format(webroot,
EEVariables
.ee_php_user)
)
# create symbolic link for debug log
EEFileUtils.create_symlink(self, ["{0}/htdocs/wp-content/"
"debug.log"
.format(webroot),
'{0}/logs/debug.log'
.format(webroot)])
self.msg = self.msg + ["{0}/{1}/logs/debug.log"
.format(EEVariables.ee_webroot,
self.app.pargs.site_name)]
else:
Log.info(self, "Site is not WordPress site, skipping "
"WordPress logs")
reset_list = []
for r_list in self.msg:
reset_list = reset_list + glob.glob(r_list)
# Clearing content of file
for r_list in reset_list:
Log.info(self, "Resetting file {file}".format(file=r_list))
open(r_list, 'w').close()
class EELogGzipController(CementBaseController):
class Meta:
label = 'gzip'
description = 'GZip Nginx, PHP, MySQL log file'
stacked_on = 'log'
stacked_type = 'nested'
arguments = [
(['--all'],
dict(help='GZip All logs file', action='store_true')),
(['--nginx'],
dict(help='GZip Nginx Error logs file', action='store_true')),
(['--php'],
dict(help='GZip PHP Error logs file', action='store_true')),
(['--fpm'],
dict(help='GZip PHP5-fpm slow logs file',
action='store_true')),
(['--mysql'],
dict(help='GZip MySQL logs file', action='store_true')),
(['--wp'],
dict(help='GZip Site specific WordPress logs file',
action='store_true')),
(['--access'],
dict(help='GZip Nginx access log file',
action='store_true')),
(['site_name'],
dict(help='Website Name', nargs='?', default=None))
]
usage = "ee log gzip [<site_name>] [options]"
@expose(hide=True)
def default(self):
"""Default function of log GZip"""
self.msg = []
if self.app.pargs.php:
self.app.pargs.nginx = True
if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
and (not self.app.pargs.mysql) and (not self.app.pargs.access)
and (not self.app.pargs.wp) and (not self.app.pargs.site_name)):
self.app.pargs.nginx = True
self.app.pargs.fpm = True
self.app.pargs.mysql = True
self.app.pargs.access = True
if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
and (not self.app.pargs.mysql) and (not self.app.pargs.access)
and (not self.app.pargs.wp) and (self.app.pargs.site_name)):
self.app.pargs.nginx = True
self.app.pargs.wp = True
self.app.pargs.access = True
self.app.pargs.mysql = True
if self.app.pargs.nginx and (not self.app.pargs.site_name):
self.msg = self.msg + ["/var/log/nginx/*error.log"]
if self.app.pargs.access and (not self.app.pargs.site_name):
self.msg = self.msg + ["/var/log/nginx/*access.log"]
if self.app.pargs.fpm:
open('/var/log/php5/slow.log', 'a').close()
open('/var/log/php5/fpm.log', 'a').close()
self.msg = self.msg + ['/var/log/php5/slow.log',
'/var/log/php5/fpm.log']
if self.app.pargs.mysql:
# MySQL debug will not work for remote MySQL
if EEVariables.ee_mysql_host is "localhost":
if os.path.isfile('/var/log/mysql/mysql-slow.log'):
self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
else:
Log.info(self, "MySQL slow-log not found, skipped")
else:
Log.warn(self, "Remote MySQL found, EasyEngine is not able to"
"show MySQL log file")
if self.app.pargs.site_name:
webroot = "{0}{1}".format(EEVariables.ee_webroot,
self.app.pargs.site_name)
if not os.path.isdir(webroot):
Log.error(self, "Site not present, quitting")
if self.app.pargs.access:
self.msg = self.msg + ["{0}/{1}/logs/access.log"
.format(EEVariables.ee_webroot,
self.app.pargs.site_name)]
if self.app.pargs.nginx:
self.msg = self.msg + ["{0}/{1}/logs/error.log"
.format(EEVariables.ee_webroot,
self.app.pargs.site_name)]
if self.app.pargs.wp:
if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
if not os.path.isfile('{0}/logs/debug.log'
.format(webroot)):
if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
.format(webroot)):
open("{0}/htdocs/wp-content/debug.log"
.format(webroot),
encoding='utf-8', mode='a').close()
EEShellExec.cmd_exec(self, "chown {1}: {0}/htdocs/"
"wp-content/debug.log"
"".format(webroot,
EEVariables
.ee_php_user)
)
# create symbolic link for debug log
EEFileUtils.create_symlink(self, ["{0}/htdocs/wp-content/"
"debug.log"
.format(webroot),
'{0}/logs/debug.log'
.format(webroot)])
self.msg = self.msg + ["{0}/{1}/logs/debug.log"
.format(EEVariables.ee_webroot,
self.app.pargs.site_name)]
else:
Log.info(self, "Site is not WordPress site, skipping "
"WordPress logs")
gzip_list = []
for g_list in self.msg:
gzip_list = gzip_list + glob.glob(g_list)
# Gzip content of file
for g_list in gzip_list:
Log.info(self, "Gzipping file {file}".format(file=g_list))
in_file = g_list
in_data = open(in_file, "rb").read()
out_gz = g_list + ".gz"
gzf = gzip.open(out_gz, "wb")
gzf.write(in_data)
gzf.close()
class EELogMailController(CementBaseController):
class Meta:
label = 'mail'
description = 'Mail Nginx, PHP, MySQL log file'
stacked_on = 'log'
stacked_type = 'nested'
arguments = [
(['--all'],
dict(help='Mail All logs file', action='store_true')),
(['--nginx'],
dict(help='Mail Nginx Error logs file', action='store_true')),
(['--php'],
dict(help='Mail PHP Error logs file', action='store_true')),
(['--fpm'],
dict(help='Mail PHP5-fpm slow logs file',
action='store_true')),
(['--mysql'],
dict(help='Mail MySQL logs file', action='store_true')),
(['--wp'],
dict(help='Mail Site specific WordPress logs file',
action='store_true')),
(['--access'],
dict(help='Mail Nginx access log file',
action='store_true')),
(['site_name'],
dict(help='Website Name', nargs='?', default=None)),
(['--to'],
dict(help='EMail addresses to send log files', action='append',
dest='to', nargs=1, required=True)),
]
usage = "ee log mail [<site_name>] [options]"
@expose(hide=True)
def default(self):
"""Default function of log Mail"""
self.msg = []
if self.app.pargs.php:
self.app.pargs.nginx = True
if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
and (not self.app.pargs.mysql) and (not self.app.pargs.access)
and (not self.app.pargs.wp) and (not self.app.pargs.site_name)):
self.app.pargs.nginx = True
self.app.pargs.fpm = True
self.app.pargs.mysql = True
self.app.pargs.access = True
if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
and (not self.app.pargs.mysql) and (not self.app.pargs.access)
and (not self.app.pargs.wp) and (self.app.pargs.site_name)):
self.app.pargs.nginx = True
self.app.pargs.wp = True
self.app.pargs.access = True
self.app.pargs.mysql = True
if self.app.pargs.nginx and (not self.app.pargs.site_name):
self.msg = self.msg + ["/var/log/nginx/*error.log"]
if self.app.pargs.access and (not self.app.pargs.site_name):
self.msg = self.msg + ["/var/log/nginx/*access.log"]
if self.app.pargs.fpm:
open('/var/log/php5/slow.log', 'a').close()
open('/var/log/php5/fpm.log', 'a').close()
self.msg = self.msg + ['/var/log/php5/slow.log',
'/var/log/php5/fpm.log']
if self.app.pargs.mysql:
# MySQL debug will not work for remote MySQL
if EEVariables.ee_mysql_host is "localhost":
if os.path.isfile('/var/log/mysql/mysql-slow.log'):
self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
else:
Log.info(self, "MySQL slow-log not found, skipped")
else:
Log.warn(self, "Remote MySQL found, EasyEngine is not able to"
"show MySQL log file")
if self.app.pargs.site_name:
webroot = "{0}{1}".format(EEVariables.ee_webroot,
self.app.pargs.site_name)
if not os.path.isdir(webroot):
Log.error(self, "Site not present, quitting")
if self.app.pargs.access:
self.msg = self.msg + ["{0}/{1}/logs/access.log"
.format(EEVariables.ee_webroot,
self.app.pargs.site_name)]
if self.app.pargs.nginx:
self.msg = self.msg + ["{0}/{1}/logs/error.log"
.format(EEVariables.ee_webroot,
self.app.pargs.site_name)]
if self.app.pargs.wp:
if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
if not os.path.isfile('{0}/logs/debug.log'
.format(webroot)):
if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
.format(webroot)):
open("{0}/htdocs/wp-content/debug.log"
.format(webroot),
encoding='utf-8', mode='a').close()
EEShellExec.cmd_exec(self, "chown {1}: {0}/htdocs/"
"wp-content/debug.log"
"".format(webroot,
EEVariables
.ee_php_user)
)
# create symbolic link for debug log
EEFileUtils.create_symlink(self, ["{0}/htdocs/wp-content/"
"debug.log"
.format(webroot),
'{0}/logs/debug.log'
.format(webroot)])
self.msg = self.msg + ["{0}/{1}/logs/debug.log"
.format(EEVariables.ee_webroot,
self.app.pargs.site_name)]
else:
Log.info(self, "Site is not WordPress site, skipping "
"WordPress logs")
mail_list = []
for m_list in self.msg:
mail_list = mail_list + glob.glob(m_list)
for tomail in self.app.pargs.to:
Log.info(self, "Sending mail to {0}".format(tomail[0]))
EESendMail("easyengine", tomail[0], "{0} Log Files"
.format(EEVariables.ee_fqdn),
"Hey Hi,\n Please find attached server log files"
"\n\n\nYour's faithfully,\nEasyEngine",
files=mail_list, port=25, isTls=False)
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
handler.register(EELogController) handler.register(EELogController)
handler.register(EELogShowController)
handler.register(EELogResetController)
handler.register(EELogGzipController)
handler.register(EELogMailController)
# register a hook (function) to run after arguments are parsed. # register a hook (function) to run after arguments are parsed.
hook.register('post_argument_parsing', ee_log_hook) hook.register('post_argument_parsing', ee_log_hook)

378
ee/cli/plugins/site.py

@ -42,10 +42,13 @@ class EESiteController(CementBaseController):
def enable(self): def enable(self):
if not self.app.pargs.site_name: if not self.app.pargs.site_name:
try: try:
self.app.pargs.site_name = input('Enter site name : ') while not self.app.pargs.site_name:
self.app.pargs.site_name = (input('Enter site name : ')
.strip())
except IOError as e: except IOError as e:
Log.error(self, 'could not input site name') Log.error(self, 'could not input site name')
self.app.pargs.site_name = self.app.pargs.site_name.strip()
# validate domain name # validate domain name
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
@ -74,9 +77,13 @@ class EESiteController(CementBaseController):
def disable(self): def disable(self):
if not self.app.pargs.site_name: if not self.app.pargs.site_name:
try: try:
self.app.pargs.site_name = input('Enter site name : ') while not self.app.pargs.site_name:
self.app.pargs.site_name = (input('Enter site name : ')
.strip())
except IOError as e: except IOError as e:
Log.error(self, 'could not input site name') Log.error(self, 'could not input site name')
self.app.pargs.site_name = self.app.pargs.site_name.strip()
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
# check if site exists # check if site exists
if not check_domain_exists(self, ee_domain): if not check_domain_exists(self, ee_domain):
@ -108,13 +115,17 @@ class EESiteController(CementBaseController):
def info(self): def info(self):
if not self.app.pargs.site_name: if not self.app.pargs.site_name:
try: try:
self.app.pargs.site_name = input('Enter site name : ') while not self.app.pargs.site_name:
self.app.pargs.site_name = (input('Enter site name : ')
.strip())
except IOError as e: except IOError as e:
Log.error(self, 'could not input site name') Log.error(self, 'could not input site name')
self.app.pargs.site_name = self.app.pargs.site_name.strip()
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
ee_db_name = '' ee_db_name = ''
ee_db_user = '' ee_db_user = ''
ee_db_pass = '' ee_db_pass = ''
hhvm = ''
if not check_domain_exists(self, ee_domain): if not check_domain_exists(self, ee_domain):
Log.error(self, "site {0} does not exist".format(ee_domain)) Log.error(self, "site {0} does not exist".format(ee_domain))
@ -131,13 +142,17 @@ class EESiteController(CementBaseController):
ee_db_user = siteinfo.db_user ee_db_user = siteinfo.db_user
ee_db_pass = siteinfo.db_password ee_db_pass = siteinfo.db_password
ee_db_host = siteinfo.db_host ee_db_host = siteinfo.db_host
if sitetype != "html":
hhvm = ("enabled" if siteinfo.is_hhvm else "disabled")
pagespeed = ("enabled" if siteinfo.is_pagespeed else "disabled")
data = dict(domain=ee_domain, webroot=ee_site_webroot, data = dict(domain=ee_domain, webroot=ee_site_webroot,
accesslog=access_log, errorlog=error_log, accesslog=access_log, errorlog=error_log,
dbname=ee_db_name, dbuser=ee_db_user, dbname=ee_db_name, dbuser=ee_db_user,
dbpass=ee_db_pass, type=sitetype + " " + cachetype + dbpass=ee_db_pass, hhvm=hhvm, pagespeed=pagespeed,
" ({0})".format("enabled" type=sitetype + " " + cachetype + " ({0})"
if siteinfo.is_enabled else .format("enabled" if siteinfo.is_enabled else
"disabled")) "disabled"))
self.app.render((data), 'siteinfo.mustache') self.app.render((data), 'siteinfo.mustache')
else: else:
@ -146,6 +161,7 @@ class EESiteController(CementBaseController):
@expose(help="Monitor example.com logs") @expose(help="Monitor example.com logs")
def log(self): def log(self):
self.app.pargs.site_name = self.app.pargs.site_name.strip()
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
ee_site_webroot = getSiteInfo(self, ee_domain).site_path ee_site_webroot = getSiteInfo(self, ee_domain).site_path
@ -155,42 +171,17 @@ class EESiteController(CementBaseController):
if logfiles: if logfiles:
logwatch(self, logfiles) logwatch(self, logfiles)
@expose(help="Edit Nginx configuration of example.com")
def edit(self):
if not self.app.pargs.site_name:
try:
self.app.pargs.site_name = input('Enter site name : ')
except IOError as e:
Log.error(self, 'Unable to read input, Please try again')
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
if not check_domain_exists(self, ee_domain):
Log.error(self, "site {0} does not exist".format(ee_domain))
if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(ee_domain)):
try:
EEShellExec.invoke_editor(self, '/etc/nginx/sites-available/'
'{0}'.format(ee_domain))
except CommandExecutionError as e:
Log.error(self, "Failed invoke editor")
if (EEGit.checkfilestatus(self, "/etc/nginx",
'/etc/nginx/sites-available/{0}'.format(ee_domain))):
EEGit.add(self, ["/etc/nginx"], msg="Edit website: {0}"
.format(ee_domain))
# Reload NGINX
EEService.reload_service(self, 'nginx')
else:
Log.error(self, "nginx configuration file does not exists"
.format(ee_domain))
@expose(help="Display Nginx configuration of example.com") @expose(help="Display Nginx configuration of example.com")
def show(self): def show(self):
if not self.app.pargs.site_name: if not self.app.pargs.site_name:
try: try:
self.app.pargs.site_name = input('Enter site name : ') while not self.app.pargs.site_name:
self.app.pargs.site_name = (input('Enter site name : ')
.strip())
except IOError as e: except IOError as e:
Log.error(self, 'could not input site name') Log.error(self, 'could not input site name')
# TODO Write code for ee site edit command here # TODO Write code for ee site edit command here
self.app.pargs.site_name = self.app.pargs.site_name.strip()
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
if not check_domain_exists(self, ee_domain): if not check_domain_exists(self, ee_domain):
@ -213,10 +204,13 @@ class EESiteController(CementBaseController):
def cd(self): def cd(self):
if not self.app.pargs.site_name: if not self.app.pargs.site_name:
try: try:
self.app.pargs.site_name = input('Enter site name : ') while not self.app.pargs.site_name:
self.app.pargs.site_name = (input('Enter site name : ')
.strip())
except IOError as e: except IOError as e:
Log.error(self, 'Unable to read input, please try again') Log.error(self, 'Unable to read input, please try again')
self.app.pargs.site_name = self.app.pargs.site_name.strip()
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
if not check_domain_exists(self, ee_domain): if not check_domain_exists(self, ee_domain):
@ -232,6 +226,79 @@ class EESiteController(CementBaseController):
Log.error(self, "unable to change directory") Log.error(self, "unable to change directory")
class EESiteEditController(CementBaseController):
class Meta:
label = 'edit'
stacked_on = 'site'
stacked_type = 'nested'
description = ('Edit Nginx configuration of site')
arguments = [
(['site_name'],
dict(help='domain name for the site',
nargs='?')),
(['--pagespeed'],
dict(help="edit pagespeed configuration for site",
action='store_true')),
]
@expose(hide=True)
def default(self):
if not self.app.pargs.site_name:
try:
while not self.app.pargs.site_name:
self.app.pargs.site_name = (input('Enter site name : ')
.strip())
except IOError as e:
Log.error(self, 'Unable to read input, Please try again')
self.app.pargs.site_name = self.app.pargs.site_name.strip()
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
if not check_domain_exists(self, ee_domain):
Log.error(self, "site {0} does not exist".format(ee_domain))
ee_site_webroot = EEVariables.ee_webroot + ee_domain
if not self.app.pargs.pagespeed:
if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(ee_domain)):
try:
EEShellExec.invoke_editor(self, '/etc/nginx/sites-availa'
'ble/{0}'.format(ee_domain))
except CommandExecutionError as e:
Log.error(self, "Failed invoke editor")
if (EEGit.checkfilestatus(self, "/etc/nginx",
'/etc/nginx/sites-available/{0}'.format(ee_domain))):
EEGit.add(self, ["/etc/nginx"], msg="Edit website: {0}"
.format(ee_domain))
# Reload NGINX
EEService.reload_service(self, 'nginx')
else:
Log.error(self, "nginx configuration file does not exists"
.format(ee_domain))
elif self.app.pargs.pagespeed:
if os.path.isfile('{0}/conf/nginx/pagespeed.conf'
.format(ee_site_webroot)):
try:
EEShellExec.invoke_editor(self, '{0}/conf/nginx/'
'pagespeed.conf'
.format(ee_site_webroot))
except CommandExecutionError as e:
Log.error(self, "Failed invoke editor")
if (EEGit.checkfilestatus(self, "{0}/conf/nginx"
.format(ee_site_webroot),
'{0}/conf/nginx/pagespeed.conf'.format(ee_site_webroot))):
EEGit.add(self, ["{0}/conf/nginx".format(ee_site_webroot)],
msg="Edit Pagespped config of site: {0}"
.format(ee_domain))
# Reload NGINX
EEService.reload_service(self, 'nginx')
else:
Log.error(self, "Pagespeed configuration file does not exists"
.format(ee_domain))
class EESiteCreateController(CementBaseController): class EESiteCreateController(CementBaseController):
class Meta: class Meta:
label = 'create' label = 'create'
@ -267,6 +334,10 @@ class EESiteCreateController(CementBaseController):
(['--wpsc'], (['--wpsc'],
dict(help="create wordpress single/multi site with wpsc cache", dict(help="create wordpress single/multi site with wpsc cache",
action='store_true')), action='store_true')),
(['--hhvm'],
dict(help="create HHVM site", action='store_true')),
(['--pagespeed'],
dict(help="create pagespeed site", action='store_true')),
] ]
@expose(hide=True) @expose(hide=True)
@ -282,12 +353,21 @@ class EESiteCreateController(CementBaseController):
if not self.app.pargs.site_name: if not self.app.pargs.site_name:
try: try:
self.app.pargs.site_name = input('Enter site name : ') while not self.app.pargs.site_name:
# preprocessing before finalize site name
self.app.pargs.site_name = (input('Enter site name : ')
.strip())
except IOError as e: except IOError as e:
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.error(self, "Unable to input site name, Please try again!") Log.error(self, "Unable to input site name, Please try again!")
self.app.pargs.site_name = self.app.pargs.site_name.strip()
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
if not ee_domain.strip():
Log.error("Invalid domain name, "
"Provide valid domain name")
ee_site_webroot = EEVariables.ee_webroot + ee_domain ee_site_webroot = EEVariables.ee_webroot + ee_domain
if check_domain_exists(self, ee_domain): if check_domain_exists(self, ee_domain):
@ -324,6 +404,23 @@ class EESiteCreateController(CementBaseController):
if stype == 'wpsubdir': if stype == 'wpsubdir':
data['wpsubdir'] = True data['wpsubdir'] = True
if stype == "html" and self.app.pargs.hhvm:
Log.error(self, "Can not create HTML site with HHVM")
if data and self.app.pargs.hhvm:
data['hhvm'] = True
hhvm = 1
elif data:
data['hhvm'] = False
hhvm = 0
if data and self.app.pargs.pagespeed:
data['pagespeed'] = True
pagespeed = 1
elif data:
data['pagespeed'] = False
pagespeed = 0
if not data: if not data:
self.app.args.print_help() self.app.args.print_help()
self.app.close(1) self.app.close(1)
@ -345,7 +442,12 @@ class EESiteCreateController(CementBaseController):
Log.error(self, "Check logs for reason " Log.error(self, "Check logs for reason "
"`tail /var/log/ee/ee.log` & Try Again!!!") "`tail /var/log/ee/ee.log` & Try Again!!!")
addNewSite(self, ee_domain, stype, cache, ee_site_webroot) # Update pagespeed config
if self.app.pargs.pagespeed:
operateOnPagespeed(self, data)
addNewSite(self, ee_domain, stype, cache, ee_site_webroot,
hhvm=hhvm, pagespeed=pagespeed)
# Setup database for MySQL site # Setup database for MySQL site
if 'ee_db_name' in data.keys() and not data['wp']: if 'ee_db_name' in data.keys() and not data['wp']:
try: try:
@ -495,11 +597,22 @@ class EESiteUpdateController(CementBaseController):
dict(help="update to wpfc cache", action='store_true')), dict(help="update to wpfc cache", action='store_true')),
(['--wpsc'], (['--wpsc'],
dict(help="update to wpsc cache", action='store_true')), dict(help="update to wpsc cache", action='store_true')),
(['--hhvm'],
dict(help='Use HHVM for site',
action='store' or 'store_const',
choices=('on', 'off'), const='on', nargs='?')),
(['--pagespeed'],
dict(help='Use PageSpeed for site',
action='store' or 'store_const',
choices=('on', 'off'), const='on', nargs='?'))
] ]
@expose(help="Update site type or cache") @expose(help="Update site type or cache")
def default(self): def default(self):
hhvm = None
pagespeed = None
data = dict() data = dict()
try: try:
stype, cache = detSitePar(vars(self.app.pargs)) stype, cache = detSitePar(vars(self.app.pargs))
@ -510,10 +623,13 @@ class EESiteUpdateController(CementBaseController):
if not self.app.pargs.site_name: if not self.app.pargs.site_name:
try: try:
self.app.pargs.site_name = input('Enter site name : ') while not self.app.pargs.site_name:
self.app.pargs.site_name = (input('Enter site name : ')
.strip())
except IOError as e: except IOError as e:
Log.error(self, 'Unable to input site name, Please try again!') Log.error(self, 'Unable to input site name, Please try again!')
self.app.pargs.site_name = self.app.pargs.site_name.strip()
(ee_domain, (ee_domain,
ee_www_domain, ) = ValidateDomain(self.app.pargs.site_name) ee_www_domain, ) = ValidateDomain(self.app.pargs.site_name)
ee_site_webroot = EEVariables.ee_webroot + ee_domain ee_site_webroot = EEVariables.ee_webroot + ee_domain
@ -525,6 +641,8 @@ class EESiteUpdateController(CementBaseController):
else: else:
oldsitetype = check_site.site_type oldsitetype = check_site.site_type
oldcachetype = check_site.cache_type oldcachetype = check_site.cache_type
old_hhvm = check_site.is_hhvm
old_pagespeed = check_site.is_pagespeed
if (self.app.pargs.password and not (self.app.pargs.html or if (self.app.pargs.password and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.mysql or self.app.pargs.wp or self.app.pargs.php or self.app.pargs.mysql or self.app.pargs.wp or
@ -573,12 +691,125 @@ class EESiteUpdateController(CementBaseController):
if stype == 'wpsubdir': if stype == 'wpsubdir':
data['wpsubdir'] = True data['wpsubdir'] = True
if self.app.pargs.pagespeed or self.app.pargs.hhvm:
if not data:
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
currsitetype=oldsitetype,
currcachetype=oldcachetype,
webroot=ee_site_webroot)
stype = oldsitetype
cache = oldcachetype
if oldsitetype == 'html':
data['static'] = True
data['wp'] = False
data['multisite'] = False
data['wpsubdir'] = False
elif oldsitetype == 'php' or oldsitetype == 'mysql':
data['static'] = False
data['wp'] = False
data['multisite'] = False
data['wpsubdir'] = False
elif oldsitetype == 'wp':
data['static'] = False
data['wp'] = True
data['multisite'] = False
data['wpsubdir'] = False
elif oldsitetype == 'wpsubdir':
data['static'] = False
data['wp'] = True
data['multisite'] = True
data['wpsubdir'] = True
elif oldsitetype == 'wpsubdomain':
data['static'] = False
data['wp'] = True
data['multisite'] = True
data['wpsubdir'] = False
if oldcachetype == 'basic':
data['basic'] = True
data['w3tc'] = False
data['wpfc'] = False
data['wpsc'] = False
elif oldcachetype == 'w3tc':
data['basic'] = False
data['w3tc'] = True
data['wpfc'] = False
data['wpsc'] = False
elif oldcachetype == 'wpfc':
data['basic'] = False
data['w3tc'] = False
data['wpfc'] = True
data['wpsc'] = False
elif oldcachetype == 'wpsc':
data['basic'] = False
data['w3tc'] = False
data['wpfc'] = False
data['wpsc'] = True
if self.app.pargs.hhvm != 'off':
data['hhvm'] = True
hhvm = True
elif self.app.pargs.hhvm == 'off':
data['hhvm'] = False
hhvm = False
if self.app.pargs.pagespeed != 'off':
data['pagespeed'] = True
pagespeed = True
elif self.app.pargs.pagespeed == 'off':
data['pagespeed'] = False
pagespeed = False
if self.app.pargs.pagespeed:
if pagespeed is old_pagespeed:
if pagespeed is False:
Log.info(self, "Pagespeed is allready disabled for given "
"site")
elif pagespeed is True:
Log.info(self, "Pagespeed is allready enabled for given "
"site")
if self.app.pargs.hhvm:
if hhvm is old_hhvm:
if hhvm is False:
Log.info(self, "HHVM is allready disabled for given "
"site")
elif hhvm is True:
Log.info(self, "HHVM is allready enabled for given "
"site")
if data and (not self.app.pargs.hhvm):
if old_hhvm is True:
data['hhvm'] = True
hhvm = True
else:
data['hhvm'] = False
hhvm = False
if data and (not self.app.pargs.pagespeed):
if old_pagespeed is True:
data['pagespeed'] = True
pagespeed = True
else:
data['pagespeed'] = False
pagespeed = False
if self.app.pargs.pagespeed or self.app.pargs.hhvm:
if ((hhvm is old_hhvm) and (pagespeed is old_pagespeed) and
(stype == oldsitetype and cache == oldcachetype)):
self.app.close(0)
if not data: if not data:
Log.error(self, " Cannot update {0}, Invalid Options" Log.error(self, " Cannot update {0}, Invalid Options"
.format(ee_domain)) .format(ee_domain))
ee_auth = site_package_check(self, stype) ee_auth = site_package_check(self, stype)
data['ee_db_name'] = check_site.db_name
data['ee_db_user'] = check_site.db_user
data['ee_db_pass'] = check_site.db_password
data['ee_db_host'] = check_site.db_host
try: try:
sitebackup(self, data) sitebackup(self, data)
except Exception as e: except Exception as e:
@ -594,6 +825,22 @@ class EESiteUpdateController(CementBaseController):
Log.error(self, "Update site failed. Check logs for reason " Log.error(self, "Update site failed. Check logs for reason "
"`tail /var/log/ee/ee.log` & Try Again!!!") "`tail /var/log/ee/ee.log` & Try Again!!!")
# Update pagespeed config
if self.app.pargs.pagespeed:
operateOnPagespeed(self, data)
if stype == oldsitetype and cache == oldcachetype:
# Service Nginx Reload
EEService.reload_service(self, 'nginx')
updateSiteInfo(self, ee_domain, stype=stype, cache=cache,
hhvm=hhvm, pagespeed=pagespeed)
Log.info(self, "Successfully updated site"
" http://{0}".format(ee_domain))
self.app.close(0)
if 'ee_db_name' in data.keys() and not data['wp']: if 'ee_db_name' in data.keys() and not data['wp']:
try: try:
data = setupdatabase(self, data) data = setupdatabase(self, data)
@ -619,25 +866,25 @@ class EESiteUpdateController(CementBaseController):
Log.error(self, "Update site failed. Check logs for reason " Log.error(self, "Update site failed. Check logs for reason "
"`tail /var/log/ee/ee.log` & Try Again!!!") "`tail /var/log/ee/ee.log` & Try Again!!!")
if oldsitetype == 'mysql': # if oldsitetype == 'mysql':
config_file = (ee_site_webroot + '/backup/{0}/ee-config.php' # # config_file = (ee_site_webroot + '/backup/{0}/ee-config.php'
.format(EEVariables.ee_date)) # # .format(EEVariables.ee_date))
data['ee_db_name'] = (EEFileUtils.grep(self, config_file, # # data['ee_db_name'] = (EEFileUtils.grep(self, config_file,
'DB_NAME') # # 'DB_NAME')
.split(',')[1] # # .split(',')[1]
.split(')')[0].strip()) # # .split(')')[0].strip())
data['ee_db_user'] = (EEFileUtils.grep(self, config_file, # # data['ee_db_user'] = (EEFileUtils.grep(self, config_file,
'DB_USER') # # 'DB_USER')
.split(',')[1] # # .split(',')[1]
.split(')')[0].strip()) # # .split(')')[0].strip())
data['ee_db_pass'] = (EEFileUtils.grep(self, config_file, # # data['ee_db_pass'] = (EEFileUtils.grep(self, config_file,
'DB_PASSWORD') # # 'DB_PASSWORD')
.split(',')[1] # # .split(',')[1]
.split(')')[0].strip()) # # .split(')')[0].strip())
data['ee_db_host'] = (EEFileUtils.grep(self, config_file, # # data['ee_db_host'] = (EEFileUtils.grep(self, config_file,
'DB_HOST') # # 'DB_HOST')
.split(',')[1] # # .split(',')[1]
.split(')')[0].strip()) # # .split(')')[0].strip())
# Setup WordPress if old sites are html/php/mysql sites # Setup WordPress if old sites are html/php/mysql sites
if data['wp'] and oldsitetype in ['html', 'php', 'mysql']: if data['wp'] and oldsitetype in ['html', 'php', 'mysql']:
@ -723,9 +970,11 @@ class EESiteUpdateController(CementBaseController):
db_name=data['ee_db_name'], db_name=data['ee_db_name'],
db_user=data['ee_db_user'], db_user=data['ee_db_user'],
db_password=data['ee_db_pass'], db_password=data['ee_db_pass'],
db_host=data['ee_db_host']) db_host=data['ee_db_host'], hhvm=hhvm,
pagespeed=pagespeed)
else: else:
updateSiteInfo(self, ee_domain, stype=stype, cache=cache) updateSiteInfo(self, ee_domain, stype=stype, cache=cache,
hhvm=hhvm, pagespeed=pagespeed)
Log.info(self, "Successfully updated site" Log.info(self, "Successfully updated site"
" http://{0}".format(ee_domain)) " http://{0}".format(ee_domain))
@ -755,9 +1004,13 @@ class EESiteDeleteController(CementBaseController):
def default(self): def default(self):
if not self.app.pargs.site_name: if not self.app.pargs.site_name:
try: try:
self.app.pargs.site_name = input('Enter site name : ') while not self.app.pargs.site_name:
self.app.pargs.site_name = (input('Enter site name : ')
.strip())
except IOError as e: except IOError as e:
Log.error(self, 'could not input site name') Log.error(self, 'could not input site name')
self.app.pargs.site_name = self.app.pargs.site_name.strip()
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
ee_db_name = '' ee_db_name = ''
ee_prompt = '' ee_prompt = ''
@ -883,5 +1136,6 @@ def load(app):
handler.register(EESiteUpdateController) handler.register(EESiteUpdateController)
handler.register(EESiteDeleteController) handler.register(EESiteDeleteController)
handler.register(EESiteListController) handler.register(EESiteListController)
handler.register(EESiteEditController)
# register a hook (function) to run after arguments are parsed. # register a hook (function) to run after arguments are parsed.
hook.register('post_argument_parsing', ee_site_hook) hook.register('post_argument_parsing', ee_site_hook)

92
ee/cli/plugins/site_functions.py

@ -7,6 +7,7 @@ from ee.cli.plugins.sitedb import *
from ee.core.aptget import EEAptGet from ee.core.aptget import EEAptGet
from ee.core.git import EEGit from ee.core.git import EEGit
from ee.core.logging import Log from ee.core.logging import Log
from ee.core.services import EEService
import subprocess import subprocess
from subprocess import CalledProcessError from subprocess import CalledProcessError
import os import os
@ -88,6 +89,8 @@ def setupdomain(self, data):
os.makedirs('{0}/htdocs'.format(ee_site_webroot)) os.makedirs('{0}/htdocs'.format(ee_site_webroot))
if not os.path.exists('{0}/logs'.format(ee_site_webroot)): if not os.path.exists('{0}/logs'.format(ee_site_webroot)):
os.makedirs('{0}/logs'.format(ee_site_webroot)) os.makedirs('{0}/logs'.format(ee_site_webroot))
if not os.path.exists('{0}/conf/nginx'.format(ee_site_webroot)):
os.makedirs('{0}/conf/nginx'.format(ee_site_webroot))
EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.access.log' EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.access.log'
.format(ee_domain_name), .format(ee_domain_name),
@ -499,15 +502,16 @@ def sitebackup(self, data):
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
configfiles = glob.glob(ee_site_webroot + '/*-config.php') configfiles = glob.glob(ee_site_webroot + '/*-config.php')
# if configfiles and EEFileUtils.isexist(self, configfiles[0]):
if configfiles and EEFileUtils.isexist(self, configfiles[0]): # ee_db_name = (EEFileUtils.grep(self, configfiles[0],
ee_db_name = (EEFileUtils.grep(self, configfiles[0], # 'DB_NAME').split(',')[1]
'DB_NAME').split(',')[1] # .split(')')[0].strip().replace('\'', ''))
.split(')')[0].strip().replace('\'', '')) if data['ee_db_name']:
Log.info(self, 'Backing up database \t\t', end='') Log.info(self, 'Backing up database \t\t', end='')
try: try:
if not EEShellExec.cmd_exec(self, "mysqldump {0} > {1}/{0}.sql" if not EEShellExec.cmd_exec(self, "mysqldump {0} > {1}/{0}.sql"
.format(ee_db_name, backup_path)): .format(data['ee_db_name'],
backup_path)):
Log.info(self, Log.info(self,
"[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]") "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]")
raise SiteError("mysqldump failed to backup database") raise SiteError("mysqldump failed to backup database")
@ -529,7 +533,13 @@ def site_package_check(self, stype):
stack.app = self.app stack.app = self.app
if stype in ['html', 'php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']: if stype in ['html', 'php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
Log.debug(self, "Setting apt_packages variable for Nginx") Log.debug(self, "Setting apt_packages variable for Nginx")
if not EEAptGet.is_installed(self, 'nginx-common'):
if EEVariables.ee_platform_distro == 'Debian':
check_nginx = 'nginx-extras'
else:
check_nginx = 'nginx-custom'
if not EEAptGet.is_installed(self, check_nginx):
apt_packages = apt_packages + EEVariables.ee_nginx apt_packages = apt_packages + EEVariables.ee_nginx
if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']: if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
@ -555,6 +565,28 @@ def site_package_check(self, stype):
"wp-cli-{0}.phar" "wp-cli-{0}.phar"
.format(EEVariables.ee_wp_cli), .format(EEVariables.ee_wp_cli),
"/usr/bin/wp", "WP-CLI"]] "/usr/bin/wp", "WP-CLI"]]
if self.app.pargs.hhvm:
Log.debug(self, "Setting apt_packages variable for HHVM")
if not EEAptGet.is_installed(self, 'hhvm'):
apt_packages = apt_packages + EEVariables.ee_hhvm
# Check if Nginx is allready installed and Pagespeed config there or not
# If not then copy pagespeed config
if self.app.pargs.pagespeed:
if (os.path.isdir('/etc/nginx') and
(not os.path.isfile('/etc/nginx/conf.d/pagespeed.conf'))):
# Pagespeed configuration
data = dict()
Log.debug(self, 'Writting the Pagespeed Global '
'configuration to file /etc/nginx/conf.d/'
'pagespeed.conf')
ee_nginx = open('/etc/nginx/conf.d/pagespeed.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'pagespeed-global.mustache',
out=ee_nginx)
ee_nginx.close()
return(stack.install(apt_packages=apt_packages, packages=packages, return(stack.install(apt_packages=apt_packages, packages=packages,
disp_msg=False)) disp_msg=False))
@ -769,6 +801,14 @@ def deleteDB(self, dbname, dbuser, dbhost):
def deleteWebRoot(self, webroot): def deleteWebRoot(self, webroot):
# do some preprocessing before proceeding
webroot = webroot.strip()
if (webroot == "/var/www/" or webroot == "/var/www"
or webroot == "/var/www/.." or webroot == "/var/www/."):
Log.debug(self, "Tried to remove {0}, but didn't remove it"
.format(webroot))
return False
if os.path.isdir(webroot): if os.path.isdir(webroot):
Log.debug(self, "Removing {0}".format(webroot)) Log.debug(self, "Removing {0}".format(webroot))
EEFileUtils.rm(self, webroot) EEFileUtils.rm(self, webroot)
@ -786,6 +826,7 @@ def removeNginxConf(self, domain):
.format(domain)) .format(domain))
EEFileUtils.rm(self, '/etc/nginx/sites-available/{0}' EEFileUtils.rm(self, '/etc/nginx/sites-available/{0}'
.format(domain)) .format(domain))
EEService.reload_service(self, 'nginx')
EEGit.add(self, ["/etc/nginx"], EEGit.add(self, ["/etc/nginx"],
msg="Deleted {0} " msg="Deleted {0} "
.format(domain)) .format(domain))
@ -811,3 +852,40 @@ def doCleanupAction(self, domain='', webroot='', dbname='', dbuser='',
if not dbhost: if not dbhost:
raise SiteError("dbhost not provided") raise SiteError("dbhost not provided")
deleteDB(self, dbname, dbuser, dbhost) deleteDB(self, dbname, dbuser, dbhost)
def operateOnPagespeed(self, data):
ee_domain_name = data['site_name']
ee_site_webroot = data['webroot']
if data['pagespeed'] is True:
if not os.path.isfile("{0}/conf/nginx/pagespeed.conf.disabled"
.format(ee_site_webroot)):
Log.debug(self, 'Writting the Pagespeed common '
'configuration to file {0}/conf/nginx/pagespeed.conf'
'pagespeed.conf'.format(ee_site_webroot))
ee_nginx = open('{0}/conf/nginx/pagespeed.conf'
.format(ee_site_webroot), encoding='utf-8',
mode='w')
self.app.render((data), 'pagespeed-common.mustache',
out=ee_nginx)
ee_nginx.close()
else:
EEFileUtils.mvfile(self, "{0}/conf/nginx/pagespeed.conf.disabled"
.format(ee_site_webroot),
'{0}/conf/nginx/pagespeed.conf'
.format(ee_site_webroot))
elif data['pagespeed'] is False:
if os.path.isfile("{0}/conf/nginx/pagespeed.conf"
.format(ee_site_webroot)):
EEFileUtils.mvfile(self, "{0}/conf/nginx/pagespeed.conf"
.format(ee_site_webroot),
'{0}/conf/nginx/pagespeed.conf.disabled'
.format(ee_site_webroot))
# Add nginx conf folder into GIT
EEGit.add(self, ["{0}/conf/nginx".format(ee_site_webroot)],
msg="Adding Pagespeed config of site: {0}"
.format(ee_domain_name))

14
ee/cli/plugins/sitedb.py

@ -12,13 +12,14 @@ import glob
def addNewSite(self, site, stype, cache, path, def addNewSite(self, site, stype, cache, path,
enabled=True, ssl=False, fs='ext4', db='mysql', enabled=True, ssl=False, fs='ext4', db='mysql',
db_name=None, db_user=None, db_password=None, db_name=None, db_user=None, db_password=None,
db_host='localhost'): db_host='localhost', hhvm=0, pagespeed=0):
""" """
Add New Site record information into ee database. Add New Site record information into ee database.
""" """
try: try:
newRec = SiteDB(site, stype, cache, path, enabled, ssl, fs, db, newRec = SiteDB(site, stype, cache, path, enabled, ssl, fs, db,
db_name, db_user, db_password, db_host) db_name, db_user, db_password, db_host, hhvm,
pagespeed)
db_session.add(newRec) db_session.add(newRec)
db_session.commit() db_session.commit()
except Exception as e: except Exception as e:
@ -40,7 +41,8 @@ def getSiteInfo(self, site):
def updateSiteInfo(self, site, stype='', cache='', webroot='', def updateSiteInfo(self, site, stype='', cache='', webroot='',
enabled=True, ssl=False, fs='', db='', db_name=None, enabled=True, ssl=False, fs='', db='', db_name=None,
db_user=None, db_password=None, db_host=None): db_user=None, db_password=None, db_host=None, hhvm=None,
pagespeed=None):
"""updates site record in database""" """updates site record in database"""
try: try:
q = SiteDB.query.filter(SiteDB.sitename == site).first() q = SiteDB.query.filter(SiteDB.sitename == site).first()
@ -79,6 +81,12 @@ def updateSiteInfo(self, site, stype='', cache='', webroot='',
if webroot and q.site_path != webroot: if webroot and q.site_path != webroot:
q.site_path = webroot q.site_path = webroot
if (hhvm is not None) and (q.is_hhvm is not hhvm):
q.is_hhvm = hhvm
if (pagespeed is not None) and (q.is_pagespeed is not pagespeed):
q.is_pagespeed = pagespeed
try: try:
q.created_on = func.now() q.created_on = func.now()
db_session.commit() db_session.commit()

200
ee/cli/plugins/stack.py

@ -58,6 +58,8 @@ class EEStackController(CementBaseController):
dict(help='Install PHP stack', action='store_true')), dict(help='Install PHP stack', action='store_true')),
(['--mysql'], (['--mysql'],
dict(help='Install MySQL stack', action='store_true')), dict(help='Install MySQL stack', action='store_true')),
(['--hhvm'],
dict(help='Install HHVM stack', action='store_true')),
(['--postfix'], (['--postfix'],
dict(help='Install Postfix stack', action='store_true')), dict(help='Install Postfix stack', action='store_true')),
(['--wpcli'], (['--wpcli'],
@ -166,6 +168,16 @@ class EEStackController(CementBaseController):
Log.debug(self, 'Adding ppa for PHP') Log.debug(self, 'Adding ppa for PHP')
EERepo.add(self, ppa=EEVariables.ee_php_repo) EERepo.add(self, ppa=EEVariables.ee_php_repo)
if set(EEVariables.ee_hhvm).issubset(set(apt_packages)):
Log.info(self, "Adding repository for HHVM, please wait ...")
if EEVariables.ee_platform_codename == 'precise':
Log.debug(self, 'Adding PPA for Boost')
EERepo.add(self, ppa=EEVariables.ee_boost_repo)
Log.debug(self, 'Adding ppa repo for HHVM')
EERepo.add(self, repo_url=EEVariables.ee_hhvm_repo)
Log.debug(self, 'Adding HHVM GPG Key')
EERepo.add_key(self, '0x5a16e7281be7a449')
if set(EEVariables.ee_mail).issubset(set(apt_packages)): if set(EEVariables.ee_mail).issubset(set(apt_packages)):
Log.debug(self, 'Executing the command debconf-set-selections.') Log.debug(self, 'Executing the command debconf-set-selections.')
try: try:
@ -229,7 +241,7 @@ class EEStackController(CementBaseController):
self.app.render((data), 'fastcgi.mustache', out=ee_nginx) self.app.render((data), 'fastcgi.mustache', out=ee_nginx)
ee_nginx.close() ee_nginx.close()
data = dict(php="9000", debug="9001") data = dict(php="9000", debug="9001", hhvm="8000")
Log.debug(self, 'Writting the nginx configuration to ' Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/conf.d/upstream.conf ') 'file /etc/nginx/conf.d/upstream.conf ')
ee_nginx = open('/etc/nginx/conf.d/upstream.conf', ee_nginx = open('/etc/nginx/conf.d/upstream.conf',
@ -261,7 +273,39 @@ class EEStackController(CementBaseController):
ee_nginx.close() ee_nginx.close()
Log.debug(self, 'Writting the nginx configuration to ' Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/ php.conf') 'file /etc/nginx/common/php-hhvm.conf')
ee_nginx = open('/etc/nginx/common/php-hhvm.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'php-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/w3tc-hhvm.conf')
ee_nginx = open('/etc/nginx/common/w3tc-hhvm.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'w3tc-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpfc-hhvm.conf')
ee_nginx = open('/etc/nginx/common/wpfc-hhvm.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpfc-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpsc-hhvm.conf')
ee_nginx = open('/etc/nginx/common/wpsc-hhvm.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpsc-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/php.conf')
ee_nginx = open('/etc/nginx/common/php.conf', ee_nginx = open('/etc/nginx/common/php.conf',
encoding='utf-8', mode='w') encoding='utf-8', mode='w')
self.app.render((data), 'php.mustache', self.app.render((data), 'php.mustache',
@ -308,6 +352,16 @@ class EEStackController(CementBaseController):
out=ee_nginx) out=ee_nginx)
ee_nginx.close() ee_nginx.close()
# Pagespeed configuration
Log.debug(self, 'Writting the Pagespeed Global '
'configuration to file /etc/nginx/conf.d/'
'pagespeed.conf')
ee_nginx = open('/etc/nginx/conf.d/pagespeed.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'pagespeed-global.mustache',
out=ee_nginx)
ee_nginx.close()
# 22222 port settings # 22222 port settings
Log.debug(self, 'Writting the nginx configuration to ' Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/sites-available/' 'file /etc/nginx/sites-available/'
@ -533,6 +587,81 @@ class EEStackController(CementBaseController):
EEGit.add(self, ["/etc/php5"], msg="Adding PHP into Git") EEGit.add(self, ["/etc/php5"], msg="Adding PHP into Git")
EEService.reload_service(self, 'php5-fpm') EEService.reload_service(self, 'php5-fpm')
if set(EEVariables.ee_hhvm).issubset(set(apt_packages)):
EEFileUtils.searchreplace(self, "/etc/hhvm/server.ini",
"9000", "8000")
EEFileUtils.searchreplace(self, "/etc/nginx/hhvm.conf",
"9000", "8000")
with open("/etc/hhvm/php.ini", "a") as hhvm_file:
hhvm_file.write("hhvm.log.header = true\n"
"hhvm.log.natives_stack_trace = true\n"
"hhvm.mysql.socket = "
"/var/run/mysqld/mysqld.sock\n"
"hhvm.pdo_mysql.socket = "
"/var/run/mysqld/mysqld.sock\n"
"hhvm.mysqli.socket = "
"/var/run/mysqld/mysqld.sock\n")
if os.path.isfile("/etc/nginx/conf.d/fastcgi.conf"):
if not EEFileUtils.grep(self, "/etc/nginx/conf.d/"
"fastcgi.conf",
"fastcgi_keep_conn"):
with open("/etc/nginx/conf.d/fastcgi.conf",
"a") as hhvm_file:
hhvm_file.write("fastcgi_keep_conn on;\n")
if os.path.isfile("/etc/nginx/conf.d/upstream.conf"):
if not EEFileUtils.grep(self, "/etc/nginx/conf.d/"
"upstream.conf",
"hhvm"):
with open("/etc/nginx/conf.d/upstream.conf",
"a") as hhvm_file:
hhvm_file.write("upstream hhvm {\nserver "
"127.0.0.1:8000;\n"
"server 127.0.0.1:9000 backup;\n}"
"\n")
EEGit.add(self, ["/etc/hhvm"], msg="Adding HHVM into Git")
EEService.restart_service(self, 'hhvm')
EEService.reload_service(self, 'nginx')
if os.path.isdir("/etc/nginx") and (not
os.path.isfile("/etc/nginx/common/php-hhvm.conf")):
data = dict()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/php-hhvm.conf')
ee_nginx = open('/etc/nginx/common/php-hhvm.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'php-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/w3tc-hhvm.conf')
ee_nginx = open('/etc/nginx/common/w3tc-hhvm.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'w3tc-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpfc-hhvm.conf')
ee_nginx = open('/etc/nginx/common/wpfc-hhvm.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpfc-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpsc-hhvm.conf')
ee_nginx = open('/etc/nginx/common/wpsc-hhvm.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpsc-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
if set(EEVariables.ee_mysql).issubset(set(apt_packages)): if set(EEVariables.ee_mysql).issubset(set(apt_packages)):
# TODO: Currently we are using, we need to remove it in future # TODO: Currently we are using, we need to remove it in future
# config = configparser.ConfigParser() # config = configparser.ConfigParser()
@ -1223,7 +1352,8 @@ class EEStackController(CementBaseController):
(not self.app.pargs.mail) and (not self.app.pargs.nginx) and (not self.app.pargs.mail) and (not self.app.pargs.nginx) and
(not self.app.pargs.php) and (not self.app.pargs.mysql) and (not self.app.pargs.php) and (not self.app.pargs.mysql) and
(not self.app.pargs.postfix) and (not self.app.pargs.wpcli) and (not self.app.pargs.postfix) and (not self.app.pargs.wpcli) and
(not self.app.pargs.phpmyadmin) and (not self.app.pargs.phpmyadmin) and (not self.app.pargs.hhvm)
and
(not self.app.pargs.adminer) and (not self.app.pargs.utils) and (not self.app.pargs.adminer) and (not self.app.pargs.utils) and
(not self.app.pargs.mailscanner) and (not self.app.pargs.all)): (not self.app.pargs.mailscanner) and (not self.app.pargs.all)):
self.app.pargs.web = True self.app.pargs.web = True
@ -1235,13 +1365,12 @@ class EEStackController(CementBaseController):
self.app.pargs.mail = True self.app.pargs.mail = True
if self.app.pargs.web: if self.app.pargs.web:
Log.debug(self, "Setting apt_packages variable for Nginx ,PHP"
" ,MySQL ")
self.app.pargs.nginx = True self.app.pargs.nginx = True
self.app.pargs.php = True self.app.pargs.php = True
self.app.pargs.mysql = True self.app.pargs.mysql = True
self.app.pargs.wpcli = True self.app.pargs.wpcli = True
self.app.pargs.postfix = True self.app.pargs.postfix = True
self.app.pargs.hhvm = True
if self.app.pargs.admin: if self.app.pargs.admin:
self.app.pargs.nginx = True self.app.pargs.nginx = True
@ -1285,7 +1414,13 @@ class EEStackController(CementBaseController):
if self.app.pargs.nginx: if self.app.pargs.nginx:
Log.debug(self, "Setting apt_packages variable for Nginx") Log.debug(self, "Setting apt_packages variable for Nginx")
if not EEAptGet.is_installed(self, 'nginx-common'):
if EEVariables.ee_platform_distro == 'Debian':
check_nginx = 'nginx-extras'
else:
check_nginx = 'nginx-custom'
if not EEAptGet.is_installed(self, check_nginx):
apt_packages = apt_packages + EEVariables.ee_nginx apt_packages = apt_packages + EEVariables.ee_nginx
else: else:
Log.debug(self, "Nginx already installed") Log.debug(self, "Nginx already installed")
@ -1297,6 +1432,15 @@ class EEStackController(CementBaseController):
else: else:
Log.debug(self, "PHP already installed") Log.debug(self, "PHP already installed")
Log.info(self, "PHP already installed") Log.info(self, "PHP already installed")
if self.app.pargs.hhvm:
Log.debug(self, "Setting apt packages variable for HHVM")
if not EEAptGet.is_installed(self, 'hhvm'):
apt_packages = apt_packages + EEVariables.ee_hhvm
else:
Log.debug(self, "HHVM already installed")
Log.info(self, "HHVM already installed")
if self.app.pargs.mysql: if self.app.pargs.mysql:
Log.debug(self, "Setting apt_packages variable for MySQL") Log.debug(self, "Setting apt_packages variable for MySQL")
if not EEShellExec.cmd_exec(self, "mysqladmin ping"): if not EEShellExec.cmd_exec(self, "mysqladmin ping"):
@ -1432,7 +1576,7 @@ class EEStackController(CementBaseController):
(not self.app.pargs.mail) and (not self.app.pargs.nginx) and (not self.app.pargs.mail) and (not self.app.pargs.nginx) and
(not self.app.pargs.php) and (not self.app.pargs.mysql) and (not self.app.pargs.php) and (not self.app.pargs.mysql) and
(not self.app.pargs.postfix) and (not self.app.pargs.wpcli) and (not self.app.pargs.postfix) and (not self.app.pargs.wpcli) and
(not self.app.pargs.phpmyadmin) and (not self.app.pargs.phpmyadmin) and (not self.app.pargs.hhvm) and
(not self.app.pargs.adminer) and (not self.app.pargs.utils) and (not self.app.pargs.adminer) and (not self.app.pargs.utils) and
(not self.app.pargs.mailscanner) and (not self.app.pargs.all)): (not self.app.pargs.mailscanner) and (not self.app.pargs.all)):
self.app.pargs.web = True self.app.pargs.web = True
@ -1446,6 +1590,7 @@ class EEStackController(CementBaseController):
if self.app.pargs.web: if self.app.pargs.web:
self.app.pargs.nginx = True self.app.pargs.nginx = True
self.app.pargs.php = True self.app.pargs.php = True
self.app.pargs.hhvm = True
self.app.pargs.mysql = True self.app.pargs.mysql = True
self.app.pargs.wpcli = True self.app.pargs.wpcli = True
self.app.pargs.postfix = True self.app.pargs.postfix = True
@ -1476,6 +1621,12 @@ class EEStackController(CementBaseController):
if self.app.pargs.php: if self.app.pargs.php:
Log.debug(self, "Removing apt_packages variable of PHP") Log.debug(self, "Removing apt_packages variable of PHP")
apt_packages = apt_packages + EEVariables.ee_php apt_packages = apt_packages + EEVariables.ee_php
if self.app.pargs.hhvm:
if EEAptGet.is_installed(self, 'hhvm'):
Log.debug(self, "Removing apt_packages varible of HHVM")
apt_packages = apt_packages + EEVariables.ee_hhvm
if self.app.pargs.mysql: if self.app.pargs.mysql:
Log.debug(self, "Removing apt_packages variable of MySQL") Log.debug(self, "Removing apt_packages variable of MySQL")
apt_packages = apt_packages + EEVariables.ee_mysql apt_packages = apt_packages + EEVariables.ee_mysql
@ -1506,15 +1657,27 @@ class EEStackController(CementBaseController):
'/usr/bin/pt-query-advisor', '/usr/bin/pt-query-advisor',
'{0}22222/htdocs/db/anemometer' '{0}22222/htdocs/db/anemometer'
.format(EEVariables.ee_webroot)] .format(EEVariables.ee_webroot)]
ee_prompt = input('Are you sure you to want to'
' purge from server.'
'Package configuration will remain'
' on server after this operation.\n'
'Any answer other than '
'"yes" will be stop this'
' operation : ')
if len(apt_packages): if len(apt_packages):
if ee_prompt == 'YES' or ee_prompt == 'yes':
Log.debug(self, "Removing apt_packages") Log.debug(self, "Removing apt_packages")
Log.info(self, "Uninstalling packages, please wait ...") Log.info(self, "Removing packages, please wait ...")
EEAptGet.remove(self, apt_packages) EEAptGet.remove(self, apt_packages)
EEAptGet.auto_remove(self) EEAptGet.auto_remove(self)
if len(packages): if len(packages):
if ee_prompt == 'YES' or ee_prompt == 'yes':
EEFileUtils.remove(self, packages) EEFileUtils.remove(self, packages)
EEAptGet.auto_remove(self) EEAptGet.auto_remove(self)
if ee_prompt == 'YES' or ee_prompt == 'yes':
Log.info(self, "Successfully removed packages") Log.info(self, "Successfully removed packages")
@expose(help="Purge packages") @expose(help="Purge packages")
@ -1528,7 +1691,7 @@ class EEStackController(CementBaseController):
(not self.app.pargs.mail) and (not self.app.pargs.nginx) and (not self.app.pargs.mail) and (not self.app.pargs.nginx) and
(not self.app.pargs.php) and (not self.app.pargs.mysql) and (not self.app.pargs.php) and (not self.app.pargs.mysql) and
(not self.app.pargs.postfix) and (not self.app.pargs.wpcli) and (not self.app.pargs.postfix) and (not self.app.pargs.wpcli) and
(not self.app.pargs.phpmyadmin) and (not self.app.pargs.phpmyadmin) and (not self.app.pargs.hhvm) and
(not self.app.pargs.adminer) and (not self.app.pargs.utils) and (not self.app.pargs.adminer) and (not self.app.pargs.utils) and
(not self.app.pargs.mailscanner) and (not self.app.pargs.all)): (not self.app.pargs.mailscanner) and (not self.app.pargs.all)):
self.app.pargs.web = True self.app.pargs.web = True
@ -1545,6 +1708,7 @@ class EEStackController(CementBaseController):
self.app.pargs.mysql = True self.app.pargs.mysql = True
self.app.pargs.wpcli = True self.app.pargs.wpcli = True
self.app.pargs.postfix = True self.app.pargs.postfix = True
self.app.pargs.hhvm = True
if self.app.pargs.admin: if self.app.pargs.admin:
self.app.pargs.adminer = True self.app.pargs.adminer = True
@ -1572,6 +1736,10 @@ class EEStackController(CementBaseController):
if self.app.pargs.php: if self.app.pargs.php:
Log.debug(self, "Purge apt_packages variable PHP") Log.debug(self, "Purge apt_packages variable PHP")
apt_packages = apt_packages + EEVariables.ee_php apt_packages = apt_packages + EEVariables.ee_php
if self.app.pargs.hhvm:
if EEAptGet.is_installed(self, 'hhvm'):
Log.debug(self, "Removing apt_packages varible of HHVM")
apt_packages = apt_packages + EEVariables.ee_hhvm
if self.app.pargs.mysql: if self.app.pargs.mysql:
Log.debug(self, "Purge apt_packages variable MySQL") Log.debug(self, "Purge apt_packages variable MySQL")
apt_packages = apt_packages + EEVariables.ee_mysql apt_packages = apt_packages + EEVariables.ee_mysql
@ -1604,13 +1772,25 @@ class EEStackController(CementBaseController):
.format(EEVariables.ee_webroot) .format(EEVariables.ee_webroot)
] ]
ee_prompt = input('Are you sure you to want to purge '
'from server '
'alongwith their configuration'
' packages,\nAny answer other than '
'"yes" will be stop this '
'operation :')
if len(apt_packages): if len(apt_packages):
Log.info(self, "Uninstalling packages, please wait ...") if ee_prompt == 'YES' or ee_prompt == 'yes':
Log.info(self, "Purging packages, please wait ...")
EEAptGet.remove(self, apt_packages, purge=True) EEAptGet.remove(self, apt_packages, purge=True)
EEAptGet.auto_remove(self) EEAptGet.auto_remove(self)
if len(packages): if len(packages):
if ee_prompt == 'YES' or ee_prompt == 'yes':
EEFileUtils.remove(self, packages) EEFileUtils.remove(self, packages)
EEAptGet.auto_remove(self) EEAptGet.auto_remove(self)
if ee_prompt == 'YES' or ee_prompt == 'yes':
Log.info(self, "Successfully purged packages") Log.info(self, "Successfully purged packages")

52
ee/cli/plugins/stack_services.py

@ -38,6 +38,9 @@ class EEStackStatusController(CementBaseController):
if self.app.pargs.postfix: if self.app.pargs.postfix:
Log.debug(self, "postfix service start") Log.debug(self, "postfix service start")
services = services + ['postfix'] services = services + ['postfix']
if self.app.pargs.hhvm:
services = services + ['hhvm']
Log.debug(self, "hhvm service start")
if self.app.pargs.memcache: if self.app.pargs.memcache:
Log.debug(self, "memcached service start") Log.debug(self, "memcached service start")
services = services + ['memcached'] services = services + ['memcached']
@ -45,11 +48,12 @@ class EEStackStatusController(CementBaseController):
Log.debug(self, "dovecot service start") Log.debug(self, "dovecot service start")
services = services + ['dovecot'] services = services + ['dovecot']
if not services and EEVariables.ee_mysql_host is "localhost": if not services and EEVariables.ee_mysql_host is "localhost":
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix',
Log.debug(self, "nginx,php5-fpm,mysql,postfix services start") 'hhvm']
Log.debug(self, "nginx,php5-fpm,mysql,postfix,hhvm services start")
elif not services: elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix'] services = services + ['nginx', 'php5-fpm', 'postfix', 'hhvm']
Log.debug(self, "nginx,php5-fpm,postfix services start") Log.debug(self, "nginx,php5-fpm,postfix,hhvm services start")
for service in services: for service in services:
EEService.start_service(self, service) EEService.start_service(self, service)
@ -74,6 +78,9 @@ class EEStackStatusController(CementBaseController):
if self.app.pargs.postfix: if self.app.pargs.postfix:
Log.debug(self, "postfix service stop") Log.debug(self, "postfix service stop")
services = services + ['postfix'] services = services + ['postfix']
if self.app.pargs.hhvm:
services = services + ['hhvm']
Log.debug(self, "hhvm service stop")
if self.app.pargs.memcache: if self.app.pargs.memcache:
Log.debug(self, "memcached service stop") Log.debug(self, "memcached service stop")
services = services + ['memcached'] services = services + ['memcached']
@ -81,11 +88,12 @@ class EEStackStatusController(CementBaseController):
Log.debug(self, "dovecot service stop") Log.debug(self, "dovecot service stop")
services = services + ['dovecot'] services = services + ['dovecot']
if not services and EEVariables.ee_mysql_host is "localhost": if not services and EEVariables.ee_mysql_host is "localhost":
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix',
Log.debug(self, "nginx,php5-fpm,mysql,postfix services stop") 'hhvm']
Log.debug(self, "nginx,php5-fpm,mysql,postfix,hhvm services stop")
elif not services: elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix'] services = services + ['nginx', 'php5-fpm', 'postfix', 'hhvm']
Log.debug(self, "nginx,php5-fpm,postfix services stop") Log.debug(self, "nginx,php5-fpm,postfix,hhvm services stop")
for service in services: for service in services:
EEService.stop_service(self, service) EEService.stop_service(self, service)
@ -109,6 +117,9 @@ class EEStackStatusController(CementBaseController):
if self.app.pargs.postfix: if self.app.pargs.postfix:
Log.debug(self, "postfix service restart") Log.debug(self, "postfix service restart")
services = services + ['postfix'] services = services + ['postfix']
if self.app.pargs.hhvm:
services = services + ['hhvm']
Log.debug(self, "hhvm service restart")
if self.app.pargs.memcache: if self.app.pargs.memcache:
Log.debug(self, "memcached service restart") Log.debug(self, "memcached service restart")
services = services + ['memcached'] services = services + ['memcached']
@ -116,11 +127,13 @@ class EEStackStatusController(CementBaseController):
Log.debug(self, "dovecot service restart") Log.debug(self, "dovecot service restart")
services = services + ['dovecot'] services = services + ['dovecot']
if not services and EEVariables.ee_mysql_host is "localhost": if not services and EEVariables.ee_mysql_host is "localhost":
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix',
Log.debug(self, "nginx,php5-fpm,mysql,postfix services restart") 'hhvm']
Log.debug(self, "nginx,php5-fpm,mysql,postfix,hhvm services"
"restart")
elif not services: elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix'] services = services + ['nginx', 'php5-fpm', 'postfix', 'hhvm']
Log.debug(self, "nginx,php5-fpm,postfix services restart") Log.debug(self, "nginx,php5-fpm,postfix,hhvm services restart")
for service in services: for service in services:
EEService.restart_service(self, service) EEService.restart_service(self, service)
@ -144,6 +157,9 @@ class EEStackStatusController(CementBaseController):
if self.app.pargs.postfix: if self.app.pargs.postfix:
services = services + ['postfix'] services = services + ['postfix']
Log.debug(self, "postfix service status") Log.debug(self, "postfix service status")
if self.app.pargs.hhvm:
services = services + ['hhvm']
Log.debug(self, "hhvm service status")
if self.app.pargs.memcache: if self.app.pargs.memcache:
Log.debug(self, "memcached service status") Log.debug(self, "memcached service status")
services = services + ['memcached'] services = services + ['memcached']
@ -151,11 +167,13 @@ class EEStackStatusController(CementBaseController):
Log.debug(self, "dovecot service status") Log.debug(self, "dovecot service status")
services = services + ['dovecot'] services = services + ['dovecot']
if not services and EEVariables.ee_mysql_host is "localhost": if not services and EEVariables.ee_mysql_host is "localhost":
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix',
Log.debug(self, "nginx,php5-fpm,mysql,postfix services status") 'hhvm']
Log.debug(self, "nginx,php5-fpm,mysql,postfix,hhvm services"
" status")
elif not services: elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix'] services = services + ['nginx', 'php5-fpm', 'postfix', 'hhvm']
Log.debug(self, "nginx,php5-fpm,postfix services status") Log.debug(self, "nginx,php5-fpm,postfix,hhvm services status")
for service in services: for service in services:
if EEService.get_service_status(self, service): if EEService.get_service_status(self, service):
Log.info(self, "{0:10}: {1}".format(service, "Running")) Log.info(self, "{0:10}: {1}".format(service, "Running"))
@ -180,6 +198,8 @@ class EEStackStatusController(CementBaseController):
if self.app.pargs.postfix: if self.app.pargs.postfix:
Log.debug(self, "postfix service reload") Log.debug(self, "postfix service reload")
services = services + ['postfix'] services = services + ['postfix']
if self.app.pargs.hhvm:
Log.warn(self, "hhvm does not support to reload")
if self.app.pargs.memcache: if self.app.pargs.memcache:
Log.debug(self, "memcached service reload") Log.debug(self, "memcached service reload")
services = services + ['memcached'] services = services + ['memcached']

1
ee/cli/templates/fastcgi.mustache

@ -7,3 +7,4 @@ fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k; fastcgi_buffer_size 32k;
fastcgi_param SERVER_NAME $http_host; fastcgi_param SERVER_NAME $http_host;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie; fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_keep_conn on;

44
ee/cli/templates/pagespeed-common.mustache

@ -0,0 +1,44 @@
# HTTPS Support
# pagespeed FetchHttps enable;
# PageSpeed Filters
# CSS Minification
# pagespeed EnableFilters combine_css,rewrite_css;
# JS Minification
# pagespeed EnableFilters combine_javascript,rewrite_javascript;
# Images Optimization
#pagespeed EnableFilters lazyload_images;
#pagespeed EnableFilters rewrite_images;
#pagespeed EnableFilters convert_jpeg_to_progressive,convert_png_to_jpeg,convert_jpeg_to_webp,convert_to_webp_lossless;
# Remove comments from HTML
#pagespeed EnableFilters remove_comments;
# Remove WHITESPACE from HTML
#pagespeed EnableFilters collapse_whitespace;
# CDN Support
#pagespeed MapRewriteDomain cdn.example.com www.example.com;
###########################################################################################################################
# DO NOT EDIT AFTER THIS LINE #
###########################################################################################################################
# PageSpeed Admin
location /ngx_pagespeed_statistics { include common/acl.conf; }
location /ngx_pagespeed_global_statistics { include common/acl.conf; }
location /ngx_pagespeed_message { include common/acl.conf; }
location /pagespeed_console { include common/acl.conf; }
location ~ ^/pagespeed_admin { include common/acl.conf; }
location ~ ^/pagespeed_global_admin { include common/acl.conf; }
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }

21
ee/cli/templates/pagespeed-global.mustache

@ -0,0 +1,21 @@
# Turning the module on and off
pagespeed on;
# Configuring PageSpeed Filters
pagespeed RewriteLevel PassThrough;
# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed MemcachedServers "127.0.0.1:11211";
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# PageSpeed Admin
pagespeed StatisticsPath /ngx_pagespeed_statistics;
pagespeed GlobalStatisticsPath /ngx_pagespeed_global_statistics;
pagespeed MessagesPath /ngx_pagespeed_message;
pagespeed ConsolePath /pagespeed_console;
pagespeed AdminPath /pagespeed_admin;
pagespeed GlobalAdminPath /pagespeed_global_admin;
# PageSpeed Cache Purge
pagespeed EnableCachePurge on;
pagespeed PurgeMethod PURGE;

10
ee/cli/templates/php-hhvm.mustache

@ -0,0 +1,10 @@
# PHP NGINX CONFIGURATION
# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee)
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass hhvm;
}

2
ee/cli/templates/siteinfo.mustache

@ -1,6 +1,8 @@
Information about {{domain}}: Information about {{domain}}:
Nginx configuration {{type}} {{enable}} Nginx configuration {{type}} {{enable}}
{{#pagespeed}}Pagespeed {{pagespeed}}{{/pagespeed}}
{{#hhvm}}HHVM {{hhvm}}{{/hhvm}}
access_log {{accesslog}} access_log {{accesslog}}
error_log {{errorlog}} error_log {{errorlog}}
Webroot {{webroot}} Webroot {{webroot}}

5
ee/cli/templates/upstream.mustache

@ -7,3 +7,8 @@ upstream debug {
# Debug Pool # Debug Pool
server 127.0.0.1:{{debug}}; server 127.0.0.1:{{debug}};
} }
upstream hhvm {
# HHVM Pool
server 127.0.0.1:{{hhvm}};
server 127.0.0.1:{{php}} backup;
}

3
ee/cli/templates/virtualconf.mustache

@ -27,8 +27,9 @@ server {
} }
{{/static}} {{/static}}
{{^static}}include{{/static}} {{#basic}}common/php.conf;{{/basic}}{{#w3tc}}common/w3tc.conf;{{/w3tc}}{{#wpfc}}common/wpfc.conf;{{/wpfc}} {{#wpsc}}common/wpsc.conf;{{/wpsc}} {{^static}}include{{/static}} {{^hhvm}}{{#basic}}common/php.conf;{{/basic}}{{#w3tc}}common/w3tc.conf;{{/w3tc}}{{#wpfc}}common/wpfc.conf;{{/wpfc}} {{#wpsc}}common/wpsc.conf;{{/wpsc}} {{/hhvm}}{{#hhvm}}{{#basic}}common/php-hhvm.conf;{{/basic}}{{#w3tc}}common/w3tc-hhvm.conf;{{/w3tc}}{{#wpfc}}common/wpfc-hhvm.conf;{{/wpfc}} {{#wpsc}}common/wpsc-hhvm.conf;{{/wpsc}} {{/hhvm}}
{{#wpsubdir}}include common/wpsubdir.conf;{{/wpsubdir}} {{#wpsubdir}}include common/wpsubdir.conf;{{/wpsubdir}}
{{#wp}}include common/wpcommon.conf;{{/wp}} {{#wp}}include common/wpcommon.conf;{{/wp}}
include common/locations.conf; include common/locations.conf;
{{^vma}}{{^rc}}include {{webroot}}/conf/nginx/*.conf;{{/rc}}{{/vma}}
} }

31
ee/cli/templates/w3tc-hhvm.mustache

@ -0,0 +1,31 @@
# W3TC NGINX CONFIGURATION
# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee)
set $cache_uri $request_uri;
# POST requests and URL with a query string should always go to php
if ($request_method = POST) {
set $cache_uri 'null cache';
}
if ($query_string != "") {
set $cache_uri 'null cache';
}
# Don't cache URL containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|wp-.*.php|index.php|/feed/|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $cache_uri 'null cache';
}
# Don't use the cache for logged in users or recent commenter
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
set $cache_uri 'null cache';
}
# Use cached or actual file if they exists, Otherwise pass request to WordPress
location / {
try_files /wp-content/cache/page_enhanced/${host}${cache_uri}_index.html $uri $uri/ /index.php?$args;
}
location ~ ^/wp-content/cache/minify/(.+\.(css|js))$ {
try_files $uri /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass hhvm;
}

36
ee/cli/templates/wpfc-hhvm.mustache

@ -0,0 +1,36 @@
# WPFC NGINX CONFIGURATION
# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee)
set $skip_cache 0;
# POST requests and URL with a query string should always go to php
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
# Don't cache URL containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|wp-.*.php|index.php|/feed/|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $skip_cache 1;
}
# Don't use the cache for logged in users or recent commenter
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
# Use cached or actual file if they exists, Otherwise pass request to WordPress
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ ^/wp-content/cache/minify/(.+\.(css|js))$ {
try_files $uri /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass hhvm;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache WORDPRESS;
}
location ~ /purge(/.*) {
fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
}

31
ee/cli/templates/wpsc-hhvm.mustache

@ -0,0 +1,31 @@
# WPSC NGINX CONFIGURATION
# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee)
set $cache_uri $request_uri;
# POST requests and URL with a query string should always go to php
if ($request_method = POST) {
set $cache_uri 'null cache';
}
if ($query_string != "") {
set $cache_uri 'null cache';
}
# Don't cache URL containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|wp-.*.php|index.php|/feed/|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $cache_uri 'null cache';
}
# Don't use the cache for logged in users or recent commenter
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
set $cache_uri 'null cache';
}
# Use cached or actual file if they exists, Otherwise pass request to WordPress
location / {
# If we add index.php?$args its break WooCommerce like plugins
# Ref: #330
try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass hhvm;
# Following line is needed by WP Super Cache plugin
fastcgi_param SERVER_NAME $http_host;
}

1
ee/core/fileutils.py

@ -218,6 +218,7 @@ class EEFileUtils():
for line in open(fnm, encoding='utf-8'): for line in open(fnm, encoding='utf-8'):
if sstr in line: if sstr in line:
return line return line
return False
except OSError as e: except OSError as e:
Log.debug(self, "{0}".format(e.strerror)) Log.debug(self, "{0}".format(e.strerror))
Log.error(self, "Unable to Search string {0} in {1}" Log.error(self, "Unable to Search string {0} in {1}"

33
ee/core/sendmail.py

@ -0,0 +1,33 @@
import smtplib
import os
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
from email import encoders
def EESendMail(send_from, send_to, subject, text, files, server="localhost",
port=587, username='', password='', isTls=True):
msg = MIMEMultipart()
msg['From'] = send_from
msg['To'] = send_to
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject
msg.attach(MIMEText(text))
for f in files:
part = MIMEBase('application', "octet-stream")
part.set_payload(open(f, "rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="{0}"'
.format(os.path.basename(f)))
msg.attach(part)
smtp = smtplib.SMTP(server, port)
if isTls:
smtp.starttls()
smtp.sendmail(send_from, send_to, msg.as_string())
smtp.quit()

18
ee/core/variables.py

@ -12,7 +12,7 @@ class EEVariables():
"""Intialization of core variables""" """Intialization of core variables"""
# EasyEngine version # EasyEngine version
ee_version = "3.0.10" ee_version = "3.1.0"
# EasyEngine packages versions # EasyEngine packages versions
ee_wp_cli = "0.18.0" ee_wp_cli = "0.18.0"
@ -73,7 +73,7 @@ class EEVariables():
elif ee_platform_distro == 'debian': elif ee_platform_distro == 'debian':
ee_nginx_repo = ("deb http://packages.dotdeb.org {codename} all" ee_nginx_repo = ("deb http://packages.dotdeb.org {codename} all"
.format(codename=ee_platform_codename)) .format(codename=ee_platform_codename))
ee_nginx = ["nginx-full", "nginx-common"] ee_nginx = ["nginx-extras", "nginx-common"]
# PHP repo and packages # PHP repo and packages
if ee_platform_distro == 'Ubuntu': if ee_platform_distro == 'Ubuntu':
@ -116,6 +116,20 @@ class EEVariables():
"arj", "zoo", "nomarch", "lzop", "cabextract", "p7zip", "arj", "zoo", "nomarch", "lzop", "cabextract", "p7zip",
"rpm", "unrar-free"] "rpm", "unrar-free"]
# HHVM repo details
# 12.04 requires boot repository
if ee_platform_distro == 'Ubuntu':
if ee_platform_codename == "precise":
ee_boost_repo = ("ppa:mapnik/boost")
ee_hhvm_repo = ("deb http://dl.hhvm.com/ubuntu {codename} main"
.format(codename=ee_platform_codename))
else:
ee_hhvm_repo = ("deb http://dl.hhvm.com/debian {codename} main"
.format(codename=ee_platform_codename))
ee_hhvm = ["hhvm"]
# Repo path # Repo path
ee_repo_file = "ee-repo.list" ee_repo_file = "ee-repo.list"
ee_repo_file_path = ("/etc/apt/sources.list.d/" + ee_repo_file) ee_repo_file_path = ("/etc/apt/sources.list.d/" + ee_repo_file)

7
install

@ -48,7 +48,7 @@ fi
# Define variables for later use # Define variables for later use
ee_branch=$1 ee_branch=$1
readonly ee_version_old="2.2.3" readonly ee_version_old="2.2.3"
readonly ee_version_new="3.0.10" readonly ee_version_new="3.1.0"
readonly ee_log_dir=/var/log/ee/ readonly ee_log_dir=/var/log/ee/
readonly ee_install_log=/var/log/ee/install.log readonly ee_install_log=/var/log/ee/install.log
readonly ee_linux_distro=$(lsb_release -i | awk '{print $3}') readonly ee_linux_distro=$(lsb_release -i | awk '{print $3}')
@ -89,9 +89,9 @@ function ee_install_dep()
{ {
ee_lib_echo "Installing required packages, please wait..." ee_lib_echo "Installing required packages, please wait..."
if [ "$ee_linux_distro" == "Ubuntu" ]; then if [ "$ee_linux_distro" == "Ubuntu" ]; then
apt-get -y install gcc gzip python3 python3-apt python3-setuptools python3-dev sqlite3 git tar python-software-properties software-properties-common || ee_lib_error "Unable to install pre depedencies, exit status " 1 apt-get -y install gcc curl gzip python3 python3-apt python3-setuptools python3-dev sqlite3 git tar python-software-properties software-properties-common || ee_lib_error "Unable to install pre depedencies, exit status " 1
elif [ "$ee_linux_distro" == "Debian" ]; then elif [ "$ee_linux_distro" == "Debian" ]; then
apt-get -y install gcc gzip python3 python3-apt python3-setuptools python3-dev sqlite3 git tar python-software-properties || ee_lib_error "Unable to pre depedencies, exit status " 1 apt-get -y install gcc curl gzip python3 python3-apt python3-setuptools python3-dev sqlite3 git tar python-software-properties || ee_lib_error "Unable to pre depedencies, exit status " 1
fi fi
# Generating Locale # Generating Locale
@ -222,7 +222,6 @@ function secure_ee_db()
chmod -R 600 /var/lib/ee/ chmod -R 600 /var/lib/ee/
} }
# Install EasyEngine 3.x # Install EasyEngine 3.x
function ee_install() function ee_install()
{ {

2
setup.py

@ -54,7 +54,7 @@ except Exception as e:
os.system("git config --global user.email {0}".format(ee_email)) os.system("git config --global user.email {0}".format(ee_email))
setup(name='ee', setup(name='ee',
version='3.0.10', version='3.1.0',
description=long_description, description=long_description,
long_description=long_description, long_description=long_description,
classifiers=[], classifiers=[],

Loading…
Cancel
Save