Browse Source

updated log messages

bugfixes
shital.rtcamp 10 years ago
parent
commit
850727aaee
  1. 191
      ee/cli/plugins/debug.py
  2. 46
      ee/cli/plugins/site.py
  3. 190
      ee/cli/plugins/site_functions.py
  4. 33
      ee/core/fileutils.py
  5. 7
      ee/core/mysql.py
  6. 13
      ee/core/services.py

191
ee/cli/plugins/debug.py

@ -3,6 +3,8 @@
from cement.core.controller import CementBaseController, expose from cement.core.controller import CementBaseController, expose
from cement.core import handler, hook from cement.core import handler, hook
from ee.core.shellexec import EEShellExec from ee.core.shellexec import EEShellExec
from ee.core.mysql import EEMysql
import os
def debug_plugin_hook(app): def debug_plugin_hook(app):
@ -35,12 +37,18 @@ class EEDebugController(CementBaseController):
dict(help='Debug Nginx rewrite rules', action='store_true')), dict(help='Debug Nginx rewrite rules', action='store_true')),
(['-i', '--interactive'], (['-i', '--interactive'],
dict(help='Interactive debug', action='store_true')), dict(help='Interactive debug', action='store_true')),
(['--import-slow-log-interval'],
dict(help='Import MySQL slow log to Anemometer',
action='store', dest='interval')),
(['site_name'],
dict(help='Website Name', nargs='?', default=None))
] ]
@expose(hide=True) @expose(hide=True)
def debug_nginx(self): def debug_nginx(self):
self.trigger_nginx = False self.trigger_nginx = False
if self.start: # start global debug
if self.start and not self.app.pargs.site_name:
try: try:
debug_address = (self.app.config.get('stack', 'ip-address') debug_address = (self.app.config.get('stack', 'ip-address')
.split()) .split())
@ -61,7 +69,8 @@ class EEDebugController(CementBaseController):
self.msg = self.msg + " /var/log/nginx/*.error.log" self.msg = self.msg + " /var/log/nginx/*.error.log"
else: # stop global debug
elif not self.start and not self.app.pargs.site_name:
if "debug_connection " in open('/etc/nginx/nginx.conf').read(): if "debug_connection " in open('/etc/nginx/nginx.conf').read():
print("Disabling Nginx debug connections") print("Disabling Nginx debug connections")
EEShellExec.cmd_exec(self, "sed -i \"/debug_connection.*/d\"" EEShellExec.cmd_exec(self, "sed -i \"/debug_connection.*/d\""
@ -70,8 +79,48 @@ class EEDebugController(CementBaseController):
else: else:
print("Nginx debug connection already disbaled") print("Nginx debug connection already disbaled")
# start site specific debug
elif self.start and self.app.pargs.site_name:
config_path = ("/etc/nginx/sites-available/{0}"
.format(self.app.pargs.site_name))
if os.path.isfile(config_path):
if not EEShellExec.cmd_exec("grep \"error.log debug\" {0}"
.format(config_path)):
print("Starting NGINX debug connection for {0}"
.format(self.app.pargs.site_name))
EEShellExec.cmd_exec("sed -i \"s/error.log;/error.log "
"debug;/\" {0}".format(config_path))
self.trigger_nginx = True
else:
print("Debug for site allready enabled")
else:
print("{0} domain not valid".format(self.app.pargs.site_name))
# stop site specific debug
elif not self.start and self.app.pargs.site_name:
config_path = ("/etc/nginx/sites-available/{0}"
.format(self.app.pargs.site_name))
if os.path.isfile(config_path):
if EEShellExec.cmd_exec("grep \"error.log debug\" {0}"
.format(config_path)):
print("Stoping NGINX debug connection for {0}"
.format(self.app.pargs.site_name))
EEShellExec.cmd_exec("sed -i \"s/error.log debug;/"
"error.log;/\" {0}"
.format(config_path))
self.trigger_nginx = True
else:
print("Debug for site allready disbaled")
else:
print("{0} domain not valid".format(self.app.pargs.site_name))
@expose(hide=True) @expose(hide=True)
def debug_php(self): def debug_php(self):
# PHP global debug start
if self.start: if self.start:
if not (EEShellExec.cmd_exec(self, "sed -n \"/upstream php" if not (EEShellExec.cmd_exec(self, "sed -n \"/upstream php"
"{/,/}/p \" /etc/nginx/" "{/,/}/p \" /etc/nginx/"
@ -84,9 +133,11 @@ class EEDebugController(CementBaseController):
ee_nginx = open('/etc/nginx/conf.d/upstream.conf', 'w') ee_nginx = open('/etc/nginx/conf.d/upstream.conf', 'w')
self.app.render((data), 'upstream.mustache', out=ee_nginx) self.app.render((data), 'upstream.mustache', out=ee_nginx)
ee_nginx.close() ee_nginx.close()
self.trigger_php = True
else: else:
print("PHP debug is allready enabled") print("PHP debug is allready enabled")
# PHP global debug stop
else: else:
if EEShellExec.cmd_exec(self, "sed -n \"/upstream php {/,/}/p\" " if EEShellExec.cmd_exec(self, "sed -n \"/upstream php {/,/}/p\" "
"/etc/nginx/conf.d/upstream.conf " "/etc/nginx/conf.d/upstream.conf "
@ -98,36 +149,148 @@ class EEDebugController(CementBaseController):
ee_nginx = open('/etc/nginx/conf.d/upstream.conf', 'w') ee_nginx = open('/etc/nginx/conf.d/upstream.conf', 'w')
self.app.render((data), 'upstream.mustache', out=ee_nginx) self.app.render((data), 'upstream.mustache', out=ee_nginx)
ee_nginx.close() ee_nginx.close()
self.trigger_php = True
else: else:
print("PHP debug is allready disbaled") print("PHP debug is allready disbaled")
@expose(hide=True) @expose(hide=True)
def debug_fpm(self): def debug_fpm(self):
# PHP5-FPM start global debug
if self.start: if self.start:
print("Start FPM debug") if not EEShellExec.cmd_exec(self, "grep \"log_level = debug\" "
"/etc/php5/fpm/php-fpm.conf"):
print("Setting up PHP5-FPM log_level = debug")
EEShellExec.cmd_exec(self, "sed -i \"s\';log_level.*\'log_"
"level = debug\'\" /etc/php5/fpm"
"/php-fpm.conf")
self.trigger_php = True
else:
print("PHP5-FPM log_level = debug already setup")
# PHP5-FPM stop global debug
else: else:
print("Stop FPM debug") if EEShellExec.cmd_exec(self, "grep \"log_level = debug\" "
"/etc/php5/fpm/php-fpm.conf"):
print("Disabling PHP5-FPM log_level = debug")
EEShellExec.cmd_exec(self, "sed -i \"s\'log_level.*\';log_"
"level = notice\'\" /etc/php5/fpm"
"/php-fpm.conf")
self.trigger_php = True
else:
print("PHP5-FPM log_level = debug already disabled")
@expose(hide=True) @expose(hide=True)
def debug_mysql(self): def debug_mysql(self):
# MySQL start global debug
if self.start: if self.start:
print("Start MySQL debug") if not EEShellExec.cmd_exec(self, "mysql -e \"show variables like"
" \'slow_query_log\';\" | "
"grep ON"):
print("Setting up MySQL slow log")
EEMysql.execute(self, "set global slow_query_log = "
"\'ON\';")
EEMysql.execute(self, "set global slow_query_log_file = "
"\'/var/log/mysql/mysql-slow.log\';")
EEMysql.execute(self, "set global long_query_time = 2;")
EEMysql.execute(self, "set global log_queries_not_using"
"_indexes = \'ON\';")
if self.app.pargs.interval:
try:
cron_time = int(self.app.pargs.interval)
except Exception as e:
cron_time = 5
EEShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l 2> "
"/dev/null | {{ cat; echo -e"
" \\\"#EasyEngine start MySQL slow"
" log \\n*/{0} * * * * "
"/usr/local/sbin/ee import-slow-log\\"
"n#EasyEngine end MySQL slow log\\\";"
" }} | crontab -\"".format(cron_time))
else:
print("MySQL slow log is allready enabled")
# MySQL stop global debug
else: else:
print("Stop MySQL debug") if EEShellExec.cmd_exec(self, "mysql -e \"show variables like \'"
"slow_query_log\';\" | grep ON"):
print("Disabling MySQL slow log")
EEMysql.execute(self, "set global slow_query_log = \'OFF\';")
EEMysql.execute(self, "set global slow_query_log_file = \'"
"/var/log/mysql/mysql-slow.log\';")
EEMysql.execute(self, "set global long_query_time = 10;")
EEMysql.execute(self, "set global log_queries_not_using_index"
"es = \'OFF\';")
EEShellExec.cmd_exec(self, "crontab -l | sed \'/#EasyEngine "
"start/,/#EasyEngine end/d\' | crontab -")
else:
print("MySQL slow log already disabled")
@expose(hide=True) @expose(hide=True)
def debug_wp(self): def debug_wp(self):
if self.start: if self.start and self.app.pargs.site_name:
print("Start WP debug") wp_config = ("/var/www/{0}/wp-config.php"
.format(self.app.pargs.site_name))
webroot = "/var/www/{0}".format(self.app.pargs.site_name)
if os.path.isfile(wp_config):
if not EEShellExec.cmd_exec(self, "grep \"\'WP_DEBUG\'\" {0} |"
" grep true".format(wp_config)):
print("Starting WordPress debug")
open("{0}/htdocs/wp-content/debug.log".format(webroot),
'a').close()
EEShellExec.cmd_exec(self, "chown www-data: {0}/htdocs/wp-"
"content/debug.log".format(webroot))
EEShellExec.cmd_exec(self, "sed -i \"s/define(\'WP_DEBUG\'"
".*/define(\'WP_DEBUG\', true);\\n"
"define(\'WP_DEBUG_DISPLAY\', false);"
"\\ndefine(\'WP_DEBUG_LOG\', true);"
"\\ndefine(\'SAVEQUERIES\', true);/\""
" {0}".format(wp_config))
EEShellExec.cmd_exec(self, "cd {0}/htdocs/ && wp"
" plugin --allow-root install "
"developer".format(webroot))
EEShellExec.cmd_exec(self, "chown -R www-data: {0}/htdocs/"
"wp-content/plugins"
.format(webroot))
else:
print("WordPress debug log already enabled")
else:
print("{0} domain not valid".format(self.app.pargs.site_name))
elif not self.start and self.app.pargs.site_name:
wp_config = ("/var/www/{0}/wp-config.php"
.format(self.app.pargs.site_name))
webroot = "/var/www/{0}".format(self.app.pargs.site_name)
if os.path.isfile(wp_config):
if EEShellExec.cmd_exec(self, "grep \"\'WP_DEBUG\'\" {0} | "
"grep true".format(wp_config)):
print("Disabling WordPress debug")
EEShellExec.cmd_exec(self, "sed -i \"s/define(\'WP_DEBUG\'"
", true);/define(\'WP_DEBUG\', "
"false);/\" {0}".format(wp_config))
EEShellExec.cmd_exec(self, "sed -i \"/define(\'"
"WP_DEBUG_DISPLAY\', false);/d\" {0}"
.format(wp_config))
EEShellExec.cmd_exec(self, "sed -i \"/define(\'"
"WP_DEBUG_LOG\', true);/d\" {0}"
.format(wp_config))
EEShellExec.cmd_exec("sed -i \"/define(\'"
"SAVEQUERIES\', "
"true);/d\" {0}".format(wp_config))
else:
print("WordPress debug all already disbaled")
else:
print("{0} domain not valid".format(self.app.pargs.site_name))
else: else:
print("Stop WP debug") print("Missing argument site_name")
@expose(hide=True) @expose(hide=True)
def debug_rewrite(self): def debug_rewrite(self):
if self.start: if self.start and not self.app.pargs.site_name:
print("Start WP-Rewrite debug") print("Start WP-Rewrite debug globally")
else: elif self.start and not self.app.pargs.site_name:
print("Stop WP-Rewrite debug") print("Stop WP-Rewrite debug globally")
elif self.start and self.app.pargs.site_name:
print("Start WP-Rewrite for site")
elif not self.start and not self.app.pargs.site_name:
print("Stop WP-Rewrite for site")
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):

46
ee/cli/plugins/site.py

@ -4,7 +4,7 @@ from cement.core import handler, hook
from ee.core.variables import EEVariables from ee.core.variables import EEVariables
from ee.core.domainvalidate import validate_domain from ee.core.domainvalidate import validate_domain
from ee.core.fileutils import EEFileUtils from ee.core.fileutils import EEFileUtils
from ee.cli.plugins.site_functions import setup_domain, setup_database from ee.cli.plugins.site_functions import *
import sys import sys
import os import os
@ -149,7 +149,8 @@ class EESiteCreateController(CementBaseController):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=True, wp=False, w3tc=False, static=False, basic=True, wp=False, w3tc=False,
wpfc=False, wpsc=False, multisite=False, wpfc=False, wpsc=False, multisite=False,
wpsubdir=False, webroot=ee_site_webroot) wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='')
if ((self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or if ((self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or
self.app.pargs.wpsc) and not (self.app.pargs.html or self.app.pargs.wpsc) and not (self.app.pargs.html or
@ -160,25 +161,29 @@ class EESiteCreateController(CementBaseController):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=True, wp=True, w3tc=False, static=False, basic=True, wp=True, w3tc=False,
wpfc=False, wpsc=False, multisite=False, wpfc=False, wpsc=False, multisite=False,
wpsubdir=False, webroot=ee_site_webroot) wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='')
if (self.app.pargs.w3tc and not if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)): (self.app.pargs.wpfc or self.app.pargs.wpsc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=True, static=False, basic=False, wp=True, w3tc=True,
wpfc=False, wpsc=False, multisite=False, wpfc=False, wpsc=False, multisite=False,
wpsubdir=False, webroot=ee_site_webroot) wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='')
if (self.app.pargs.wpfc and not if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)): (self.app.pargs.wpsc or self.app.pargs.w3tc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
wpfc=True, wpsc=False, multisite=False, wpfc=True, wpsc=False, multisite=False,
wpsubdir=False, webroot=ee_site_webroot) wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='')
if (self.app.pargs.wpsc and not if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)): (self.app.pargs.w3tc or self.app.pargs.wpfc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
wpfc=False, wpsc=True, multisite=False, wpfc=False, wpsc=True, multisite=False,
wpsubdir=False, webroot=ee_site_webroot) wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='')
if (self.app.pargs.wpsubdir and not (self.app.pargs.html or if (self.app.pargs.wpsubdir and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.mysql or self.app.pargs.php or self.app.pargs.mysql or
@ -188,25 +193,29 @@ class EESiteCreateController(CementBaseController):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=True, wp=True, w3tc=False, static=False, basic=True, wp=True, w3tc=False,
wpfc=False, wpsc=False, multisite=True, wpfc=False, wpsc=False, multisite=True,
wpsubdir=True, webroot=ee_site_webroot) wpsubdir=True, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='')
if (self.app.pargs.w3tc and not if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)): (self.app.pargs.wpfc or self.app.pargs.wpsc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=True, static=False, basic=False, wp=True, w3tc=True,
wpfc=False, wpsc=False, multisite=True, wpfc=False, wpsc=False, multisite=True,
wpsubdir=True, webroot=ee_site_webroot) wpsubdir=True, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='')
if (self.app.pargs.wpfc and not if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)): (self.app.pargs.wpsc or self.app.pargs.w3tc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
wpfc=True, wpsc=False, multisite=True, wpfc=True, wpsc=False, multisite=True,
wpsubdir=True, webroot=ee_site_webroot) wpsubdir=True, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='')
if (self.app.pargs.wpsc and not if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)): (self.app.pargs.w3tc or self.app.pargs.wpfc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
wpfc=False, wpsc=True, multisite=True, wpfc=False, wpsc=True, multisite=True,
wpsubdir=True, webroot=ee_site_webroot) wpsubdir=True, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='')
if (self.app.pargs.wpsubdomain and not (self.app.pargs.html or if (self.app.pargs.wpsubdomain and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.mysql or self.app.pargs.php or self.app.pargs.mysql or
@ -216,28 +225,35 @@ class EESiteCreateController(CementBaseController):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=True, wp=True, w3tc=False, static=False, basic=True, wp=True, w3tc=False,
wpfc=False, wpsc=False, multisite=True, wpfc=False, wpsc=False, multisite=True,
wpsubdir=False, webroot=ee_site_webroot) wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='')
if (self.app.pargs.w3tc and not if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)): (self.app.pargs.wpfc or self.app.pargs.wpsc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=True, static=False, basic=False, wp=True, w3tc=True,
wpfc=False, wpsc=False, multisite=True, wpfc=False, wpsc=False, multisite=True,
wpsubdir=False, webroot=ee_site_webroot) wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='')
if (self.app.pargs.wpfc and not if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)): (self.app.pargs.wpsc or self.app.pargs.w3tc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
wpfc=True, wpsc=False, multisite=True, wpfc=True, wpsc=False, multisite=True,
wpsubdir=False, webroot=ee_site_webroot) wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='')
if (self.app.pargs.wpsc and not if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)): (self.app.pargs.w3tc or self.app.pargs.wpfc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
wpfc=False, wpsc=True, multisite=True, wpfc=False, wpsc=True, multisite=True,
wpsubdir=False, webroot=ee_site_webroot) wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='')
setup_domain(self, data) setup_domain(self, data)
setup_database(self, data) if 'ee_db_name' in data.keys():
data = setup_database(self, data)
if data['wp']:
setup_wordpress(self, data)
class EESiteUpdateController(CementBaseController): class EESiteUpdateController(CementBaseController):

