Browse Source

Merge branch 'python'

bugfixes
gau1991 10 years ago
parent
commit
dba28ec2ed
  1. 1
      .travis.yml
  2. 22
      ee/cli/main.py
  3. 51
      ee/cli/plugins/debug.py
  4. 65
      ee/cli/plugins/site.py
  5. 12
      ee/cli/plugins/stack.py
  6. 75
      ee/cli/plugins/stack_services.py
  7. 4
      install

1
.travis.yml

@ -21,6 +21,7 @@ before_script:
- sudo apt-get update
script:
- unset LANG
- sudo echo -e "[user]\n\tname = abc\n\temail = root@localhost.com" > ~/.gitconfig
- sudo echo "Travis Banch = $TRAVIS_BRANCH"
- sudo apt-get install -y --force-yes git python3-setuptools python3-dev python3-apt

22
ee/cli/main.py

@ -13,8 +13,11 @@ else:
from cement.core import foundation
from cement.utils.misc import init_defaults
from cement.core.exc import FrameworkError, CaughtSignal
from cement.utils import fs
from cement.ext.ext_mustache import MustacheOutputHandler
from ee.core import exc
# Application default. Should update config/ee.conf to reflect any
# changes, or additions here.
defaults = init_defaults('ee')
@ -29,6 +32,23 @@ defaults['ee']['plugin_dir'] = '/var/lib/ee/plugins'
defaults['ee']['template_dir'] = '/var/lib/ee/templates'
# Based on https://github.com/datafolklabs/cement/issues/295
# To avoid encoding releated error,we defined our custom output handler
# I hope we will remove this when we upgarde to Cement 2.6 (Not released yet)
class EEOutputHandler(MustacheOutputHandler):
class Meta:
label = 'ee_output_handler'
def _load_template_from_file(self, path):
for templ_dir in self.app._meta.template_dirs:
full_path = fs.abspath(os.path.join(templ_dir, path))
if os.path.exists(full_path):
self.app.log.debug('loading template file %s' % full_path)
return open(full_path, encoding='utf-8', mode='r').read()
else:
continue
class EEApp(foundation.CementApp):
class Meta:
label = 'ee'
@ -50,7 +70,7 @@ class EEApp(foundation.CementApp):
extensions = ['mustache']
# default output handler
output_handler = 'mustache'
output_handler = EEOutputHandler
debug = TOGGLE_DEBUG

51
ee/cli/plugins/debug.py

@ -103,7 +103,7 @@ class EEDebugController(CementBaseController):
self.trigger_nginx = True
else:
Log.info(self, "Debug for site allready enabled")
Log.info(self, "Nginx debug for site already enabled")
self.msg = self.msg + ['{0}{1}/logs/error.log'
.format(EEVariables.ee_webroot,
@ -129,7 +129,7 @@ class EEDebugController(CementBaseController):
else:
Log.info(self, "Debug for site allready disabled")
Log.info(self, "Nginx debug for site already disabled")
else:
Log.info(self, "{0} domain not valid"
.format(self.app.pargs.site_name))
@ -154,7 +154,7 @@ class EEDebugController(CementBaseController):
self.trigger_php = True
self.trigger_nginx = True
else:
Log.info(self, "PHP debug is allready enabled")
Log.info(self, "PHP debug is already enabled")
self.msg = self.msg + ['/var/log/php5/slow.log']
@ -174,7 +174,7 @@ class EEDebugController(CementBaseController):
self.trigger_php = True
self.trigger_nginx = True
else:
Log.info(self, "PHP debug is allready disabled")
Log.info(self, "PHP debug is already disabled")
@expose(hide=True)
def debug_fpm(self):
@ -249,7 +249,7 @@ class EEDebugController(CementBaseController):
"n#EasyEngine end MySQL slow log\\\";"
" }} | crontab -\"".format(cron_time))
else:
Log.info(self, "MySQL slow log is allready enabled")
Log.info(self, "MySQL slow log is already enabled")
self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
@ -273,7 +273,7 @@ class EEDebugController(CementBaseController):
def debug_wp(self):
"""Start/Stop WordPress debug"""
if self.start and self.app.pargs.site_name:
wp_config = ("{0}{1}/wp-config.php"
wp_config = ("{0}/{1}/wp-config.php"
.format(EEVariables.ee_webroot,
self.app.pargs.site_name))
webroot = "{0}{1}".format(EEVariables.ee_webroot,
@ -301,8 +301,6 @@ class EEDebugController(CementBaseController):
"wp-content/plugins"
.format(webroot,
EEVariables.ee_php_user))
else:
Log.info(self, "WordPress debug log already enabled")
self.msg = self.msg + ['{0}{1}/htdocs/wp-content'
'/debug.log'
@ -337,9 +335,6 @@ class EEDebugController(CementBaseController):
"true);/d\" {0}".format(wp_config))
else:
Log.info(self, "WordPress debug all already disabled")
else:
Log.error(self, "{0} domain not valid"
.format(self.app.pargs.site_name))
else:
Log.error(self, "Missing argument site name")
@ -383,7 +378,7 @@ class EEDebugController(CementBaseController):
.format(config_path))
self.trigger_nginx = True
else:
Log.info(self, "Nginx rewrite logs for {0} allready setup"
Log.info(self, "Nginx rewrite logs for {0} already setup"
.format(self.app.pargs.site_name))
if ('{0}{1}/logs/error.log'.format(EEVariables.ee_webroot,
@ -405,7 +400,7 @@ class EEDebugController(CementBaseController):
.format(config_path))
self.trigger_nginx = True
else:
Log.info(self, "Nginx rewrite logs for {0} allready "
Log.info(self, "Nginx rewrite logs for {0} already "
" disabled".format(self.app.pargs.site_name))
@expose(hide=True)
@ -419,7 +414,12 @@ class EEDebugController(CementBaseController):
if self.app.pargs.fpm:
self.debug_fpm()
if self.app.pargs.mysql:
self.debug_mysql()
# MySQL debug will not work for remote MySQL
if EEVariables.ee_mysql_host is "localhost":
self.debug_mysql()
else:
Log.warn(self, "Remote MySQL found, EasyEngine will not "
"enable remote debug")
if self.app.pargs.wp:
self.debug_wp()
if self.app.pargs.rewrite:
@ -450,19 +450,19 @@ class EEDebugController(CementBaseController):
and (not self.app.pargs.fpm) and (not self.app.pargs.mysql)
and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
and (not self.app.pargs.site_name)):
self.debug_nginx()
self.debug_php()
self.debug_fpm()
self.debug_mysql()
self.debug_rewrite()
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.fpm = True
self.app.pargs.mysql = True
self.app.pargs.rewrite = True
if ((not self.app.pargs.nginx) and (not self.app.pargs.php)
and (not self.app.pargs.fpm) and (not self.app.pargs.mysql)
and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
and self.app.pargs.site_name):
self.debug_nginx()
self.debug_wp()
self.debug_rewrite()
self.app.pargs.nginx = True
self.app.pargs.wp = True
self.app.pargs.rewrite = True
if self.app.pargs.nginx:
self.debug_nginx()
@ -471,7 +471,12 @@ class EEDebugController(CementBaseController):
if self.app.pargs.fpm:
self.debug_fpm()
if self.app.pargs.mysql:
self.debug_mysql()
# MySQL debug will not work for remote MySQL
if EEVariables.ee_mysql_host is "localhost":
self.debug_mysql()
else:
Log.warn(self, "Remote MySQL found, EasyEngine will not "
"enable remote debug")
if self.app.pargs.wp:
self.debug_wp()
if self.app.pargs.rewrite:

65
ee/cli/plugins/site.py

@ -29,7 +29,7 @@ class EESiteController(CementBaseController):
description = ('Performs website specific operations')
arguments = [
(['site_name'],
dict(help='Website name')),
dict(help='Website name', nargs='?')),
]
@expose(hide=True)
@ -38,6 +38,11 @@ class EESiteController(CementBaseController):
@expose(help="Enable site example.com")
def enable(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, 'could not input site name')
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
Log.info(self, "Enable domain {0:10} \t".format(ee_domain), end='')
if os.path.isfile('/etc/nginx/sites-available/{0}'
@ -58,6 +63,11 @@ class EESiteController(CementBaseController):
@expose(help="Disable site example.com")
def disable(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, 'could not input site name')
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
Log.info(self, "Disable domain {0:10} \t".format(ee_domain), end='')
if os.path.isfile('/etc/nginx/sites-available/{0}'
@ -81,6 +91,11 @@ class EESiteController(CementBaseController):
@expose(help="Get example.com information")
def info(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, 'could not input site name')
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
ee_db_name = ''
ee_db_user = ''
@ -135,6 +150,11 @@ class EESiteController(CementBaseController):
@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, 'could not input site name')
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(ee_domain)):
@ -151,6 +171,11 @@ class EESiteController(CementBaseController):
@expose(help="Display Nginx configuration of example.com")
def show(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, 'could not input site name')
# TODO Write code for ee site edit command here
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
if os.path.isfile('/etc/nginx/sites-available/{0}'
@ -167,7 +192,11 @@ class EESiteController(CementBaseController):
@expose(help="Change directory to site webroot")
def cd(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, 'could not input site name')
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(ee_domain)):
@ -189,7 +218,8 @@ class EESiteCreateController(CementBaseController):
'required files as options are provided')
arguments = [
(['site_name'],
dict(help='domain name for the site to be created.')),
dict(help='domain name for the site to be created.',
nargs='?')),
(['--html'],
dict(help="create html site", action='store_true')),
(['--php'],
@ -220,6 +250,18 @@ class EESiteCreateController(CementBaseController):
def default(self):
# self.app.render((data), 'default.mustache')
# Check domain name validation
if not self.app.pargs.site_name:
try:
self.app.pargs.site_name = input('Enter site name : ')
except IOError as e:
Log.error(self, 'could not input site name')
if not (self.app.pargs.html or self.app.pargs.php or
self.app.pargs.mysql or self.app.pargs.wp or
self.app.pargs.w3tc or self.app.pargs.wpfc or
self.app.pargs.wpsc or self.app.pargs.wpsubdir or
self.app.pargs.wpsubdomain):
self.app.pargs.html = True
data = ''
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
ee_site_webroot = EEVariables.ee_webroot + ee_domain
@ -494,7 +536,8 @@ class EESiteUpdateController(CementBaseController):
'another as per the options are provided')
arguments = [
(['site_name'],
dict(help='domain name for the site to be updated')),
dict(help='domain name for the site to be updated',
nargs='?')),
(['--password'],
dict(help="update to password for wordpress site user",
action='store_true')),
@ -521,6 +564,11 @@ class EESiteUpdateController(CementBaseController):
@expose(help="Update site type or cache")
def default(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, 'could not input site name')
data = ''
(ee_domain,
ee_www_domain, ) = ValidateDomain(self.app.pargs.site_name)
@ -947,7 +995,7 @@ class EESiteDeleteController(CementBaseController):
description = 'delete an existing website'
arguments = [
(['site_name'],
dict(help='domain name to be deleted')),
dict(help='domain name to be deleted', nargs='?')),
(['--no-prompt'],
dict(help="doesnt ask permission for delete",
action='store_true')),
@ -962,12 +1010,15 @@ class EESiteDeleteController(CementBaseController):
@expose(help="Delete website configuration and files")
@expose(hide=True)
def default(self):
# TODO Write code for ee site update here
if not self.app.pargs.site_name:
try:
self.app.pargs.site_name = input('Enter site name : ')
except IOError as e:
Log.error(self, 'could not input site name')
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
ee_db_name = ''
ee_prompt = ''
ee_nginx_prompt = ''
if ((not self.app.pargs.db) and (not self.app.pargs.files) and
(not self.app.pargs.all)):
self.app.pargs.all = True

12
ee/cli/plugins/stack.py

@ -442,6 +442,7 @@ class EEStackController(CementBaseController):
config = configparser.ConfigParser()
config.read('/etc/php5/fpm/pool.d/debug.conf')
config['debug']['listen'] = '127.0.0.1:9001'
config['debug']['rlimit_core'] = 'unlimited'
with open('/etc/php5/fpm/pool.d/debug.conf',
encoding='utf-8', mode='w') as confifile:
Log.debug(self, "writting PHP5 configuration into "
@ -1122,8 +1123,9 @@ class EEStackController(CementBaseController):
(not self.app.pargs.postfix) and (not self.app.pargs.wpcli) and
(not self.app.pargs.phpmyadmin) and
(not self.app.pargs.adminer) and (not self.app.pargs.utils) and
(not self.app.pargs.mailscanner)):
(not self.app.pargs.mailscanner) and (not self.app.pargs.all)):
self.app.pargs.web = True
self.app.pargs.admin = True
if self.app.pargs.all:
self.app.pargs.web = True
@ -1244,7 +1246,7 @@ class EEStackController(CementBaseController):
else:
Log.error(self, "Failed to find installed Dovecot")
else:
Log.error(self, "Mail scanner allready installed")
Log.error(self, "Mail scanner already installed")
if self.app.pargs.utils:
Log.debug(self, "Setting packages variable for utils")
@ -1329,8 +1331,9 @@ class EEStackController(CementBaseController):
(not self.app.pargs.postfix) and (not self.app.pargs.wpcli) and
(not self.app.pargs.phpmyadmin) and
(not self.app.pargs.adminer) and (not self.app.pargs.utils) and
(not self.app.pargs.mailscanner)):
(not self.app.pargs.mailscanner) and (not self.app.pargs.all)):
self.app.pargs.web = True
self.app.pargs.admin = True
if self.app.pargs.all:
self.app.pargs.web = True
@ -1423,8 +1426,9 @@ class EEStackController(CementBaseController):
(not self.app.pargs.postfix) and (not self.app.pargs.wpcli) and
(not self.app.pargs.phpmyadmin) and
(not self.app.pargs.adminer) and (not self.app.pargs.utils) and
(not self.app.pargs.mailscanner)):
(not self.app.pargs.mailscanner) and (not self.app.pargs.all)):
self.app.pargs.web = True
self.app.pargs.admin = True
if self.app.pargs.all:
self.app.pargs.web = True