190
ee/cli/plugins/site_functions.py

@ -5,6 +5,7 @@ import sys
import getpass import getpass
from ee.core.fileutils import EEFileUtils from ee.core.fileutils import EEFileUtils
from ee.core.mysql import EEMysql from ee.core.mysql import EEMysql
from ee.core.shellexec import EEShellExec
def setup_domain(self, data): def setup_domain(self, data):
@ -62,7 +63,7 @@ def setup_database(self, data):
prompt_dbname = self.app.config.get('mysql', 'db-name') prompt_dbname = self.app.config.get('mysql', 'db-name')
prompt_dbuser = self.app.config.get('mysql', 'db-user') prompt_dbuser = self.app.config.get('mysql', 'db-user')
ee_mysql_host = self.app.config.get('mysql', 'grant-host') ee_mysql_host = self.app.config.get('mysql', 'grant-host')
print(ee_random) ee_db_name = ''
if prompt_dbname == 'True': if prompt_dbname == 'True':
try: try:
@ -72,8 +73,8 @@ def setup_database(self, data):
print("{0} {1}".format(e.errorno, e.strerror)) print("{0} {1}".format(e.errorno, e.strerror))
sys.exit(0) sys.exit(0)
if not ee_db_name: if not ee_db_name:
ee_db_name = ee_replace_dot ee_db_name = ee_replace_dot
if prompt_dbuser: if prompt_dbuser:
try: try:
@ -85,28 +86,161 @@ def setup_database(self, data):
print("{0} {1}".format(e.errorno, e.strerror)) print("{0} {1}".format(e.errorno, e.strerror))
sys.exit(1) sys.exit(1)
if not ee_db_username: if not ee_db_username:
ee_db_username = ee_replace_dot ee_db_username = ee_replace_dot
if not ee_db_password: if not ee_db_password:
ee_db_password = ee_random ee_db_password = ee_random
if len(ee_db_name) > 16: if len(ee_db_username) > 16:
print('Autofix MySQL username (ERROR 1470 (HY000)), please wait...' print('Autofix MySQL username (ERROR 1470 (HY000)), please wait...')
) ee_random10 = (''.join(random.sample(string.ascii_uppercase +
ee_random10 = (''.join(random.sample(string.ascii_uppercase + string.ascii_lowercase + string.digits, 10)))
string.ascii_lowercase + string.digits, 10))) ee_db_name = (ee_db_name[0:6] + ee_random10)
ee_db_name = (ee_db_name[0:6] + ee_random10)
# create MySQL database
# create MySQL database EEMysql.execute(self, "create database \'{0}\'"
EEMysql.execute(self, "create database \'{0}\'" .format(ee_db_name))
.format(ee_db_name))
# Create MySQL User
# Create MySQL User EEMysql.execute(self,
EEMysql.execute(self, "create user \'{0}\'@\'{1}\' identified by \'{2}\'"
"create user \'{0}\'@\'{1}\' identified by \'{2}\'" .format(ee_db_username, ee_mysql_host, ee_db_password))
.format(ee_db_username, ee_mysql_host, ee_db_password))
# Grant permission
# Grant permission EEMysql.execute(self,
EEMysql.execute(self, "grant all privileges on \'{0}\'.* to \'{1}\'@\'{2}\'"
"grant all privileges on \'{0}\'.* to \'{1}\'@\'{2}\'" .format(ee_db_name, ee_db_username, ee_db_password))
.format(ee_db_name, ee_db_username, ee_db_password)) data['ee_db_name'] = ee_db_name
data['ee_db_user'] = ee_db_username
data['ee_db_pass'] = ee_db_password
return data
def setup_wordpress(self, data):
ee_domain_name = data['site_name']
ee_site_webroot = data['webroot']
prompt_wpprefix = self.app.config.get('wordpress', 'prefix')
ee_wp_user = self.app.config.get('wordpress', 'user')
ee_wp_pass = self.app.config.get('wordpress', 'password')
ee_wp_email = self.app.config.get('wordpress', 'email')
# Random characters
ee_random = (''.join(random.sample(string.ascii_uppercase +
string.ascii_lowercase + string.digits, 15)))
print("Downloading Wordpress, please wait...")
EEShellExec.cmd_exec(self, "wp --allow-root core download"
"--path={0}/htdocs/".format(ee_site_webroot))
setup_database(self, data)
if prompt_wpprefix == 'True':
ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: '
.format(ee_replace_dot))
while re.match('^[A-Za-z0-9_]*$', ee_wp_prefix):
print("Warning: table prefix can only contain numbers, letters,"
"and underscores")
ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: ')
if not ee_wp_prefix:
ee_wp_prefix = 'wp_'
# Modify wp-config.php & move outside the webroot
'''EEFileUtils.copyfile(self,
'{0}/htdocs/wp-config-sample.php'
.format(ee_site_webroot),
'{0}/wp-config.php'.format(ee_site_webroot))
EEFileUtils.searchreplace('{0}/wp-config.php'.format(ee_site_webroot),
'database_name_here', '')
EEFileUtils.searchreplace('{0}/wp-config.php'.format(ee_site_webroot),
'database_name_here', '')
EEFileUtils.searchreplace('{0}/wp-config.php'.format(ee_site_webroot),
'username_here', '')
EEFileUtils.searchreplace('{0}/wp-config.php'.format(ee_site_webroot),
'password_here', '')
EEFileUtils.searchreplace('{0}/wp-config.php'.format(ee_site_webroot),
'localhost', '')
EEFileUtils.searchreplace('{0}/wp-config.php'.format(ee_site_webroot),
'wp_', '')'''
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
if not data['multisite']:
EEShellExec.cmd_exec(self, "wp --allow-root core config"
"--dbname={0} --dbprefix={1} --dbuser={2}"
.format(ee_db_name, ee_wp_prefix, ee_db_user)
+ "--dbpass={0}".format(ee_db_password))
else:
EEShellExec.cmd_exec(self, "wp --allow-root core config"
"--dbname={0} --dbprefix={1}"
.format(ee_db_name, ee_wp_prefix)
+ "--dbuser={0} --dbpass={1} --extra-php<<PHP"
+ "define('WP_ALLOW_MULTISITE', true);"
+ "define('WPMU_ACCEL_REDIRECT', true);"
+ "PHP"
.format(ee_db_user, ee_db_password))
EEFileUtils.mvfile('./wp-config.php', '../')
# TODO code for salts here
if not ee_wp_user:
ee_wp_user = EEVariables.ee_user
while not ee_wp_user:
print("Warning: Usernames can have only alphanumeric"
"characters, spaces, underscores, hyphens,"
"periods and the @ symbol.")
ee_wp_user = input('Enter WordPress username: ')
if not ee_wp_pass:
ee_wp_pass = ee_random
if not ee_wp_email:
ee_wp_email = EEVariables.ee_email
while not ee_wp_email:
ee_wp_email = input('Enter WordPress email: ')
print("Setting up WordPress, please wait...")
if not data['multisite']:
EEShellExec.cmd_exec(self, "wp --allow-root core install"
"--url=www.{0} --title=www.{0} --admin_name={1}"
.format(ee_domain_name, ee_wp_user)
+ "--admin_password={0} --admin_email={1}"
.format(ee_wp_pass, ee_wp_email))
else:
EEShellExec.cmd_exec(self, "wp --allow-root core multisite-install"
"--url=www.{0} --title=www.{0} --admin_name={1}"
.format(ee_domain_name, ee_wp_user)
+ "--admin_password={0} --admin_email={1} "
"{subdomains}"
.format(ee_wp_pass, ee_wp_email,
subdomains='--subdomains'
if not data['wpsubdir'] else ''))
print("Updating WordPress permalink, please wait...")
EEShellExec.cmd_exec("wp rewrite structure --allow-root"
"/%year%/%monthnum%/%day%/%postname%/")
"""Install nginx-helper plugin """
install_wp_plugin(self, 'nginx-helper', data)
"""Install Wp Super Cache"""
if data['wpsc']:
install_wp_plugin(self, 'wp-super-cache', data)
"""Install W3 Total Cache"""
if data['w3tc'] or data['wpfc']:
install_wp_plugin(self, 'w3-total-cache', data)
def setup_wordpress_network(self, ee_www_domain, ee_site_webroot,
subdomain=False):
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert'
'--title={0}')
def install_wp_plugin(self, plugin_name, data):
ee_site_webroot = ee_site_webroot = data['webroot']
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, "wp plugin --allow-root install {0}"
.format(plugin_name))
EEShellExec.cmd_exec(self, "wp plugin --allow-root activate {0} {na}"
.format(na='--network' if data['multisite'] else ''))

33
ee/core/fileutils.py

@ -3,6 +3,8 @@ import shutil
import os import os
import sys import sys
import glob import glob
import shutil
import fileinput
class EEFileUtils(): class EEFileUtils():
@ -46,3 +48,34 @@ class EEFileUtils():
self.app.log.error("Unable to reomove symbolic link ...\n {0} {1}" self.app.log.error("Unable to reomove symbolic link ...\n {0} {1}"
.format(e.errno, e.strerror)) .format(e.errno, e.strerror))
sys.exit(1) sys.exit(1)
def copyfile(self, src, dst):
try:
shutil.copy2(src, dest)
except shutil.Error as e:
print('Error: {0}'.format(e))
except IOError as e:
print('Error: {e}'.format(e.strerror))
def searchreplace(self, fnm, sstr, rstr):
try:
for line in fileinput.input(fnm, inplace=True):
print(line.replace(textToSearch, textToReplace), end='')
except Exception as e:
print('Error : {0}'.format(e))
def mvfile(self, src, dst):
try:
shutil.move(src, dst)
except shutil.Error as e:
self.app.log.error('Unable to move file {err}'
.format(err=str(e.reason)))
sys.exit(1)
def chdir(self, path):
try:
os.chdir(path)
except OSError as e:
self.app.log.error('Unable to Change Directory {err}'
.format(err=e.strerror))
sys.exit(1)