75
ee/cli/plugins/stack_services.py

@ -2,6 +2,7 @@ from cement.core.controller import CementBaseController, expose
from cement.core import handler, hook
from ee.core.services import EEService
from ee.core.logging import Log
from ee.core.variables import EEVariables
class EEStackStatusController(CementBaseController):
@ -28,8 +29,12 @@ class EEStackStatusController(CementBaseController):
Log.debug(self, "php5-fpm service start")
services = services + ['php5-fpm']
if self.app.pargs.mysql:
Log.debug(self, "mysql service start")
services = services + ['mysql']
if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service start")
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found,"
"unable to start MySQL service")
if self.app.pargs.postfix:
Log.debug(self, "postfix service start")
services = services + ['postfix']
@ -39,9 +44,13 @@ class EEStackStatusController(CementBaseController):
if self.app.pargs.dovecot:
Log.debug(self, "dovecot service start")
services = services + ['dovecot']
if not services:
Log.debug(self, "nginx,php5-fpm,mysql,postfix services start")
if not services and EEVariables.ee_mysql_host is "localhost":
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
Log.debug(self, "nginx,php5-fpm,mysql,postfix services start")
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix']
Log.debug(self, "nginx,php5-fpm,postfix services start")
for service in services:
EEService.start_service(self, service)
@ -56,8 +65,12 @@ class EEStackStatusController(CementBaseController):
Log.debug(self, "php5-fpm service stop")
services = services + ['php5-fpm']
if self.app.pargs.mysql:
Log.debug(self, "mysql service stop")
services = services + ['mysql']
if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service stop")
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found, "
"unable to stop MySQL service")
if self.app.pargs.postfix:
Log.debug(self, "postfix service stop")
services = services + ['postfix']
@ -67,9 +80,12 @@ class EEStackStatusController(CementBaseController):
if self.app.pargs.dovecot:
Log.debug(self, "dovecot service stop")
services = services + ['dovecot']
if not services:
if not services and EEVariables.ee_mysql_host is "localhost":
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
Log.debug(self, "nginx,php5-fpm,mysql,postfix services stop")
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix']
Log.debug(self, "nginx,php5-fpm,postfix services stop")
for service in services:
EEService.stop_service(self, service)
@ -84,8 +100,12 @@ class EEStackStatusController(CementBaseController):
Log.debug(self, "php5-fpm service restart")
services = services + ['php5-fpm']
if self.app.pargs.mysql:
Log.debug(self, "mysql service restart")
services = services + ['mysql']
if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service restart")
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found, "
"unable to restart MySQL service")
if self.app.pargs.postfix:
Log.debug(self, "postfix service restart")
services = services + ['postfix']
@ -95,10 +115,13 @@ class EEStackStatusController(CementBaseController):
if self.app.pargs.dovecot:
Log.debug(self, "dovecot service restart")
services = services + ['dovecot']
if not services:
if not services and EEVariables.ee_mysql_host is "localhost":
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
for service in services:
Log.debug(self, "nginx,php5-fpm,mysql,postfix services restart")
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix']
Log.debug(self, "nginx,php5-fpm,postfix services restart")
for service in services:
EEService.restart_service(self, service)
@expose(help="Get stack status")
@ -112,8 +135,12 @@ class EEStackStatusController(CementBaseController):
Log.debug(self, "php5-fpm service status")
services = services + ['php5-fpm']
if self.app.pargs.mysql:
Log.debug(self, "mysql service status")
services = services + ['mysql']
if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service status")
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found, "
"unable to get MySQL service status")
if self.app.pargs.postfix:
services = services + ['postfix']
Log.debug(self, "postfix service status")
@ -123,9 +150,12 @@ class EEStackStatusController(CementBaseController):
if self.app.pargs.dovecot:
Log.debug(self, "dovecot service status")
services = services + ['dovecot']
if not services:
Log.debug(self, "nginx,php5-fpm,mysql,postfix services status")
if not services and EEVariables.ee_mysql_host is "localhost":
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
Log.debug(self, "nginx,php5-fpm,mysql,postfix services status")
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix']
Log.debug(self, "nginx,php5-fpm,postfix services status")
for service in services:
if EEService.get_service_status(self, service):
Log.info(self, "{0:10}: {1}".format(service, "Running"))
@ -141,8 +171,12 @@ class EEStackStatusController(CementBaseController):
Log.debug(self, "php5-fpm service reload")
services = services + ['php5-fpm']
if self.app.pargs.mysql:
Log.debug(self, "mysql service reload")
services = services + ['mysql']
if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service reload")
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found, "
"unable to remote MySQL service")
if self.app.pargs.postfix:
Log.debug(self, "postfix service reload")
services = services + ['postfix']
@ -152,8 +186,11 @@ class EEStackStatusController(CementBaseController):
if self.app.pargs.dovecot:
Log.debug(self, "dovecot service reload")
services = services + ['dovecot']
if not services:
if not services and EEVariables.ee_mysql_host is "localhost":
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
for service in services:
Log.debug(self, "nginx,php5-fpm,mysql,postfix services reload")
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix']
Log.debug(self, "nginx,php5-fpm,postfix services reload")
for service in services:
EEService.reload_service(self, service)

4
install

@ -175,7 +175,7 @@ function update_to_ee3()
sed -i "s/X-Powered-By.*/X-Powered-By \"EasyEngine $new_ee_version\";/" /etc/nginx/nginx.conf &>> /dev/null
fi
grant_host=$(grep grant-host /etc/easyengine/ee.conf | awk '{ print $3 }')
grant_host=$(grep grant-host /etc/easyengine/ee.conf | awk '{ print $3 }' | head -1 )
db_name=$(grep db-name /etc/easyengine/ee.conf | awk '{ print $3 }')
db_user=$(grep db-name /etc/easyengine/ee.conf | awk '{ print $3 }')
wp_prefix=$(grep prefix /etc/easyengine/ee.conf | awk '{ print $3 }')
@ -318,7 +318,7 @@ else
service nginx reload &>> /dev/null
fi
else
ee_lib_echo_fail "You allready have EasyEngine $new_ee_version" | tee -ai $EE_INSTALL_LOG
ee_lib_echo_fail "You already have EasyEngine $new_ee_version" | tee -ai $EE_INSTALL_LOG
exit 1
fi
fi

Loading…
Cancel
Save