7
ee/core/mysql.py

@ -28,14 +28,15 @@ class EEMysql():
user=user, passwd=passwd) user=user, passwd=passwd)
cur = conn.cursor() cur = conn.cursor()
except Exception as e: except Exception as e:
self.app.log.error('Unable to connect to database\{0} {1}' self.app.log.error('Unable to connect to database: {0}'
.format(e.errno, e.strerror)) .format(e.strerror))
return False return False
try: try:
cur.execute(statement) cur.execute(statement)
except Exception as e: except Exception as e:
self.app.log.error('Error occured while executing', e.reason()) self.app.log.error('Error occured while executing: {0}'
.format(e.strerror))
self.app.log.info("Error occured while executing "+statement) self.app.log.info("Error occured while executing "+statement)
cur.close() cur.close()
conn.close() conn.close()

13
ee/core/services.py

@ -46,6 +46,19 @@ class EEService():
self.app.log.error("Unable to restart services \{0} {1}" self.app.log.error("Unable to restart services \{0} {1}"
.format(e.errno, e.strerror)) .format(e.errno, e.strerror))
def reload_service(self, service_name):
try:
retcode = subprocess.getstatusoutput('service {0} reload'
.format(service_name))
if retcode[0] == 0:
self.app.log.info("reload : {0}".format(service_name))
return True
else:
return False
except OSError as e:
self.app.log.error("Execution failed:", e)
return False
def get_service_status(self, service_name): def get_service_status(self, service_name):
try: try:
is_exist = subprocess.getstatusoutput('which {0}' is_exist = subprocess.getstatusoutput('which {0}'

Loading…
Cancel
Save