Browse Source

ee site commands done

bugfixes
harshadyeola 10 years ago
parent
commit
487424d37d
  1. 18
      ee/cli/plugins/clean.py
  2. 93
      ee/cli/plugins/debug.py
  3. 11
      ee/cli/plugins/secure.py
  4. 271
      ee/cli/plugins/stack.py
  5. 59
      ee/cli/plugins/stack_services.py
  6. 1
      ee/core/aptget.py
  7. 11
      ee/core/download.py
  8. 3
      ee/core/extract.py
  9. 20
      ee/core/fileutils.py
  10. 11
      ee/core/git.py
  11. 5
      ee/core/mysql.py
  12. 22
      ee/core/services.py
  13. 4
      ee/core/shellexec.py

18
ee/cli/plugins/clean.py

@ -5,6 +5,7 @@ from cement.core.controller import CementBaseController, expose
from cement.core import handler, hook from cement.core import handler, hook
import os import os
import urllib.request import urllib.request
from ee.core.logging import Log
def clean_plugin_hook(app): def clean_plugin_hook(app):
@ -49,30 +50,31 @@ class EECleanController(CementBaseController):
@expose(hide=True) @expose(hide=True)
def clean_memcache(self): def clean_memcache(self):
try:
if(EEAptGet.is_installed("memcached")): if(EEAptGet.is_installed("memcached")):
self.app.log.info("memcache is installed")
EEService.restart_service(self, "memcached") EEService.restart_service(self, "memcached")
self.app.log.info("Cleaning memcache..") Log.info(self, "Cleaning memcache..")
else: else:
self.app.log.info("memcache is not installed") Log.error(self, "Memcache not installed")
except:
Log.error(self, "Unable to restart memcached")
@expose(hide=True) @expose(hide=True)
def clean_fastcgi(self): def clean_fastcgi(self):
if(os.path.isdir("/var/run/nginx-cache")): if(os.path.isdir("/var/run/nginx-cache")):
self.app.log.info("Cleaning fastcgi...") Log.info(self, "Cleaning NGINX FastCGI cache, please wait...")
EEShellExec.cmd_exec(self, "rm -rf /var/run/nginx-cache/*") EEShellExec.cmd_exec(self, "rm -rf /var/run/nginx-cache/*")
else: else:
self.app.log.info("Error occur while Cleaning fastcgi..") Log.error(self, "Unable to clean FastCGI cache")
@expose(hide=True) @expose(hide=True)
def clean_opcache(self): def clean_opcache(self):
try: try:
self.app.log.info("Cleaning opcache.... ") Log.info(self, "Cleaning opcache.... ")
wp = urllib.request.urlopen(" https://127.0.0.1:22222/cache" wp = urllib.request.urlopen(" https://127.0.0.1:22222/cache"
"/opcache/opgui.php?page=reset").read() "/opcache/opgui.php?page=reset").read()
except Exception as e: except Exception as e:
self.app.log.info("Unable to clean opacache\n {0}{1}" Log.error(self, "Unable to clean opacache {0}".format(e))
.format(e.errno, e.strerror))
def load(app): def load(app):

93
ee/cli/plugins/debug.py

@ -6,6 +6,7 @@ from ee.core.shellexec import EEShellExec
from ee.core.mysql import EEMysql from ee.core.mysql import EEMysql
from ee.core.services import EEService from ee.core.services import EEService
import os import os
from ee.core.logging import Log
def debug_plugin_hook(app): def debug_plugin_hook(app):
@ -57,7 +58,7 @@ class EEDebugController(CementBaseController):
for ip_addr in debug_address: for ip_addr in debug_address:
if not ("debug_connection "+ip_addr in open('/etc/nginx/' if not ("debug_connection "+ip_addr in open('/etc/nginx/'
'nginx.conf').read()): 'nginx.conf').read()):
self.app.log.info("Setting up NGINX debug connection" Log.info(self, "Setting up NGINX debug connection"
" for "+ip_addr) " for "+ip_addr)
EEShellExec.cmd_exec(self, "sed -i \"/events {{/a\\ \\ \\ " EEShellExec.cmd_exec(self, "sed -i \"/events {{/a\\ \\ \\ "
"\\ $(echo debug_connection " "\\ $(echo debug_connection "
@ -66,19 +67,19 @@ class EEDebugController(CementBaseController):
self.trigger_nginx = True self.trigger_nginx = True
if not self.trigger_nginx: if not self.trigger_nginx:
self.app.log.info("NGINX debug connection already enabled") Log.info(self, "NGINX debug connection already enabled")
self.msg = self.msg + [" /var/log/nginx/*.error.log"] self.msg = self.msg + [" /var/log/nginx/*.error.log"]
# stop global debug # stop global debug
elif not self.start and not self.app.pargs.site_name: 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():
self.app.log.info("Disabling Nginx debug connections") Log.info(self, "Disabling Nginx debug connections")
EEShellExec.cmd_exec(self, "sed -i \"/debug_connection.*/d\"" EEShellExec.cmd_exec(self, "sed -i \"/debug_connection.*/d\""
" /etc/nginx/nginx.conf") " /etc/nginx/nginx.conf")
self.trigger_nginx = True self.trigger_nginx = True
else: else:
self.app.log.info("Nginx debug connection already disbaled") Log.info(self, "Nginx debug connection already disbaled")
# start site specific debug # start site specific debug
elif self.start and self.app.pargs.site_name: elif self.start and self.app.pargs.site_name:
@ -87,21 +88,20 @@ class EEDebugController(CementBaseController):
if os.path.isfile(config_path): if os.path.isfile(config_path):
if not EEShellExec.cmd_exec("grep \"error.log debug\" {0}" if not EEShellExec.cmd_exec("grep \"error.log debug\" {0}"
.format(config_path)): .format(config_path)):
self.app.log.info("Starting NGINX debug connection for " Log.info(self, "Starting NGINX debug connection for "
"{0}" "{0}".format(self.app.pargs.site_name))
.format(self.app.pargs.site_name))
EEShellExec.cmd_exec("sed -i \"s/error.log;/error.log " EEShellExec.cmd_exec("sed -i \"s/error.log;/error.log "
"debug;/\" {0}".format(config_path)) "debug;/\" {0}".format(config_path))
self.trigger_nginx = True self.trigger_nginx = True
else: else:
self.app.log.info("Debug for site allready enabled") Log.info(self, "Debug for site allready enabled")
self.msg = self.msg + ['/var/www//logs/error.log' self.msg = self.msg + ['/var/www//logs/error.log'
.format(self.app.pargs.site_name)] .format(self.app.pargs.site_name)]
else: else:
self.app.log.info("{0} domain not valid" Log.info(self, "{0} domain not valid"
.format(self.app.pargs.site_name)) .format(self.app.pargs.site_name))
# stop site specific debug # stop site specific debug
@ -111,7 +111,7 @@ class EEDebugController(CementBaseController):
if os.path.isfile(config_path): if os.path.isfile(config_path):
if EEShellExec.cmd_exec("grep \"error.log debug\" {0}" if EEShellExec.cmd_exec("grep \"error.log debug\" {0}"
.format(config_path)): .format(config_path)):
self.app.log.info("Stoping NGINX debug connection for {0}" Log.info(self, "Stoping NGINX debug connection for {0}"
.format(self.app.pargs.site_name)) .format(self.app.pargs.site_name))
EEShellExec.cmd_exec("sed -i \"s/error.log debug;/" EEShellExec.cmd_exec("sed -i \"s/error.log debug;/"
"error.log;/\" {0}" "error.log;/\" {0}"
@ -119,10 +119,10 @@ class EEDebugController(CementBaseController):
self.trigger_nginx = True self.trigger_nginx = True
else: else:
self.app.log.info("Debug for site allready disbaled")
Log.info(self, "Debug for site allready disbaled")
else: else:
self.app.log.info("{0} domain not valid" Log.info(self, "{0} domain not valid"
.format(self.app.pargs.site_name)) .format(self.app.pargs.site_name))
@expose(hide=True) @expose(hide=True)
@ -133,16 +133,16 @@ class EEDebugController(CementBaseController):
"{/,/}/p \" /etc/nginx/" "{/,/}/p \" /etc/nginx/"
"conf.d/upstream.conf " "conf.d/upstream.conf "
"| grep 9001")): "| grep 9001")):
self.app.log.info("Enabling PHP debug") Log.info(self, "Enabling PHP debug")
data = dict(php="9001", debug="9001") data = dict(php="9001", debug="9001")
self.app.log.info('writting the nginx configration to file' Log.info(self, 'writting the nginx configration to file'
'/etc/nginx/conf.d/upstream.conf ') '/etc/nginx/conf.d/upstream.conf ')
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 self.trigger_php = True
else: else:
self.app.log.info("PHP debug is allready enabled") Log.info(self, "PHP debug is allready enabled")
self.msg = self.msg + ['/var/log/php5/slow.log'] self.msg = self.msg + ['/var/log/php5/slow.log']
@ -151,16 +151,16 @@ class EEDebugController(CementBaseController):
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 "
"| grep 9001"): "| grep 9001"):
self.app.log.info("Disabling PHP debug") Log.info(self, "Disabling PHP debug")
data = dict(php="9000", debug="9001") data = dict(php="9000", debug="9001")
self.app.log.info('writting the nginx configration to file' Log.info(self, 'writting the nginx configration to file'
'/etc/nginx/conf.d/upstream.conf ') '/etc/nginx/conf.d/upstream.conf ')
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 self.trigger_php = True
else: else:
self.app.log.info("PHP debug is allready disbaled") Log.info(self, "PHP debug is allready disbaled")
@expose(hide=True) @expose(hide=True)
def debug_fpm(self): def debug_fpm(self):
@ -168,26 +168,26 @@ class EEDebugController(CementBaseController):
if self.start: if self.start:
if not EEShellExec.cmd_exec(self, "grep \"log_level = debug\" " if not EEShellExec.cmd_exec(self, "grep \"log_level = debug\" "
"/etc/php5/fpm/php-fpm.conf"): "/etc/php5/fpm/php-fpm.conf"):
self.app.log.info("Setting up PHP5-FPM log_level = debug") Log.info(self, "Setting up PHP5-FPM log_level = debug")
EEShellExec.cmd_exec(self, "sed -i \"s\';log_level.*\'log_" EEShellExec.cmd_exec(self, "sed -i \"s\';log_level.*\'log_"
"level = debug\'\" /etc/php5/fpm" "level = debug\'\" /etc/php5/fpm"
"/php-fpm.conf") "/php-fpm.conf")
self.trigger_php = True self.trigger_php = True
else: else:
self.app.log.info("PHP5-FPM log_level = debug already setup") Log.info(self, "PHP5-FPM log_level = debug already setup")
self.msg = self.msg + ['/var/log/php5/fpm.log'] self.msg = self.msg + ['/var/log/php5/fpm.log']
# PHP5-FPM stop global debug # PHP5-FPM stop global debug
else: else:
if EEShellExec.cmd_exec(self, "grep \"log_level = debug\" " if EEShellExec.cmd_exec(self, "grep \"log_level = debug\" "
"/etc/php5/fpm/php-fpm.conf"): "/etc/php5/fpm/php-fpm.conf"):
self.app.log.info("Disabling PHP5-FPM log_level = debug") Log.info(self, "Disabling PHP5-FPM log_level = debug")
EEShellExec.cmd_exec(self, "sed -i \"s\'log_level.*\';log_" EEShellExec.cmd_exec(self, "sed -i \"s\'log_level.*\';log_"
"level = notice\'\" /etc/php5/fpm" "level = notice\'\" /etc/php5/fpm"
"/php-fpm.conf") "/php-fpm.conf")
self.trigger_php = True self.trigger_php = True
else: else:
self.app.log.info("PHP5-FPM log_level = debug " Log.info(self, "PHP5-FPM log_level = debug "
" already disabled") " already disabled")
@expose(hide=True) @expose(hide=True)
@ -197,7 +197,7 @@ class EEDebugController(CementBaseController):
if not EEShellExec.cmd_exec(self, "mysql -e \"show variables like" if not EEShellExec.cmd_exec(self, "mysql -e \"show variables like"
" \'slow_query_log\';\" | " " \'slow_query_log\';\" | "
"grep ON"): "grep ON"):
print("Setting up MySQL slow log") Log.info(self, "Setting up MySQL slow log")
EEMysql.execute(self, "set global slow_query_log = " EEMysql.execute(self, "set global slow_query_log = "
"\'ON\';") "\'ON\';")
EEMysql.execute(self, "set global slow_query_log_file = " EEMysql.execute(self, "set global slow_query_log_file = "
@ -218,7 +218,7 @@ class EEDebugController(CementBaseController):
"n#EasyEngine end MySQL slow log\\\";" "n#EasyEngine end MySQL slow log\\\";"
" }} | crontab -\"".format(cron_time)) " }} | crontab -\"".format(cron_time))
else: else:
self.app.log.info("MySQL slow log is allready enabled") Log.info(self, "MySQL slow log is allready enabled")
self.msg = self.msg + ['/var/log/mysql/mysql-slow.log'] self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
@ -226,7 +226,7 @@ class EEDebugController(CementBaseController):
else: else:
if EEShellExec.cmd_exec(self, "mysql -e \"show variables like \'" if EEShellExec.cmd_exec(self, "mysql -e \"show variables like \'"
"slow_query_log\';\" | grep ON"): "slow_query_log\';\" | grep ON"):
print("Disabling MySQL slow log") Log.info(self, "Disabling MySQL slow log")
EEMysql.execute(self, "set global slow_query_log = \'OFF\';") EEMysql.execute(self, "set global slow_query_log = \'OFF\';")
EEMysql.execute(self, "set global slow_query_log_file = \'" EEMysql.execute(self, "set global slow_query_log_file = \'"
"/var/log/mysql/mysql-slow.log\';") "/var/log/mysql/mysql-slow.log\';")
@ -236,7 +236,7 @@ class EEDebugController(CementBaseController):
EEShellExec.cmd_exec(self, "crontab -l | sed \'/#EasyEngine " EEShellExec.cmd_exec(self, "crontab -l | sed \'/#EasyEngine "
"start/,/#EasyEngine end/d\' | crontab -") "start/,/#EasyEngine end/d\' | crontab -")
else: else:
self.app.log.info("MySQL slow log already disabled") Log.info(self, "MySQL slow log already disabled")
@expose(hide=True) @expose(hide=True)
def debug_wp(self): def debug_wp(self):
@ -247,7 +247,7 @@ class EEDebugController(CementBaseController):
if os.path.isfile(wp_config): if os.path.isfile(wp_config):
if not EEShellExec.cmd_exec(self, "grep \"\'WP_DEBUG\'\" {0} |" if not EEShellExec.cmd_exec(self, "grep \"\'WP_DEBUG\'\" {0} |"
" grep true".format(wp_config)): " grep true".format(wp_config)):
self.app.log.info("Starting WordPress debug") Log.info(self, "Starting WordPress debug")
open("{0}/htdocs/wp-content/debug.log".format(webroot), open("{0}/htdocs/wp-content/debug.log".format(webroot),
'a').close() 'a').close()
EEShellExec.cmd_exec(self, "chown www-data: {0}/htdocs/wp-" EEShellExec.cmd_exec(self, "chown www-data: {0}/htdocs/wp-"
@ -265,9 +265,9 @@ class EEDebugController(CementBaseController):
"wp-content/plugins" "wp-content/plugins"
.format(webroot)) .format(webroot))
else: else:
self.app.log.info("WordPress debug log already enabled") Log.info(self, "WordPress debug log already enabled")
else: else:
self.app.log.info("{0} domain not valid" Log.info(self, "{0} domain not valid"
.format(self.app.pargs.site_name)) .format(self.app.pargs.site_name))
elif not self.start and self.app.pargs.site_name: elif not self.start and self.app.pargs.site_name:
@ -277,7 +277,7 @@ class EEDebugController(CementBaseController):
if os.path.isfile(wp_config): if os.path.isfile(wp_config):
if EEShellExec.cmd_exec(self, "grep \"\'WP_DEBUG\'\" {0} | " if EEShellExec.cmd_exec(self, "grep \"\'WP_DEBUG\'\" {0} | "
"grep true".format(wp_config)): "grep true".format(wp_config)):
self.app.log.info("Disabling WordPress debug") Log.info(self, "Disabling WordPress debug")
EEShellExec.cmd_exec(self, "sed -i \"s/define(\'WP_DEBUG\'" EEShellExec.cmd_exec(self, "sed -i \"s/define(\'WP_DEBUG\'"
", true);/define(\'WP_DEBUG\', " ", true);/define(\'WP_DEBUG\', "
"false);/\" {0}".format(wp_config)) "false);/\" {0}".format(wp_config))
@ -291,12 +291,12 @@ class EEDebugController(CementBaseController):
"SAVEQUERIES\', " "SAVEQUERIES\', "
"true);/d\" {0}".format(wp_config)) "true);/d\" {0}".format(wp_config))
else: else:
print("WordPress debug all already disbaled") Log.info(self, "WordPress debug all already disbaled")
else: else:
self.app.log.info("{0} domain not valid" Log.info(self, "{0} domain not valid"
.format(self.app.pargs.site_name)) .format(self.app.pargs.site_name))
else: else:
self.app.log.info("Missing argument site_name") Log.info(self, "Missing argument site_name")
@expose(hide=True) @expose(hide=True)
def debug_rewrite(self): def debug_rewrite(self):
@ -304,12 +304,12 @@ class EEDebugController(CementBaseController):
if self.start and not self.app.pargs.site_name: if self.start and not self.app.pargs.site_name:
if not EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" " if not EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" "
"/etc/nginx/nginx.conf"): "/etc/nginx/nginx.conf"):
self.app.log.info("Setting up Nginx rewrite logs") Log.info(self, "Setting up Nginx rewrite logs")
EEShellExec.cmd_exec(self, "sed -i \'/http {/a \\\\t" EEShellExec.cmd_exec(self, "sed -i \'/http {/a \\\\t"
"rewrite_log on;\' /etc/nginx/nginx.conf") "rewrite_log on;\' /etc/nginx/nginx.conf")
self.trigger_nginx = True self.trigger_nginx = True
else: else:
self.app.log.info("NGINX rewrite logs already enabled") Log.info(self, "NGINX rewrite logs already enabled")
if '/var/log/nginx/*.error.log' not in self.msg: if '/var/log/nginx/*.error.log' not in self.msg:
self.msg = self.msg + ['/var/log/nginx/*.error.log'] self.msg = self.msg + ['/var/log/nginx/*.error.log']
@ -318,26 +318,26 @@ class EEDebugController(CementBaseController):
elif not self.start and not self.app.pargs.site_name: elif not self.start and not self.app.pargs.site_name:
if EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" " if EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" "
"/etc/nginx/nginx.conf"): "/etc/nginx/nginx.conf"):
self.app.log.info("Disabling Nginx rewrite logs") Log.info(self, "Disabling Nginx rewrite logs")
EEShellExec.cmd_exec(self, "sed -i \"/rewrite_log.*/d\"" EEShellExec.cmd_exec(self, "sed -i \"/rewrite_log.*/d\""
" /etc/nginx/nginx.conf") " /etc/nginx/nginx.conf")
self.trigger_nginx = True self.trigger_nginx = True
else: else:
self.app.log.info("NGINX rewrite logs already disbaled") Log.info(self, "NGINX rewrite logs already disbaled")
# Start Nginx rewrite for site # Start Nginx rewrite for site
elif self.start and self.app.pargs.site_name: elif self.start and self.app.pargs.site_name:
config_path = ("/etc/nginx/sites-available/{0}.conf" config_path = ("/etc/nginx/sites-available/{0}.conf"
.format(self.app.pargs.site_name)) .format(self.app.pargs.site_name))
if not EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}" if not EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}"
.format(config_path)): .format(config_path)):
self.app.log.info("Setting up NGINX rewrite logs for {0}" Log.info(self, "Setting up NGINX rewrite logs for {0}"
.format(self.app.pargs.site_name)) .format(self.app.pargs.site_name))
EEShellExec.cmd_exec(self, "sed -i \"/access_log/i \\\\\\t" EEShellExec.cmd_exec(self, "sed -i \"/access_log/i \\\\\\t"
"rewrite_log on;\" {0}" "rewrite_log on;\" {0}"
.format(config_path)) .format(config_path))
self.trigger_nginx = True self.trigger_nginx = True
else: else:
self.app.log.info("Nginx rewrite logs for {0} allready setup" Log.info(self, "Nginx rewrite logs for {0} allready setup"
.format(self.app.pargs.site_name)) .format(self.app.pargs.site_name))
if ('/var/www/{0}/logs/error.log'.format(self.app.pargs.site_name) if ('/var/www/{0}/logs/error.log'.format(self.app.pargs.site_name)
@ -351,15 +351,14 @@ class EEDebugController(CementBaseController):
.format(self.app.pargs.site_name)) .format(self.app.pargs.site_name))
if EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}" if EEShellExec.cmd_exec(self, "grep \"rewrite_log on;\" {0}"
.format(config_path)): .format(config_path)):
self.app.log.info("Disabling NGINX rewrite logs for {0}" Log.info(self, "Disabling NGINX rewrite logs for {0}"
.format(self.app.pargs.site_name)) .format(self.app.pargs.site_name))
EEShellExec.cmd_exec(self, "sed -i \"/rewrite_log.*/d\" {0}" EEShellExec.cmd_exec(self, "sed -i \"/rewrite_log.*/d\" {0}"
.format(config_path)) .format(config_path))
self.trigger_nginx = True self.trigger_nginx = True
else: else:
self.app.log.info("Nginx rewrite logs for {0} allready " Log.info(self, "Nginx rewrite logs for {0} allready "
" disbaled" " disbaled".format(self.app.pargs.site_name))
.format(self.app.pargs.site_name))
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
@ -404,10 +403,10 @@ class EEDebugController(CementBaseController):
# Reload PHP # Reload PHP
if self.trigger_php: if self.trigger_php:
EEService.reload_service(self, ['php5-fpm']) EEService.reload_service(self, ['php5-fpm'])
#
if len(self.msg) > 0: # if len(self.msg) > 0:
self.app.log.info("Use following command to check debug logs:" # self.app.log.info("Use following command to check debug logs:"
"\n{0}".format(self.msg.join())) # "\n{0}".format(self.msg.join()))
def load(app): def load(app):

11
ee/cli/plugins/secure.py

@ -7,6 +7,7 @@ import random
import sys import sys
import hashlib import hashlib
import getpass import getpass
from ee.core.logging import Log
def secure_plugin_hook(app): def secure_plugin_hook(app):
@ -50,11 +51,11 @@ class EEsecureController(CementBaseController):
"password [{0}]".format(passwd)) "password [{0}]".format(passwd))
if username == "": if username == "":
username = EEVariables.ee_user username = EEVariables.ee_user
self.app.log.info("HTTP authentication username:{username}" Log.info(self, "HTTP authentication username:{username}"
.format(username=username)) .format(username=username))
if password == "": if password == "":
password = passwd password = passwd
self.app.log.info("HTTP authentication password:{password}" Log.info(self, "HTTP authentication password:{password}"
.format(password=password)) .format(password=password))
EEShellExec.cmd_exec(self, "printf \"{username}:" EEShellExec.cmd_exec(self, "printf \"{username}:"
"$(openssl passwd -crypt " "$(openssl passwd -crypt "
@ -73,11 +74,15 @@ class EEsecureController(CementBaseController):
"{port} default_server ssl spdy;/\" " "{port} default_server ssl spdy;/\" "
"/etc/nginx/sites-available/22222" "/etc/nginx/sites-available/22222"
.format(port=port)) .format(port=port))
elif EEVariables.ee_platform_distro == 'Debian': else:
Log.info(self, "Unable to change EasyEngine admin port")
if EEVariables.ee_platform_distro == 'Debian':
EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen " EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen "
"{port} default_server ssl;/\" " "{port} default_server ssl;/\" "
"/etc/nginx/sites-available/22222" "/etc/nginx/sites-available/22222"
.format(port=port)) .format(port=port))
else:
Log.info(self, "Unable to change EasyEngine admin port")
@expose(hide=True) @expose(hide=True)
def secure_ip(self): def secure_ip(self):

271
ee/cli/plugins/stack.py

@ -23,6 +23,7 @@ import os
import pwd import pwd
import grp import grp
from ee.cli.plugins.stack_services import EEStackStatusController from ee.cli.plugins.stack_services import EEStackStatusController
from ee.core.logging import Log
def ee_stack_hook(app): def ee_stack_hook(app):
@ -69,12 +70,12 @@ class EEStackController(CementBaseController):
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
# TODO Default action for ee stack command # TODO Default action for ee stack command
print("Inside EEStackController.default().") Log.info(self, "Inside EEStackController.default().")
@expose(hide=True) @expose(hide=True)
def pre_pref(self, apt_packages): def pre_pref(self, apt_packages):
if set(EEVariables.ee_postfix).issubset(set(apt_packages)): if set(EEVariables.ee_postfix).issubset(set(apt_packages)):
print("Pre-seeding postfix variables ... ") Log.info(self, "Pre-seeding postfix variables ... ")
EEShellExec.cmd_exec(self, "echo \"postfix postfix" EEShellExec.cmd_exec(self, "echo \"postfix postfix"
"/main_mailer_type string \'Internet Site\'\"" "/main_mailer_type string \'Internet Site\'\""
" | debconf-set-selections") " | debconf-set-selections")
@ -82,12 +83,12 @@ class EEStackController(CementBaseController):
" $(hostname -f)\" | debconf-set-selections") " $(hostname -f)\" | debconf-set-selections")
if set(EEVariables.ee_mysql).issubset(set(apt_packages)): if set(EEVariables.ee_mysql).issubset(set(apt_packages)):
print("Adding repository for MySQL ... ") Log.info(self, "Adding repository for MySQL ... ")
EERepo.add(self, repo_url=EEVariables.ee_mysql_repo) EERepo.add(self, repo_url=EEVariables.ee_mysql_repo)
self.app.log.debug('Adding key of MySQL.') Log.debug(self, 'Adding key of MySQL.')
EERepo.add_key(self, '1C4CBDCDCD2EFD2A') EERepo.add_key(self, '1C4CBDCDCD2EFD2A')
chars = ''.join(random.sample(string.ascii_letters, 8)) chars = ''.join(random.sample(string.ascii_letters, 8))
print("Pre-seeding MySQL variables ... ") Log.info(self, "Pre-seeding MySQL variables ... ")
EEShellExec.cmd_exec(self, "echo \"percona-server-server-5.6 " EEShellExec.cmd_exec(self, "echo \"percona-server-server-5.6 "
"percona-server-server/root_password " "percona-server-server/root_password "
"password {chars}\" | " "password {chars}\" | "
@ -103,35 +104,35 @@ class EEStackController(CementBaseController):
""".format(chars=chars) """.format(chars=chars)
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read_string(mysql_config) config.read_string(mysql_config)
self.app.log.debug('writting configartion into MySQL file.') Log.debug(self, 'writting configartion into MySQL file.')
with open(os.path.expanduser("~")+'/.my.cnf', 'w') as configfile: with open(os.path.expanduser("~")+'/.my.cnf', 'w') as configfile:
config.write(configfile) config.write(configfile)
if set(EEVariables.ee_nginx).issubset(set(apt_packages)): if set(EEVariables.ee_nginx).issubset(set(apt_packages)):
print("Adding repository for Nginx ... ") Log.info(self, "Adding repository for Nginx ... ")
if EEVariables.ee_platform_distro == 'Debian': if EEVariables.ee_platform_distro == 'Debian':
self.app.log.debug('Adding Dotdeb/nginx GPG key') Log.debug(self, 'Adding Dotdeb/nginx GPG key')
EERepo.add(self, repo_url=EEVariables.ee_nginx_repo) EERepo.add(self, repo_url=EEVariables.ee_nginx_repo)
else: else:
self.app.log.debug('Adding ppa of Nginx') Log.debug(self, 'Adding ppa of Nginx')
EERepo.add(self, ppa=EEVariables.ee_nginx_repo) EERepo.add(self, ppa=EEVariables.ee_nginx_repo)
if set(EEVariables.ee_php).issubset(set(apt_packages)): if set(EEVariables.ee_php).issubset(set(apt_packages)):
print("Adding repository for PHP ... ") Log.info(self, "Adding repository for PHP ... ")
if EEVariables.ee_platform_distro == 'Debian': if EEVariables.ee_platform_distro == 'Debian':
self.app.log.debug('Adding repo_url of php for Debian') Log.debug(self, 'Adding repo_url of php for Debian')
EERepo.add(self, repo_url=EEVariables.ee_php_repo) EERepo.add(self, repo_url=EEVariables.ee_php_repo)
self.app.log.debug('Adding Dotdeb/php GPG key') Log.debug(self, 'Adding Dotdeb/php GPG key')
EERepo.add_key(self, '89DF5277') EERepo.add_key(self, '89DF5277')
else: else:
self.app.log.debug('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_mail).issubset(set(apt_packages)): if set(EEVariables.ee_mail).issubset(set(apt_packages)):
if EEVariables.ee_platform_codename == 'squeeze': if EEVariables.ee_platform_codename == 'squeeze':
print("Adding repository for dovecot ... ") Log.info(self, "Adding repository for dovecot ... ")
EERepo.add(self, repo_url=EEVariables.ee_dovecot_repo) EERepo.add(self, repo_url=EEVariables.ee_dovecot_repo)
self.app.log.debug('Executing the command debconf-set-selections.') Log.debug(self, 'Executing the command debconf-set-selections.')
EEShellExec.cmd_exec(self, "echo \"dovecot-core dovecot-core/" EEShellExec.cmd_exec(self, "echo \"dovecot-core dovecot-core/"
"create-ssl-cert boolean yes\" " "create-ssl-cert boolean yes\" "
"| debconf-set-selections") "| debconf-set-selections")
@ -151,7 +152,7 @@ class EEStackController(CementBaseController):
if ((not os.path.isfile('/etc/nginx/conf.d/ee-nginx.conf')) and if ((not os.path.isfile('/etc/nginx/conf.d/ee-nginx.conf')) and
os.path.isfile('/etc/nginx/nginx.conf')): os.path.isfile('/etc/nginx/nginx.conf')):
nc = NginxConfig() nc = NginxConfig()
self.app.log.debug('Loading file /etc/nginx/nginx.conf ') Log.debug(self, 'Loading file /etc/nginx/nginx.conf ')
nc.loadf('/etc/nginx/nginx.conf') nc.loadf('/etc/nginx/nginx.conf')
nc.set('worker_processes', 'auto') nc.set('worker_processes', 'auto')
nc.append(('worker_rlimit_nofile', '100000'), position=2) nc.append(('worker_rlimit_nofile', '100000'), position=2)
@ -160,13 +161,13 @@ class EEStackController(CementBaseController):
[('worker_connections', '4096'), [('worker_connections', '4096'),
('multi_accept', 'on')]}, position=4) ('multi_accept', 'on')]}, position=4)
nc.set([('http',), 'keepalive_timeout'], '30') nc.set([('http',), 'keepalive_timeout'], '30')
self.app.log.debug("Writting nginx configration to " Log.debug(self, "Writting nginx configration to "
"file /etc/nginx/nginx.conf ") "file /etc/nginx/nginx.conf ")
nc.savef('/etc/nginx/nginx.conf') nc.savef('/etc/nginx/nginx.conf')
# Custom Nginx configuration by EasyEngine # Custom Nginx configuration by EasyEngine
data = dict(version='EasyEngine 3.0.1') data = dict(version='EasyEngine 3.0.1')
self.app.log.debug('writting the nginx configration to ' Log.debug(self, 'writting the nginx configration to '
'file /etc/nginx/conf.d/ee-nginx.conf ') 'file /etc/nginx/conf.d/ee-nginx.conf ')
ee_nginx = open('/etc/nginx/conf.d/ee-nginx.conf', 'w') ee_nginx = open('/etc/nginx/conf.d/ee-nginx.conf', 'w')
self.app.render((data), 'nginx-core.mustache', self.app.render((data), 'nginx-core.mustache',
@ -174,20 +175,20 @@ class EEStackController(CementBaseController):
ee_nginx.close() ee_nginx.close()
data = dict() data = dict()
self.app.log.debug('writting the nginx configration to' Log.debug(self, 'writting the nginx configration to'
'file /etc/nginx/conf.d/blockips.conf') 'file /etc/nginx/conf.d/blockips.conf')
ee_nginx = open('/etc/nginx/conf.d/blockips.conf', 'w') ee_nginx = open('/etc/nginx/conf.d/blockips.conf', 'w')
self.app.render((data), 'blockips.mustache', out=ee_nginx) self.app.render((data), 'blockips.mustache', out=ee_nginx)
ee_nginx.close() ee_nginx.close()
self.app.log.debug('writting the nginx configration to' Log.debug(self, 'writting the nginx configration to'
' file /etc/nginx/conf.d/fastcgi.conf') ' file /etc/nginx/conf.d/fastcgi.conf')
ee_nginx = open('/etc/nginx/conf.d/fastcgi.conf', 'w') ee_nginx = open('/etc/nginx/conf.d/fastcgi.conf', 'w')
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")
self.app.log.debug('writting the nginx configration to' Log.debug(self, 'writting the nginx configration to'
'file /etc/nginx/conf.d/upstream.conf ') 'file /etc/nginx/conf.d/upstream.conf ')
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)
@ -195,61 +196,61 @@ class EEStackController(CementBaseController):
# Setup Nginx common directory # Setup Nginx common directory
if not os.path.exists('/etc/nginx/common'): if not os.path.exists('/etc/nginx/common'):
self.app.log.debug('Creating directory' Log.debug(self, 'Creating directory'
'/etc/nginx/common') '/etc/nginx/common')
os.makedirs('/etc/nginx/common') os.makedirs('/etc/nginx/common')
data = dict() data = dict()
self.app.log.debug('Writting the nginx configration to' Log.debug(self, 'Writting the nginx configration to'
'file /etc/nginx/common/acl.conf') 'file /etc/nginx/common/acl.conf')
ee_nginx = open('/etc/nginx/common/acl.conf', 'w') ee_nginx = open('/etc/nginx/common/acl.conf', 'w')
self.app.render((data), 'acl.mustache', self.app.render((data), 'acl.mustache',
out=ee_nginx) out=ee_nginx)
ee_nginx.close() ee_nginx.close()
self.app.log.debug('Writting the nginx configration to' Log.debug(self, 'Writting the nginx configration to'
'file /etc/nginx/common/locations.conf') 'file /etc/nginx/common/locations.conf')
ee_nginx = open('/etc/nginx/common/locations.conf', 'w') ee_nginx = open('/etc/nginx/common/locations.conf', 'w')
self.app.render((data), 'locations.mustache', self.app.render((data), 'locations.mustache',
out=ee_nginx) out=ee_nginx)
ee_nginx.close() ee_nginx.close()
self.app.log.debug('Writting the nginx configration to' Log.debug(self, 'Writting the nginx configration to'
'file /etc/nginx/common/ php.conf') 'file /etc/nginx/common/ php.conf')
ee_nginx = open('/etc/nginx/common/php.conf', 'w') ee_nginx = open('/etc/nginx/common/php.conf', 'w')
self.app.render((data), 'php.mustache', self.app.render((data), 'php.mustache',
out=ee_nginx) out=ee_nginx)
ee_nginx.close() ee_nginx.close()
self.app.log.debug('Writting the nginx configration to' Log.debug(self, 'Writting the nginx configration to'
'file /etc/nginx/common/w3tc.conf') 'file /etc/nginx/common/w3tc.conf')
ee_nginx = open('/etc/nginx/common/w3tc.conf', 'w') ee_nginx = open('/etc/nginx/common/w3tc.conf', 'w')
self.app.render((data), 'w3tc.mustache', self.app.render((data), 'w3tc.mustache',
out=ee_nginx) out=ee_nginx)
ee_nginx.close() ee_nginx.close()
self.app.log.debug('Writting the nginx configration to' Log.debug(self, 'Writting the nginx configration to'
'file /etc/nginx/common/wpcommon.conf') 'file /etc/nginx/common/wpcommon.conf')
ee_nginx = open('/etc/nginx/common/wpcommon.conf', 'w') ee_nginx = open('/etc/nginx/common/wpcommon.conf', 'w')
self.app.render((data), 'wpcommon.mustache', self.app.render((data), 'wpcommon.mustache',
out=ee_nginx) out=ee_nginx)
ee_nginx.close() ee_nginx.close()
self.app.log.debug('Writting the nginx configration to' Log.debug(self, 'Writting the nginx configration to'
'file /etc/nginx/common/wpfc.conf') 'file /etc/nginx/common/wpfc.conf')
ee_nginx = open('/etc/nginx/common/wpfc.conf', 'w') ee_nginx = open('/etc/nginx/common/wpfc.conf', 'w')
self.app.render((data), 'wpfc.mustache', self.app.render((data), 'wpfc.mustache',
out=ee_nginx) out=ee_nginx)
ee_nginx.close() ee_nginx.close()
self.app.log.debug('Writting the nginx configration to' Log.debug(self, 'Writting the nginx configration to'
'file /etc/nginx/common/wpsc.conf') 'file /etc/nginx/common/wpsc.conf')
ee_nginx = open('/etc/nginx/common/wpsc.conf', 'w') ee_nginx = open('/etc/nginx/common/wpsc.conf', 'w')
self.app.render((data), 'wpsc.mustache', self.app.render((data), 'wpsc.mustache',
out=ee_nginx) out=ee_nginx)
ee_nginx.close() ee_nginx.close()
self.app.log.debug('Writting the nginx configration to' Log.debug(self, 'Writting the nginx configration to'
'file /etc/nginx/common/wpsubdir.conf') 'file /etc/nginx/common/wpsubdir.conf')
ee_nginx = open('/etc/nginx/common/wpsubdir.conf', 'w') ee_nginx = open('/etc/nginx/common/wpsubdir.conf', 'w')
self.app.render((data), 'wpsubdir.mustache', self.app.render((data), 'wpsubdir.mustache',
@ -257,7 +258,7 @@ class EEStackController(CementBaseController):
ee_nginx.close() ee_nginx.close()
# 22222 port settings # 22222 port settings
self.app.log.debug('Writting the nginx configration to' Log.debug(self, 'Writting the nginx configration to'
'file /etc/nginx/sites-available/' 'file /etc/nginx/sites-available/'
'22222.conf') '22222.conf')
ee_nginx = open('/etc/nginx/sites-available/22222.conf', ee_nginx = open('/etc/nginx/sites-available/22222.conf',
@ -269,7 +270,7 @@ class EEStackController(CementBaseController):
passwd = ''.join([random.choice passwd = ''.join([random.choice
(string.ascii_letters + string.digits) (string.ascii_letters + string.digits)
for n in range(6)]) for n in range(6)])
EEShellExec.cmd_exec(self, "printf \"easyengine:" EEShellExec.cmd_exec(self, "Log.infof \"easyengine:"
"$(openssl passwd -crypt " "$(openssl passwd -crypt "
"{password} 2> /dev/null)\n\"" "{password} 2> /dev/null)\n\""
"> /etc/nginx/htpasswd-ee 2>/dev/null" "> /etc/nginx/htpasswd-ee 2>/dev/null"
@ -329,12 +330,12 @@ class EEStackController(CementBaseController):
if set(EEVariables.ee_php).issubset(set(apt_packages)): if set(EEVariables.ee_php).issubset(set(apt_packages)):
# Create log directories # Create log directories
if not os.path.exists('/var/log/php5/'): if not os.path.exists('/var/log/php5/'):
self.app.log.debug('Creating directory /var/log/php5/') Log.debug(self, 'Creating directory /var/log/php5/')
os.makedirs('/var/log/php5/') os.makedirs('/var/log/php5/')
# Parse etc/php5/fpm/php.ini # Parse etc/php5/fpm/php.ini
config = configparser.ConfigParser() config = configparser.ConfigParser()
self.app.log.debug("configring php file /etc/php5/fpm/php.ini") Log.debug(self, "configring php file /etc/php5/fpm/php.ini")
config.read('/etc/php5/fpm/php.ini') config.read('/etc/php5/fpm/php.ini')
config['PHP']['expose_php'] = 'Off' config['PHP']['expose_php'] = 'Off'
config['PHP']['post_max_size'] = '100M' config['PHP']['post_max_size'] = '100M'
@ -342,7 +343,7 @@ class EEStackController(CementBaseController):
config['PHP']['max_execution_time'] = '300' config['PHP']['max_execution_time'] = '300'
config['PHP']['date.timezone'] = time.tzname[time.daylight] config['PHP']['date.timezone'] = time.tzname[time.daylight]
with open('/etc/php5/fpm/php.ini', 'w') as configfile: with open('/etc/php5/fpm/php.ini', 'w') as configfile:
self.app.log.debug("writting configration of php in to" Log.debug(self, "writting configration of php in to"
"file /etc/php5/fpm/php.ini") "file /etc/php5/fpm/php.ini")
config.write(configfile) config.write(configfile)
@ -351,7 +352,7 @@ class EEStackController(CementBaseController):
config.read('/etc/php5/fpm/php-fpm.conf') config.read('/etc/php5/fpm/php-fpm.conf')
config['global']['error_log'] = '/var/log/php5/fpm.log' config['global']['error_log'] = '/var/log/php5/fpm.log'
with open('/etc/php5/fpm/php-fpm.conf', 'w') as configfile: with open('/etc/php5/fpm/php-fpm.conf', 'w') as configfile:
self.app.log.debug("writting php5 configartion into " Log.debug(self, "writting php5 configartion into "
" /etc/php5/fpm/php-fpm.conf") " /etc/php5/fpm/php-fpm.conf")
config.write(configfile) config.write(configfile)
@ -369,7 +370,7 @@ class EEStackController(CementBaseController):
config['www']['pm'] = 'ondemand' config['www']['pm'] = 'ondemand'
config['www']['listen'] = '127.0.0.1:9000' config['www']['listen'] = '127.0.0.1:9000'
with open('/etc/php5/fpm/pool.d/www.conf', 'w') as configfile: with open('/etc/php5/fpm/pool.d/www.conf', 'w') as configfile:
self.app.log.debug("writting PHP5 configartion into " Log.debug(self, "writting PHP5 configartion into "
" /etc/php5/fpm/pool.d/www.conf") " /etc/php5/fpm/pool.d/www.conf")
config.write(configfile) config.write(configfile)
@ -382,7 +383,7 @@ class EEStackController(CementBaseController):
config.read('/etc/php5/fpm/pool.d/debug.conf') config.read('/etc/php5/fpm/pool.d/debug.conf')
config['debug']['listen'] = '127.0.0.1:9001' config['debug']['listen'] = '127.0.0.1:9001'
with open('/etc/php5/fpm/pool.d/debug.conf', 'w') as confifile: with open('/etc/php5/fpm/pool.d/debug.conf', 'w') as confifile:
self.app.log.debug("writting PHP5 configartion into " Log.debug(self, "writting PHP5 configartion into "
" /etc/php5/fpm/pool.d/debug.conf") " /etc/php5/fpm/pool.d/debug.conf")
config.write(confifile) config.write(confifile)
EEGit.add(self, ["/etc/php5"], msg="Adding PHP into Git") EEGit.add(self, ["/etc/php5"], msg="Adding PHP into Git")
@ -414,7 +415,7 @@ class EEStackController(CementBaseController):
EEService.reload_service(self, 'mysql') EEService.reload_service(self, 'mysql')
if set(EEVariables.ee_mail).issubset(set(apt_packages)): if set(EEVariables.ee_mail).issubset(set(apt_packages)):
self.app.log.debug("Executing mail commands") Log.debug(self, "Executing mail commands")
EEShellExec.cmd_exec(self, "adduser --uid 5000 --home /var" EEShellExec.cmd_exec(self, "adduser --uid 5000 --home /var"
"/vmail --disabled-password --gecos ''" "/vmail --disabled-password --gecos ''"
" vmail") " vmail")
@ -425,14 +426,14 @@ class EEStackController(CementBaseController):
"pem -keyout /etc/ssl/private/dovecot.pem" "pem -keyout /etc/ssl/private/dovecot.pem"
.format(HOSTNAME=EEVariables.ee_fqdn, .format(HOSTNAME=EEVariables.ee_fqdn,
EMAIL=EEVariables.ee_email)) EMAIL=EEVariables.ee_email))
self.app.log.debug("Adding Privillages to file " Log.debug(self, "Adding Privillages to file "
"/etc/ssl/private/dovecot.pem ") "/etc/ssl/private/dovecot.pem ")
EEShellExec.cmd_exec(self, "chmod 0600 /etc/ssl/private" EEShellExec.cmd_exec(self, "chmod 0600 /etc/ssl/private"
"/dovecot.pem") "/dovecot.pem")
# Custom Dovecot configuration by EasyEngine # Custom Dovecot configuration by EasyEngine
data = dict() data = dict()
self.app.log.debug("Writting configration into file" Log.debug(self, "Writting configration into file"
"/etc/dovecot/conf.d/99-ee.conf ") "/etc/dovecot/conf.d/99-ee.conf ")
ee_dovecot = open('/etc/dovecot/conf.d/99-ee.conf', 'w') ee_dovecot = open('/etc/dovecot/conf.d/99-ee.conf', 'w')
self.app.render((data), 'dovecot.mustache', out=ee_dovecot) self.app.render((data), 'dovecot.mustache', out=ee_dovecot)
@ -503,13 +504,13 @@ class EEStackController(CementBaseController):
# Sieve configuration # Sieve configuration
if not os.path.exists('/var/lib/dovecot/sieve/'): if not os.path.exists('/var/lib/dovecot/sieve/'):
self.app.log.debug('Creating directory' Log.debug(self, 'Creating directory'
'/var/lib/dovecot/sieve/ ') '/var/lib/dovecot/sieve/ ')
os.makedirs('/var/lib/dovecot/sieve/') os.makedirs('/var/lib/dovecot/sieve/')
# Custom sieve configuration by EasyEngine # Custom sieve configuration by EasyEngine
data = dict() data = dict()
self.app.log.debug("Writting configaration of EasyEngine into" Log.debug(self, "Writting configaration of EasyEngine into"
"file /var/lib/dovecot/sieve/default.sieve") "file /var/lib/dovecot/sieve/default.sieve")
ee_sieve = open('/var/lib/dovecot/sieve/default.sieve', 'w') ee_sieve = open('/var/lib/dovecot/sieve/default.sieve', 'w')
self.app.render((data), 'default-sieve.mustache', self.app.render((data), 'default-sieve.mustache',
@ -517,7 +518,7 @@ class EEStackController(CementBaseController):
ee_sieve.close() ee_sieve.close()
# Compile sieve rules # Compile sieve rules
self.app.log.debug("Privillages to dovecot ") Log.debug(self, "Privillages to dovecot ")
# EEShellExec.cmd_exec(self, "chown -R vmail:vmail /var/lib" # EEShellExec.cmd_exec(self, "chown -R vmail:vmail /var/lib"
# "/dovecot") # "/dovecot")
EEFileUtils.chown(self, "/var/lig/dovecot", "vmail", "vmail", EEFileUtils.chown(self, "/var/lig/dovecot", "vmail", "vmail",
@ -532,7 +533,7 @@ class EEStackController(CementBaseController):
if set(EEVariables.ee_mailscanner).issubset(set(apt_packages)): if set(EEVariables.ee_mailscanner).issubset(set(apt_packages)):
# Set up Custom amavis configuration # Set up Custom amavis configuration
data = dict() data = dict()
self.app.log.debug("Configuring file /etc/amavis/conf.d" Log.debug(self, "Configuring file /etc/amavis/conf.d"
"/15-content_filter_mode") "/15-content_filter_mode")
ee_amavis = open('/etc/amavis/conf.d/15-content_filter_mode', ee_amavis = open('/etc/amavis/conf.d/15-content_filter_mode',
'w') 'w')
@ -550,17 +551,17 @@ class EEStackController(CementBaseController):
"_checks/\" /etc/postfix/master.cf") "_checks/\" /etc/postfix/master.cf")
# Amavis ClamAV configuration # Amavis ClamAV configuration
self.app.log.debug("Adding new user clamav amavis") Log.debug(self, "Adding new user clamav amavis")
EEShellExec.cmd_exec(self, "adduser clamav amavis") EEShellExec.cmd_exec(self, "adduser clamav amavis")
self.app.log.debug("Adding new user amavis clamav") Log.debug(self, "Adding new user amavis clamav")
EEShellExec.cmd_exec(self, "adduser amavis clamav") EEShellExec.cmd_exec(self, "adduser amavis clamav")
self.app.log.debug("Privillages to file /var/lib/amavis/tmp ") Log.debug(self, "Privillages to file /var/lib/amavis/tmp ")
EEShellExec.cmd_exec(self, "chmod -R 775 /var/lib/amavis/tmp") EEShellExec.cmd_exec(self, "chmod -R 775 /var/lib/amavis/tmp")
# Update ClamAV database # Update ClamAV database
self.app.log.debug("Updating database") Log.debug(self, "Updating database")
EEShellExec.cmd_exec(self, "freshclam") EEShellExec.cmd_exec(self, "freshclam")
self.app.log.debug("Restarting service clamav-daemon") Log.debug(self, "Restarting service clamav-daemon")
EEShellExec.cmd_exec(self, "service clamav-daemon restart") EEShellExec.cmd_exec(self, "service clamav-daemon restart")
EEGit.add(self, ["/etc/amavis"], msg="Adding Amvis into Git") EEGit.add(self, ["/etc/amavis"], msg="Adding Amvis into Git")
EEService.reload_service(self, 'dovecot') EEService.reload_service(self, 'dovecot')
@ -569,20 +570,20 @@ class EEStackController(CementBaseController):
if len(packages): if len(packages):
if any('/usr/bin/wp' == x[1] for x in packages): if any('/usr/bin/wp' == x[1] for x in packages):
self.app.log.debug("Privillages to /usr/bin/wp ") Log.debug(self, "Privillages to /usr/bin/wp ")
EEShellExec.cmd_exec(self, "chmod +x /usr/bin/wp") EEShellExec.cmd_exec(self, "chmod +x /usr/bin/wp")
if any('/tmp/pma.tar.gz' == x[1] if any('/tmp/pma.tar.gz' == x[1]
for x in packages): for x in packages):
EEExtract.extract(self, '/tmp/pma.tar.gz', '/tmp/') EEExtract.extract(self, '/tmp/pma.tar.gz', '/tmp/')
self.app.log.debug('Extracting file /tmp/pma.tar.gz to ' Log.debug(self, 'Extracting file /tmp/pma.tar.gz to '
'loaction /tmp/') 'loaction /tmp/')
if not os.path.exists('/var/www/22222/htdocs/db'): if not os.path.exists('/var/www/22222/htdocs/db'):
self.app.log.debug("Creating new directory " Log.debug(self, "Creating new directory "
"/var/www/22222/htdocs/db") "/var/www/22222/htdocs/db")
os.makedirs('/var/www/22222/htdocs/db') os.makedirs('/var/www/22222/htdocs/db')
shutil.move('/tmp/phpmyadmin-STABLE/', shutil.move('/tmp/phpmyadmin-STABLE/',
'/var/www/22222/htdocs/db/pma/') '/var/www/22222/htdocs/db/pma/')
self.app.log.debug('Privillages to www-data:www-data ' Log.debug(self, 'Privillages to www-data:www-data '
'/var/www/22222/htdocs/db/pma ') '/var/www/22222/htdocs/db/pma ')
# EEShellExec.cmd_exec(self, 'chown -R www-data:www-data ' # EEShellExec.cmd_exec(self, 'chown -R www-data:www-data '
# '/var/www/22222/htdocs/db/pma') # '/var/www/22222/htdocs/db/pma')
@ -591,11 +592,11 @@ class EEStackController(CementBaseController):
EEVariables.ee_php_user, recursive=True) EEVariables.ee_php_user, recursive=True)
if any('/tmp/memcache.tar.gz' == x[1] if any('/tmp/memcache.tar.gz' == x[1]
for x in packages): for x in packages):
self.app.log.debug("Extracting memcache.tar.gz to location" Log.debug(self, "Extracting memcache.tar.gz to location"
" /var/www/22222/htdocs/cache/memcache ") " /var/www/22222/htdocs/cache/memcache ")
EEExtract.extract(self, '/tmp/memcache.tar.gz', EEExtract.extract(self, '/tmp/memcache.tar.gz',
'/var/www/22222/htdocs/cache/memcache') '/var/www/22222/htdocs/cache/memcache')
self.app.log.debug("Privillages to" Log.debug(self, "Privillages to"
" /var/www/22222/htdocs/cache/memcache") " /var/www/22222/htdocs/cache/memcache")
# EEShellExec.cmd_exec(self, 'chown -R www-data:www-data ' # EEShellExec.cmd_exec(self, 'chown -R www-data:www-data '
# '/var/www/22222/htdocs/cache/memcache') # '/var/www/22222/htdocs/cache/memcache')
@ -605,16 +606,16 @@ class EEStackController(CementBaseController):
if any('/tmp/webgrind.tar.gz' == x[1] if any('/tmp/webgrind.tar.gz' == x[1]
for x in packages): for x in packages):
self.app.log.debug("Extracting file webgrind.tar.gz to " Log.debug(self, "Extracting file webgrind.tar.gz to "
"location /tmp/ ") "location /tmp/ ")
EEExtract.extract(self, '/tmp/webgrind.tar.gz', '/tmp/') EEExtract.extract(self, '/tmp/webgrind.tar.gz', '/tmp/')
if not os.path.exists('/var/www/22222/htdocs/php'): if not os.path.exists('/var/www/22222/htdocs/php'):
self.app.log.debug("Creating directroy " Log.debug(self, "Creating directroy "
"/var/www/22222/htdocs/php") "/var/www/22222/htdocs/php")
os.makedirs('/var/www/22222/htdocs/php') os.makedirs('/var/www/22222/htdocs/php')
shutil.move('/tmp/webgrind-master/', shutil.move('/tmp/webgrind-master/',
'/var/www/22222/htdocs/php/webgrind') '/var/www/22222/htdocs/php/webgrind')
self.app.log.debug("Privillages www-data:www-data " Log.debug(self, "Privillages www-data:www-data "
"/var/www/22222/htdocs/php/webgrind/ ") "/var/www/22222/htdocs/php/webgrind/ ")
# EEShellExec.cmd_exec(self, 'chown -R www-data:www-data ' # EEShellExec.cmd_exec(self, 'chown -R www-data:www-data '
# '/var/www/22222/htdocs/php/webgrind/') # '/var/www/22222/htdocs/php/webgrind/')
@ -624,11 +625,11 @@ class EEStackController(CementBaseController):
if any('/tmp/anemometer.tar.gz' == x[1] if any('/tmp/anemometer.tar.gz' == x[1]
for x in packages): for x in packages):
self.app.log.debug("Extracting file anemometer.tar.gz to " Log.debug(self, "Extracting file anemometer.tar.gz to "
"location /tmp/ ") "location /tmp/ ")
EEExtract.extract(self, '/tmp/anemometer.tar.gz', '/tmp/') EEExtract.extract(self, '/tmp/anemometer.tar.gz', '/tmp/')
if not os.path.exists('/var/www/22222/htdocs/db/'): if not os.path.exists('/var/www/22222/htdocs/db/'):
self.app.log.debug("Creating directory") Log.debug(self, "Creating directory")
os.makedirs('/var/www/22222/htdocs/db/') os.makedirs('/var/www/22222/htdocs/db/')
shutil.move('/tmp/Anemometer-master', shutil.move('/tmp/Anemometer-master',
'/var/www/22222/htdocs/db/anemometer') '/var/www/22222/htdocs/db/anemometer')
@ -642,7 +643,7 @@ class EEStackController(CementBaseController):
' BY \''+chars+'\'') ' BY \''+chars+'\'')
# Custom Anemometer configuration # Custom Anemometer configuration
self.app.log.debug("configration Anemometer") Log.debug(self, "configration Anemometer")
data = dict(host='localhost', port='3306', user='anemometer', data = dict(host='localhost', port='3306', user='anemometer',
password=chars) password=chars)
ee_anemometer = open('/var/www/22222/htdocs/db/anemometer' ee_anemometer = open('/var/www/22222/htdocs/db/anemometer'
@ -658,24 +659,24 @@ class EEStackController(CementBaseController):
if any('/tmp/vimbadmin.tar.gz' == x[1] for x in packages): if any('/tmp/vimbadmin.tar.gz' == x[1] for x in packages):
# Extract ViMbAdmin # Extract ViMbAdmin
self.app.log.debug("Extracting ViMbAdmin.tar.gz to " Log.debug(self, "Extracting ViMbAdmin.tar.gz to "
"location /tmp/") "location /tmp/")
EEExtract.extract(self, '/tmp/vimbadmin.tar.gz', '/tmp/') EEExtract.extract(self, '/tmp/vimbadmin.tar.gz', '/tmp/')
if not os.path.exists('/var/www/22222/htdocs/'): if not os.path.exists('/var/www/22222/htdocs/'):
self.app.log.debug("Creating directory " Log.debug(self, "Creating directory "
" /var/www/22222/htdocs/") " /var/www/22222/htdocs/")
os.makedirs('/var/www/22222/htdocs/') os.makedirs('/var/www/22222/htdocs/')
shutil.move('/tmp/ViMbAdmin-3.0.10/', shutil.move('/tmp/ViMbAdmin-3.0.10/',
'/var/www/22222/htdocs/vimbadmin/') '/var/www/22222/htdocs/vimbadmin/')
# Donwload composer and install ViMbAdmin # Donwload composer and install ViMbAdmin
self.app.log.debug("Downloading composer " Log.debug(self, "Downloading composer "
"https://getcomposer.org/installer | php ") "https://getcomposer.org/installer | php ")
EEShellExec.cmd_exec(self, "cd /var/www/22222/htdocs" EEShellExec.cmd_exec(self, "cd /var/www/22222/htdocs"
"/vimbadmin; curl" "/vimbadmin; curl"
" -sS https://getcomposer.org/installer |" " -sS https://getcomposer.org/installer |"
" php") " php")
self.app.log.debug("installation of composer") Log.debug(self, "installation of composer")
EEShellExec.cmd_exec(self, "cd /var/www/22222/htdocs" EEShellExec.cmd_exec(self, "cd /var/www/22222/htdocs"
"/vimbadmin && " "/vimbadmin && "
"php composer.phar install --prefer-dist" "php composer.phar install --prefer-dist"
@ -684,17 +685,17 @@ class EEStackController(CementBaseController):
# Configure vimbadmin database # Configure vimbadmin database
vm_passwd = ''.join(random.sample(string.ascii_letters, 8)) vm_passwd = ''.join(random.sample(string.ascii_letters, 8))
self.app.log.debug("Creating vimbadmin database if not exist") Log.debug(self, "Creating vimbadmin database if not exist")
EEMysql.execute(self, "create database if not exists" EEMysql.execute(self, "create database if not exists"
" vimbadmin") " vimbadmin")
self.app.log.debug("Granting all privileges on vimbadmin ") Log.debug(self, "Granting all privileges on vimbadmin ")
EEMysql.execute(self, "grant all privileges on vimbadmin.* to" EEMysql.execute(self, "grant all privileges on vimbadmin.* to"
" vimbadmin@localhost IDENTIFIED BY" " vimbadmin@localhost IDENTIFIED BY"
" '{password}'".format(password=vm_passwd)) " '{password}'".format(password=vm_passwd))
# Configure ViMbAdmin settings # Configure ViMbAdmin settings
config = configparser.ConfigParser(strict=False) config = configparser.ConfigParser(strict=False)
self.app.log.debug("configuring ViMbAdmin ") Log.debug(self, "configuring ViMbAdmin ")
config.read('/var/www/22222/htdocs/vimbadmin/application/' config.read('/var/www/22222/htdocs/vimbadmin/application/'
'configs/application.ini.dist') 'configs/application.ini.dist')
config['user']['defaults.mailbox.uid'] = '5000' config['user']['defaults.mailbox.uid'] = '5000'
@ -725,7 +726,7 @@ class EEStackController(CementBaseController):
(string.ascii_letters (string.ascii_letters
+ string.ascii_letters, + string.ascii_letters,
64))) 64)))
self.app.log.debug("Writting configration to file " Log.debug(self, "Writting configration to file "
"/var/www/22222/htdocs/vimbadmin" "/var/www/22222/htdocs/vimbadmin"
"/application/configs/application.ini ") "/application/configs/application.ini ")
with open('/var/www/22222/htdocs/vimbadmin/application' with open('/var/www/22222/htdocs/vimbadmin/application'
@ -736,7 +737,7 @@ class EEStackController(CementBaseController):
".htaccess.dist", ".htaccess.dist",
"/var/www/22222/htdocs/vimbadmin/public/" "/var/www/22222/htdocs/vimbadmin/public/"
".htaccess") ".htaccess")
self.app.log.debug("Executing command " Log.debug(self, "Executing command "
"/var/www/22222/htdocs/vimbadmin/bin" "/var/www/22222/htdocs/vimbadmin/bin"
"/doctrine2-cli.php orm:schema-tool:" "/doctrine2-cli.php orm:schema-tool:"
"create") "create")
@ -752,7 +753,7 @@ class EEStackController(CementBaseController):
# Vimbadmin # Vimbadmin
if not os.path.exists('/etc/postfix/mysql/'): if not os.path.exists('/etc/postfix/mysql/'):
self.app.log.debug("Creating directory " Log.debug(self, "Creating directory "
"/etc/postfix/mysql/") "/etc/postfix/mysql/")
os.makedirs('/etc/postfix/mysql/') os.makedirs('/etc/postfix/mysql/')
data = dict(password=vm_passwd) data = dict(password=vm_passwd)
@ -762,7 +763,7 @@ class EEStackController(CementBaseController):
out=vm_config) out=vm_config)
vm_config.close() vm_config.close()
self.app.log.debug("Configration of file " Log.debug(self, "Configration of file "
"/etc/postfix/mysql" "/etc/postfix/mysql"
"/virtual_domains_maps.cf") "/virtual_domains_maps.cf")
vm_config = open('/etc/postfix/mysql/virtual_domains_maps.cf', vm_config = open('/etc/postfix/mysql/virtual_domains_maps.cf',
@ -771,7 +772,7 @@ class EEStackController(CementBaseController):
out=vm_config) out=vm_config)
vm_config.close() vm_config.close()
self.app.log.debug("Configation of file " Log.debug(self, "Configation of file "
"/etc/postfix/mysql" "/etc/postfix/mysql"
"/virtual_mailbox_maps.cf ") "/virtual_mailbox_maps.cf ")
vm_config = open('/etc/postfix/mysql/virtual_mailbox_maps.cf', vm_config = open('/etc/postfix/mysql/virtual_mailbox_maps.cf',
@ -780,7 +781,7 @@ class EEStackController(CementBaseController):
out=vm_config) out=vm_config)
vm_config.close() vm_config.close()
self.app.log.debug("Configration of file ") Log.debug(self, "Configration of file ")
vm_config = open('/etc/dovecot/dovecot-sql.conf.ext', vm_config = open('/etc/dovecot/dovecot-sql.conf.ext',
'w') 'w')
self.app.render((data), 'dovecot-sql-conf.mustache', self.app.render((data), 'dovecot-sql-conf.mustache',
@ -801,11 +802,11 @@ class EEStackController(CementBaseController):
if any('/tmp/roundcube.tar.gz' == x[1] for x in packages): if any('/tmp/roundcube.tar.gz' == x[1] for x in packages):
# Extract RoundCubemail # Extract RoundCubemail
self.app.log.debug("Extracting file /tmp/roundcube.tar.gz " Log.debug(self, "Extracting file /tmp/roundcube.tar.gz "
"to location /tmp/ ") "to location /tmp/ ")
EEExtract.extract(self, '/tmp/roundcube.tar.gz', '/tmp/') EEExtract.extract(self, '/tmp/roundcube.tar.gz', '/tmp/')
if not os.path.exists('/var/www/roundcubemail'): if not os.path.exists('/var/www/roundcubemail'):
self.app.log.debug("Creating new directory " Log.debug(self, "Creating new directory "
" /var/www/roundcubemail/") " /var/www/roundcubemail/")
os.makedirs('/var/www/roundcubemail/') os.makedirs('/var/www/roundcubemail/')
shutil.move('/tmp/roundcubemail-1.0.4/', shutil.move('/tmp/roundcubemail-1.0.4/',
@ -813,10 +814,10 @@ class EEStackController(CementBaseController):
# Configure roundcube database # Configure roundcube database
rc_passwd = ''.join(random.sample(string.ascii_letters, 8)) rc_passwd = ''.join(random.sample(string.ascii_letters, 8))
self.app.log.debug("Creating Database roundcubemail") Log.debug(self, "Creating Database roundcubemail")
EEMysql.execute(self, "create database if not exists " EEMysql.execute(self, "create database if not exists "
" roundcubemail") " roundcubemail")
self.app.log.debug("Grant all privileges on roundcubemail") Log.debug(self, "Grant all privileges on roundcubemail")
EEMysql.execute(self, "grant all privileges" EEMysql.execute(self, "grant all privileges"
" on roundcubemail.* to " " on roundcubemail.* to "
" roundcube@localhost IDENTIFIED BY " " roundcube@localhost IDENTIFIED BY "
@ -855,7 +856,7 @@ class EEStackController(CementBaseController):
ee_db_user='', ee_db_pass='', ee_db_host='', ee_db_user='', ee_db_pass='', ee_db_host='',
rc=True) rc=True)
self.app.log.debug('Writting the nginx configration for' Log.debug(self, 'Writting the nginx configration for'
' RoundCubemail') ' RoundCubemail')
ee_rc = open('/etc/nginx/sites-available/webmail.conf', 'w') ee_rc = open('/etc/nginx/sites-available/webmail.conf', 'w')
self.app.render((data), 'virtualconf.mustache', self.app.render((data), 'virtualconf.mustache',
@ -891,7 +892,7 @@ class EEStackController(CementBaseController):
@expose() @expose()
def install(self, packages=[], apt_packages=[]): def install(self, packages=[], apt_packages=[]):
if self.app.pargs.web: if self.app.pargs.web:
self.app.log.debug("Setting apt_packages variable for Nginx ,PHP" Log.debug(self, "Setting apt_packages variable for Nginx ,PHP"
" ,MySQL ") " ,MySQL ")
self.app.pargs.nginx = True self.app.pargs.nginx = True
self.app.pargs.php = True self.app.pargs.php = True
@ -914,111 +915,115 @@ class EEStackController(CementBaseController):
self.app.pargs.postfix = True self.app.pargs.postfix = True
if not EEAptGet.is_installed('dovecot-core'): if not EEAptGet.is_installed('dovecot-core'):
self.app.log.debug("Setting apt_packages variable for mail") Log.debug(self, "Setting apt_packages variable for mail")
apt_packages = apt_packages + EEVariables.ee_mail apt_packages = apt_packages + EEVariables.ee_mail
packages = packages + [["https://github.com/opensolutions/" packages = packages + [["https://github.com/opensolutions/"
"ViMbAdmin/archive/3.0.10.tar.gz", "ViMbAdmin/archive/3.0.10.tar.gz",
"/tmp/vimbadmin.tar.gz"], "/tmp/vimbadmin.tar.gz", "ViMbAdmin"],
["https://github.com/roundcube/" ["https://github.com/roundcube/"
"roundcubemail/releases/download/" "roundcubemail/releases/download/"
"1.0.4/roundcubemail-1.0.4.tar.gz", "1.0.4/roundcubemail-1.0.4.tar.gz",
"/tmp/roundcube.tar.gz"]] "/tmp/roundcube.tar.gz",
"roundcubemail"]]
if EEVariables.ee_ram > 1024: if EEVariables.ee_ram > 1024:
apt_packages = apt_packages + EEVariables.ee_mailscanner apt_packages = apt_packages + EEVariables.ee_mailscanner
else: else:
self.app.log.info("Mail server is allready installed") Log.info(self, "Mail server is allready installed")
if self.app.pargs.nginx: if self.app.pargs.nginx:
self.app.log.debug("Setting apt_packages variable for Nginx") Log.debug(self, "Setting apt_packages variable for Nginx")
if not EEAptGet.is_installed('nginx-common'): if not EEAptGet.is_installed('nginx-common'):
apt_packages = apt_packages + EEVariables.ee_nginx apt_packages = apt_packages + EEVariables.ee_nginx
else: else:
self.app.log.info("Nginx allready installed") Log.info(self, "Nginx allready installed")
if self.app.pargs.php: if self.app.pargs.php:
self.app.log.debug("Setting apt_packages variable for PHP") Log.debug(self, "Setting apt_packages variable for PHP")
if not EEAptGet.is_installed('php5-common'): if not EEAptGet.is_installed('php5-common'):
apt_packages = apt_packages + EEVariables.ee_php apt_packages = apt_packages + EEVariables.ee_php
else: else:
self.app.log.info("PHP allready installed") Log.info(self, "PHP allready installed")
if self.app.pargs.mysql: if self.app.pargs.mysql:
self.app.log.debug("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"):
apt_packages = apt_packages + EEVariables.ee_mysql apt_packages = apt_packages + EEVariables.ee_mysql
else: else:
self.app.log.info("MySQL connection is allready alive") Log.info(self, "MySQL connection is allready alive")
if self.app.pargs.postfix: if self.app.pargs.postfix:
self.app.log.debug("Setting apt_packages variable for PostFix") Log.debug(self, "Setting apt_packages variable for PostFix")
if not EEAptGet.is_installed('postfix'): if not EEAptGet.is_installed('postfix'):
apt_packages = apt_packages + EEVariables.ee_postfix apt_packages = apt_packages + EEVariables.ee_postfix
else: else:
self.app.log.info("Postfix is allready installed") Log.info(self, "Postfix is allready installed")
if self.app.pargs.wpcli: if self.app.pargs.wpcli:
self.app.log.debug("Setting packages variable for WPCLI") Log.debug(self, "Setting packages variable for WPCLI")
if not EEShellExec.cmd_exec(self, "which wp"): if not EEShellExec.cmd_exec(self, "which wp"):
packages = packages + [["https://github.com/wp-cli/wp-cli/" packages = packages + [["https://github.com/wp-cli/wp-cli/"
"releases/download/v0.17.1/" "releases/download/v0.17.1/"
"wp-cli.phar", "/usr/bin/wp"]] "wp-cli.phar", "/usr/bin/wp",
"wp-cli"]]
else: else:
self.app.log.info("WP-CLI is allready installed") Log.info(self, "WP-CLI is allready installed")
if self.app.pargs.phpmyadmin: if self.app.pargs.phpmyadmin:
self.app.log.debug("Setting packages varible for phpMyAdmin ") Log.debug(self, "Setting packages varible for phpMyAdmin ")
packages = packages + [["https://github.com/phpmyadmin/phpmyadmin" packages = packages + [["https://github.com/phpmyadmin/phpmyadmin"
"/archive/STABLE.tar.gz", "/archive/STABLE.tar.gz",
"/tmp/pma.tar.gz"]] "/tmp/pma.tar.gz", "phpMyAdmin"]]
if self.app.pargs.adminer: if self.app.pargs.adminer:
self.app.log.debug("Setting packages variable for Adminer ") Log.debug(self, "Setting packages variable for Adminer ")
packages = packages + [["http://downloads.sourceforge.net/adminer" packages = packages + [["http://downloads.sourceforge.net/adminer"
"/adminer-4.1.0.php", "/var/www/22222/" "/adminer-4.1.0.php", "/var/www/22222/"
"htdocs/db/adminer/index.php"]] "htdocs/db/adminer/index.php", "adminer"]]
if self.app.pargs.utils: if self.app.pargs.utils:
self.app.log.debug("Setting packages variable for utils") Log.debug(self, "Setting packages variable for utils")
packages = packages + [["http://phpmemcacheadmin.googlecode.com/" packages = packages + [["http://phpmemcacheadmin.googlecode.com/"
"files/phpMemcachedAdmin-1.2.2" "files/phpMemcachedAdmin-1.2.2"
"-r262.tar.gz", '/tmp/memcache.tar.gz'], "-r262.tar.gz", '/tmp/memcache.tar.gz',
'phpMemcachedAdmin'],
["https://raw.githubusercontent.com/rtCamp/" ["https://raw.githubusercontent.com/rtCamp/"
"eeadmin/master/cache/nginx/clean.php", "eeadmin/master/cache/nginx/clean.php",
"/var/www/22222/htdocs/cache/" "/var/www/22222/htdocs/cache/"
"nginx/clean.php"], "nginx/clean.php", "clean.php"],
["https://raw.github.com/rlerdorf/opcache-" ["https://raw.github.com/rlerdorf/opcache-"
"status/master/opcache.php", "status/master/opcache.php",
"/var/www/22222/htdocs/cache/" "/var/www/22222/htdocs/cache/"
"opcache/opcache.php"], "opcache/opcache.php", "opcache.php"],
["https://raw.github.com/amnuts/opcache-gui" ["https://raw.github.com/amnuts/opcache-gui"
"/master/index.php", "/master/index.php",
"/var/www/22222/htdocs/" "/var/www/22222/htdocs/"
"cache/opcache/opgui.php"], "cache/opcache/opgui.php", "index.php"],
["https://gist.github.com/ck-on/4959032/raw" ["https://gist.github.com/ck-on/4959032/raw"
"/0b871b345fd6cfcd6d2be030c1f33d1ad6a475cb" "/0b871b345fd6cfcd6d2be030c1f33d1ad6a475cb"
"/ocp.php", "/ocp.php",
"/var/www/22222/htdocs/cache/" "/var/www/22222/htdocs/cache/"
"opcache/ocp.php"], "opcache/ocp.php", "ocp.php"],
["https://github.com/jokkedk/webgrind/" ["https://github.com/jokkedk/webgrind/"
"archive/master.tar.gz", "archive/master.tar.gz",
'/tmp/webgrind.tar.gz'], '/tmp/webgrind.tar.gz', 'webgrind.tar.gz'],
["http://bazaar.launchpad.net/~percona-too" ["http://bazaar.launchpad.net/~percona-too"
"lkit-dev/percona-toolkit/2.1/download/he" "lkit-dev/percona-toolkit/2.1/download/he"
"ad:/ptquerydigest-20110624220137-or26tn4" "ad:/ptquerydigest-20110624220137-or26tn4"
"expb9ul2a-16/pt-query-digest", "expb9ul2a-16/pt-query-digest",
"/usr/bin/pt-query-advisor"], "/usr/bin/pt-query-advisor",
"pt-query-digest"],
["https://github.com/box/Anemometer/archive" ["https://github.com/box/Anemometer/archive"
"/master.tar.gz", "/master.tar.gz",
'/tmp/anemometer.tar.gz'] '/tmp/anemometer.tar.gz', 'Anemometer']
] ]
self.app.log.debug("Calling pre_pref ") Log.debug(self, "Calling pre_pref ")
self.pre_pref(apt_packages) self.pre_pref(apt_packages)
if len(apt_packages): if len(apt_packages):
EESwap.add(self) EESwap.add(self)
self.app.log.debug("Updating apt-cache") Log.debug(self, "Updating apt-cache")
EEAptGet.update() EEAptGet.update()
self.app.log.debug("Installing all apt_packages") Log.debug(self, "Installing all apt_packages")
EEAptGet.install(apt_packages) EEAptGet.install(apt_packages)
if len(packages): if len(packages):
self.app.log.debug("Downloading all packages") Log.debug(self, "Downloading all packages")
EEDownload.download(self, packages) EEDownload.download(self, packages)
self.app.log.debug("Calling post_pref") Log.debug(self, "Calling post_pref")
self.post_pref(apt_packages, packages) self.post_pref(apt_packages, packages)
@expose() @expose()
@ -1039,7 +1044,7 @@ class EEStackController(CementBaseController):
self.app.pargs.utils = True self.app.pargs.utils = True
if self.app.pargs.mail: if self.app.pargs.mail:
self.app.log.debug("Removing mail server packages") Log.debug(self, "Removing mail server packages")
apt_packages = apt_packages + EEVariables.ee_mail apt_packages = apt_packages + EEVariables.ee_mail
apt_packages = apt_packages + EEVariables.ee_mailscanner apt_packages = apt_packages + EEVariables.ee_mailscanner
packages = packages + ["/var/www/22222/htdocs/vimbadmin", packages = packages + ["/var/www/22222/htdocs/vimbadmin",
@ -1049,28 +1054,28 @@ class EEStackController(CementBaseController):
EEMysql.execute(self, "drop database IF EXISTS roundcubemail") EEMysql.execute(self, "drop database IF EXISTS roundcubemail")
if self.app.pargs.nginx: if self.app.pargs.nginx:
self.app.log.debug("Removing apt_packages variable of Nginx") Log.debug(self, "Removing apt_packages variable of Nginx")
apt_packages = apt_packages + EEVariables.ee_nginx apt_packages = apt_packages + EEVariables.ee_nginx
if self.app.pargs.php: if self.app.pargs.php:
self.app.log.debug("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.mysql: if self.app.pargs.mysql:
self.app.log.debug("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
if self.app.pargs.postfix: if self.app.pargs.postfix:
self.app.log.debug("Removing apt_packages variable of Postfix") Log.debug(self, "Removing apt_packages variable of Postfix")
apt_packages = apt_packages + EEVariables.ee_postfix apt_packages = apt_packages + EEVariables.ee_postfix
if self.app.pargs.wpcli: if self.app.pargs.wpcli:
self.app.log.debug("Removing package variable of WPCLI ") Log.debug(self, "Removing package variable of WPCLI ")
packages = packages + ['/usr/bin/wp'] packages = packages + ['/usr/bin/wp']
if self.app.pargs.phpmyadmin: if self.app.pargs.phpmyadmin:
self.app.log.debug("Removing package variable of phpMyAdmin ") Log.debug(self, "Removing package variable of phpMyAdmin ")
packages = packages + ['/var/www/22222/htdocs/db/pma'] packages = packages + ['/var/www/22222/htdocs/db/pma']
if self.app.pargs.adminer: if self.app.pargs.adminer:
self.app.log.debug("Removing package variable of Adminer ") Log.debug(self, "Removing package variable of Adminer ")
packages = packages + ['/var/www/22222/htdocs/db/adminer'] packages = packages + ['/var/www/22222/htdocs/db/adminer']
if self.app.pargs.utils: if self.app.pargs.utils:
self.app.log.debug("Removing package variable of utils ") Log.debug(self, "Removing package variable of utils ")
packages = packages + ['/var/www/22222/htdocs/php/webgrind/', packages = packages + ['/var/www/22222/htdocs/php/webgrind/',
'/var/www/22222/htdocs/cache/opcache', '/var/www/22222/htdocs/cache/opcache',
'/var/www/22222/htdocs/cache/nginx/' '/var/www/22222/htdocs/cache/nginx/'
@ -1080,7 +1085,7 @@ class EEStackController(CementBaseController):
'/var/www/22222/htdocs/db/anemometer'] '/var/www/22222/htdocs/db/anemometer']
if len(apt_packages): if len(apt_packages):
self.app.log.debug("Removing apt_packages") Log.debug(self, "Removing apt_packages")
EEAptGet.remove(apt_packages) EEAptGet.remove(apt_packages)
if len(packages): if len(packages):
EEFileUtils.remove(self, packages) EEFileUtils.remove(self, packages)
@ -1103,7 +1108,7 @@ class EEStackController(CementBaseController):
self.app.pargs.utils = True self.app.pargs.utils = True
if self.app.pargs.mail: if self.app.pargs.mail:
self.app.log.debug("Removing mail server packages") Log.debug(self, "Removing mail server packages")
apt_packages = apt_packages + EEVariables.ee_mail apt_packages = apt_packages + EEVariables.ee_mail
apt_packages = apt_packages + EEVariables.ee_mailscanner apt_packages = apt_packages + EEVariables.ee_mailscanner
packages = packages + ["/var/www/22222/htdocs/vimbadmin", packages = packages + ["/var/www/22222/htdocs/vimbadmin",
@ -1113,28 +1118,28 @@ class EEStackController(CementBaseController):
EEMysql.execute(self, "drop database IF EXISTS roundcubemail") EEMysql.execute(self, "drop database IF EXISTS roundcubemail")
if self.app.pargs.nginx: if self.app.pargs.nginx:
self.app.log.debug("Purge apt_packages variable of Nginx") Log.debug(self, "Purge apt_packages variable of Nginx")
apt_packages = apt_packages + EEVariables.ee_nginx apt_packages = apt_packages + EEVariables.ee_nginx
if self.app.pargs.php: if self.app.pargs.php:
self.app.log.debug("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.mysql: if self.app.pargs.mysql:
self.app.log.debug("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
if self.app.pargs.postfix: if self.app.pargs.postfix:
self.app.log.debug("Purge apt_packages variable PostFix") Log.debug(self, "Purge apt_packages variable PostFix")
apt_packages = apt_packages + EEVariables.ee_postfix apt_packages = apt_packages + EEVariables.ee_postfix
if self.app.pargs.wpcli: if self.app.pargs.wpcli:
self.app.log.debug("Purge package variable WPCLI") Log.debug(self, "Purge package variable WPCLI")
packages = packages + ['/usr/bin/wp'] packages = packages + ['/usr/bin/wp']
if self.app.pargs.phpmyadmin: if self.app.pargs.phpmyadmin:
packages = packages + ['/var/www/22222/htdocs/db/pma'] packages = packages + ['/var/www/22222/htdocs/db/pma']
self.app.log.debug("Purge package variable phpMyAdmin") Log.debug(self, "Purge package variable phpMyAdmin")
if self.app.pargs.adminer: if self.app.pargs.adminer:
self.app.log.debug("Purge package variable Adminer") Log.debug(self, "Purge package variable Adminer")
packages = packages + ['/var/www/22222/htdocs/db/adminer'] packages = packages + ['/var/www/22222/htdocs/db/adminer']
if self.app.pargs.utils: if self.app.pargs.utils:
self.app.log.debug("Purge package variable utils") Log.debug(self, "Purge package variable utils")
packages = packages + ['/var/www/22222/htdocs/php/webgrind/', packages = packages + ['/var/www/22222/htdocs/php/webgrind/',
'/var/www/22222/htdocs/cache/opcache', '/var/www/22222/htdocs/cache/opcache',
'/var/www/22222/htdocs/cache/nginx/' '/var/www/22222/htdocs/cache/nginx/'

59
ee/cli/plugins/stack_services.py

@ -1,6 +1,7 @@
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.services import EEService from ee.core.services import EEService
from ee.core.logging import Log
class EEStackStatusController(CementBaseController): class EEStackStatusController(CementBaseController):
@ -20,25 +21,25 @@ class EEStackStatusController(CementBaseController):
def start(self): def start(self):
services = [] services = []
if self.app.pargs.nginx: if self.app.pargs.nginx:
self.app.log.debug("nginx service start") Log.debug(self, "nginx service start")
services = services + ['nginx'] services = services + ['nginx']
elif self.app.pargs.php: elif self.app.pargs.php:
self.app.log.debug("php5-fpm service start") Log.debug(self, "php5-fpm service start")
services = services + ['php5-fpm'] services = services + ['php5-fpm']
elif self.app.pargs.mysql: elif self.app.pargs.mysql:
self.app.log.debug("mysql service start") Log.debug(self, "mysql service start")
services = services + ['mysql'] services = services + ['mysql']
elif self.app.pargs.postfix: elif self.app.pargs.postfix:
self.app.log.debug("postfix service start") Log.debug(self, "postfix service start")
services = services + ['postfix'] services = services + ['postfix']
elif self.app.pargs.memcache: elif self.app.pargs.memcache:
self.app.log.debug("memcached service start") Log.debug(self, "memcached service start")
services = services + ['memcached'] services = services + ['memcached']
elif self.app.pargs.dovecot: elif self.app.pargs.dovecot:
self.app.log.debug("dovecot service start") Log.debug(self, "dovecot service start")
services = services + ['dovecot'] services = services + ['dovecot']
else: else:
self.app.log.debug("nginx,php5-fpm,mysql,postfix services start") Log.debug(self, "nginx,php5-fpm,mysql,postfix services start")
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
for service in services: for service in services:
EEService.start_service(self, service) EEService.start_service(self, service)
@ -47,26 +48,26 @@ class EEStackStatusController(CementBaseController):
def stop(self): def stop(self):
services = [] services = []
if self.app.pargs.nginx: if self.app.pargs.nginx:
self.app.log.debug("nginx service stop") Log.debug(self, "nginx service stop")
services = services + ['nginx'] services = services + ['nginx']
elif self.app.pargs.php: elif self.app.pargs.php:
self.app.log.debug("php5-fpm service stop") Log.debug(self, "php5-fpm service stop")
services = services + ['php5-fpm'] services = services + ['php5-fpm']
elif self.app.pargs.mysql: elif self.app.pargs.mysql:
self.app.log.debug("mysql service stop") Log.debug(self, "mysql service stop")
services = services + ['mysql'] services = services + ['mysql']
elif self.app.pargs.postfix: elif self.app.pargs.postfix:
self.app.log.debug("postfix service stop") Log.debug(self, "postfix service stop")
services = services + ['postfix'] services = services + ['postfix']
elif self.app.pargs.memcache: elif self.app.pargs.memcache:
self.app.log.debug("memcached service stop") Log.debug(self, "memcached service stop")
services = services + ['memcached'] services = services + ['memcached']
elif self.app.pargs.dovecot: elif self.app.pargs.dovecot:
self.app.log.debug("dovecot service stop") Log.debug(self, "dovecot service stop")
services = services + ['dovecot'] services = services + ['dovecot']
else: else:
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
self.app.log.debug("nginx,php5-fpm,mysql,postfix services stop") Log.debug(self, "nginx,php5-fpm,mysql,postfix services stop")
for service in services: for service in services:
EEService.stop_service(self, service) EEService.stop_service(self, service)
@ -74,53 +75,53 @@ class EEStackStatusController(CementBaseController):
def restart(self): def restart(self):
services = [] services = []
if self.app.pargs.nginx: if self.app.pargs.nginx:
self.app.log.debug("nginx service restart") Log.debug(self, "nginx service restart")
services = services + ['nginx'] services = services + ['nginx']
elif self.app.pargs.php: elif self.app.pargs.php:
self.app.log.debug("php5-fpm service restart") Log.debug(self, "php5-fpm service restart")
services = services + ['php5-fpm'] services = services + ['php5-fpm']
elif self.app.pargs.mysql: elif self.app.pargs.mysql:
self.app.log.debug("mysql service restart") Log.debug(self, "mysql service restart")
services = services + ['mysql'] services = services + ['mysql']
elif self.app.pargs.postfix: elif self.app.pargs.postfix:
self.app.log.debug("postfix service restart") Log.debug(self, "postfix service restart")
services = services + ['postfix'] services = services + ['postfix']
elif self.app.pargs.memcache: elif self.app.pargs.memcache:
self.app.log.debug("memcached service restart") Log.debug(self, "memcached service restart")
services = services + ['memcached'] services = services + ['memcached']
elif self.app.pargs.dovecot: elif self.app.pargs.dovecot:
self.app.log.debug("dovecot service restart") Log.debug(self, "dovecot service restart")
services = services + ['dovecot'] services = services + ['dovecot']
else: else:
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
for service in services: for service in services:
self.app.log.debug("nginx,php5-fpm,mysql,postfix services restart") Log.debug(self, "nginx,php5-fpm,mysql,postfix services restart")
EEService.restart_service(self, service) EEService.restart_service(self, service)
@expose(help="get stack status") @expose(help="get stack status")
def status(self): def status(self):
services = [] services = []
if self.app.pargs.nginx: if self.app.pargs.nginx:
self.app.log.debug("nginx service status") Log.debug(self, "nginx service status")
services = services + ['nginx'] services = services + ['nginx']
elif self.app.pargs.php: elif self.app.pargs.php:
self.app.log.debug("php5-fpm service status") Log.debug(self, "php5-fpm service status")
services = services + ['php5-fpm'] services = services + ['php5-fpm']
elif self.app.pargs.mysql: elif self.app.pargs.mysql:
self.app.log.debug("mysql service status") Log.debug(self, "mysql service status")
services = services + ['mysql'] services = services + ['mysql']
elif self.app.pargs.postfix: elif self.app.pargs.postfix:
services = services + ['postfix'] services = services + ['postfix']
self.app.log.debug("postfix service status") Log.debug(self, "postfix service status")
elif self.app.pargs.memcache: elif self.app.pargs.memcache:
self.app.log.debug("memcached service status") Log.debug(self, "memcached service status")
services = services + ['memcached'] services = services + ['memcached']
elif self.app.pargs.dovecot: elif self.app.pargs.dovecot:
self.app.log.debug("dovecot service status") Log.debug(self, "dovecot service status")
services = services + ['dovecot'] services = services + ['dovecot']
else: else:
self.app.log.debug("nginx,php5-fpm,mysql,postfix services status") Log.debug(self, "nginx,php5-fpm,mysql,postfix services status")
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
for service in services: for service in services:
if EEService.get_service_status(self, service): if EEService.get_service_status(self, service):
print("{0}: Running".format(service)) Log.info(self, "{0}: Running".format(service))

1
ee/core/aptget.py

@ -261,4 +261,3 @@ class EEAptGet():
except Exception as e: except Exception as e:
cache.close() cache.close()
return False return False

11
ee/core/download.py

@ -2,6 +2,7 @@
import urllib.request import urllib.request
import urllib.error import urllib.error
import os import os
from ee.core.logging import Log
class EEDownload(): class EEDownload():
@ -13,23 +14,23 @@ class EEDownload():
for package in packages: for package in packages:
url = package[0] url = package[0]
filename = package[1] filename = package[1]
pkg_name = package[2]
try: try:
directory = os.path.dirname(filename) directory = os.path.dirname(filename)
if not os.path.exists(directory): if not os.path.exists(directory):
os.makedirs(directory) os.makedirs(directory)
self.app.log.info("Downloading "+os.path.basename(url)+" ...") Log.info(self, "Downloading "+pkg_name+" ...")
urllib.request.urlretrieve(url, filename) urllib.request.urlretrieve(url, filename)
self.app.log.info("Done")
except urllib.error.URLError as e: except urllib.error.URLError as e:
self.app.log.info("Unable to donwload file, [{err}]" Log.info(self, "Unable to donwload file, [{err}]"
.format(err=str(e.reason))) .format(err=str(e.reason)))
return False return False
except urllib.error.HTTPError as e: except urllib.error.HTTPError as e:
self.app.log.error("Package download failed. [{err}]" Log.error(self, "Package download failed. [{err}]"
.format(err=str(e.reason))) .format(err=str(e.reason)))
return False return False
except urllib.error.ContentTooShortError as e: except urllib.error.ContentTooShortError as e:
self.app.log.error("Package download failed. The amount of the" Log.error(self, "Package download failed. The amount of the"
" downloaded data is less than " " downloaded data is less than "
"the expected amount \{0} {1}" "the expected amount \{0} {1}"
.format(e.errno, e.strerror)) .format(e.errno, e.strerror))

3
ee/core/extract.py

@ -1,6 +1,7 @@
"""EasyEngine extarct core classes.""" """EasyEngine extarct core classes."""
import tarfile import tarfile
import os import os
from ee.core.logging import Log
class EEExtract(): class EEExtract():
@ -14,6 +15,6 @@ class EEExtract():
os.remove(file) os.remove(file)
return True return True
except tarfile.TarError as e: except tarfile.TarError as e:
self.app.log.error('Unable to extract file \{0} {1}' Log.error(self, 'Unable to extract file \{0} {1}'
.format(e.errno, e.strerror)) .format(e.errno, e.strerror))
return False return False

20
ee/core/fileutils.py

@ -16,15 +16,13 @@ class EEFileUtils():
def remove(self, filelist): def remove(self, filelist):
for file in filelist: for file in filelist:
if os.path.isfile(file): if os.path.isfile(file):
self.app.log.info("Removing "+os.path.basename(file)+" ...") Log.info(self, "Removing "+os.path.basename(file)+" ...")
os.remove(file) os.remove(file)
self.app.log.debug('file Removed') Log.debug(self, 'file Removed')
self.app.log.info("Done")
if os.path.isdir(file): if os.path.isdir(file):
try: try:
print("Removing "+os.path.basename(file)+"...") Log.info(self, "Removing "+os.path.basename(file)+"...")
shutil.rmtree(file) shutil.rmtree(file)
self.app.log.info("Done")
except shutil.Error as e: except shutil.Error as e:
Log.error(self, 'Unable to Remove file {err}' Log.error(self, 'Unable to Remove file {err}'
.format(err=str(e.reason))) .format(err=str(e.reason)))
@ -37,11 +35,11 @@ class EEFileUtils():
try: try:
os.symlink(src, dst) os.symlink(src, dst)
except Exception as e: except Exception as e:
self.app.log.error("Unable to create symbolic link ...\n {0}" Log.error(self, "Unable to create symbolic link ...\n {0}"
" {1}".format(e.errno, e.strerror)) " {1}".format(e.errno, e.strerror))
sys.exit(1) sys.exit(1)
else: else:
self.app.log.debug("Destination: {0} exists".format(dst)) Log.debug(self, "Destination: {0} exists".format(dst))
def remove_symlink(self, filepath): def remove_symlink(self, filepath):
try: try:
@ -55,17 +53,17 @@ class EEFileUtils():
try: try:
shutil.copy2(src, dest) shutil.copy2(src, dest)
except shutil.Error as e: except shutil.Error as e:
print('Error: {0}'.format(e)) Log.info(self, 'Error: {0}'.format(e))
except IOError as e: except IOError as e:
print('Error: {e}'.format(e.strerror)) Log.info(self, 'Error: {e}'.format(e.strerror))
def searchreplace(self, fnm, sstr, rstr): def searchreplace(self, fnm, sstr, rstr):
try: try:
for line in fileinput.input(fnm, inplace=True): for line in fileinput.input(fnm, inplace=True):
print(line.replace(sstr, rstr), end='') Log.info(line.replace(sstr, rstr), end='')
fileinput.close() fileinput.close()
except Exception as e: except Exception as e:
print('Error : {0}'.format(e)) Log.info(self, 'Error : {0}'.format(e))
def mvfile(self, src, dst): def mvfile(self, src, dst):
try: try:

11
ee/core/git.py

@ -1,5 +1,6 @@
from sh import git, ErrorReturnCode from sh import git, ErrorReturnCode
import os import os
from ee.core.logging import Log
class EEGit: class EEGit:
@ -16,24 +17,24 @@ class EEGit:
if os.path.isdir(path): if os.path.isdir(path):
if not os.path.isdir(path+"/.git"): if not os.path.isdir(path+"/.git"):
try: try:
self.app.log.debug("EEGit: git init at {0}" Log.debug(self, "EEGit: git init at {0}"
.format(path)) .format(path))
git.init(path) git.init(path)
except ErrorReturnCode as e: except ErrorReturnCode as e:
self.app.log.error(e) Log.error(e)
sys.exit(1) sys.exit(1)
status = git.status("-s") status = git.status("-s")
if len(status.splitlines()) > 0: if len(status.splitlines()) > 0:
try: try:
self.app.log.debug("EEGit: git commit at {0}" Log.debug(self, "EEGit: git commit at {0}"
.format(path)) .format(path))
git.add("--all") git.add("--all")
git.commit("-am {0}".format(msg)) git.commit("-am {0}".format(msg))
except ErrorReturnCode as e: except ErrorReturnCode as e:
self.app.log.error(e) Log.error(e)
sys.exit(1) sys.exit(1)
else: else:
self.app.log.debug("EEGit: Path {0} not present".format(path)) Log.debug(self, "EEGit: Path {0} not present".format(path))
def checkfilestatus(self, repo, filepath): def checkfilestatus(self, repo, filepath):
global git global git

5
ee/core/mysql.py

@ -3,6 +3,7 @@ import pymysql
import configparser import configparser
from os.path import expanduser from os.path import expanduser
import sys import sys
from ee.core.logging import Log
class EEMysql(): class EEMysql():
@ -29,14 +30,14 @@ 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}' Log.error(self, 'Unable to connect to database: {0}'
.format(e)) .format(e))
sys.exit(1) sys.exit(1)
try: try:
cur.execute(statement) cur.execute(statement)
except Exception as e: except Exception as e:
self.app.log.error('Error occured while executing: {0}' Log.error(self, 'Error occured while executing: {0}'
.format(e)) .format(e))
cur.close() cur.close()
conn.close() conn.close()

22
ee/core/services.py

@ -3,6 +3,7 @@ import os
import sys import sys
import subprocess import subprocess
from subprocess import Popen from subprocess import Popen
from ee.core.logging import Log
class EEService(): class EEService():
@ -16,11 +17,11 @@ class EEService():
retcode = subprocess.getstatusoutput('service {0} start' retcode = subprocess.getstatusoutput('service {0} start'
.format(service_name)) .format(service_name))
if retcode[0] == 0: if retcode[0] == 0:
self.app.log.info("Started : {0}".format(service_name)) Log.info(self, "Started : {0}".format(service_name))
else: else:
self.app.log.error(retcode[1]) Log.error(self, retcode[1])
except OSError as e: except OSError as e:
self.app.log.error("Failed to start service {0} {1}" Log.error(self, "Failed to start service {0} {1}"
.format(e.errno, e.strerror)) .format(e.errno, e.strerror))
return False return False
@ -29,12 +30,12 @@ class EEService():
retcode = subprocess.getstatusoutput('service {0} stop' retcode = subprocess.getstatusoutput('service {0} stop'
.format(service_name)) .format(service_name))
if retcode[0] == 0: if retcode[0] == 0:
self.app.log.info("Stopped : {0}".format(service_name)) Log.info(self, "Stopped : {0}".format(service_name))
return True return True
else: else:
return False return False
except OSError as e: except OSError as e:
self.app.log.error("Failed to stop service : {0}{1}" Log.error(self, "Failed to stop service : {0}{1}"
.format(e.errno, e.strerror)) .format(e.errno, e.strerror))
return False return False
@ -43,7 +44,7 @@ class EEService():
EEService.stop_service(self, service_name) EEService.stop_service(self, service_name)
EEService.start_service(self, service_name) EEService.start_service(self, service_name)
except OSError as e: except OSError as e:
self.app.log.error("Failed to restart services \{0} {1}" Log.error(self, "Failed to restart services \{0} {1}"
.format(e.errno, e.strerror)) .format(e.errno, e.strerror))
def reload_service(self, service_name): def reload_service(self, service_name):
@ -67,14 +68,15 @@ class EEService():
retcode = subprocess.getstatusoutput('service {0} reload' retcode = subprocess.getstatusoutput('service {0} reload'
.format(service_name)) .format(service_name))
if retcode[0] == 0: if retcode[0] == 0:
self.app.log.info("reload : {0}".format(service_name)) Log.info(self, "reload : {0}".format(service_name))
return True return True
else: else:
return False return False
except OSError as e: except OSError as e:
self.app.log.error("Failed to reload {0} {1}"
Log.error(self, "Failed to reload {0} {1}"
.format(service_name, e)) .format(service_name, e))
return False sys.exit(1)
def get_service_status(self, service_name): def get_service_status(self, service_name):
try: try:
@ -90,6 +92,6 @@ class EEService():
else: else:
return False return False
except OSError as e: except OSError as e:
self.app.log.error("Unable to get services status \ {0}{1}" Log.error(self, "Unable to get services status \ {0}{1}"
.format(e.errno, e.strerror)) .format(e.errno, e.strerror))
return False return False

4
ee/core/shellexec.py

@ -13,12 +13,12 @@ class EEShellExec():
def cmd_exec(self, command, errormsg=''): def cmd_exec(self, command, errormsg=''):
try: try:
self.app.log.debug("Running command: {0}".format(command)) Log.debug(self, "Running command: {0}".format(command))
retcode = subprocess.getstatusoutput(command) retcode = subprocess.getstatusoutput(command)
if retcode[0] == 0: if retcode[0] == 0:
return True return True
else: else:
self.app.log.debug(retcode[1]) Log.debug(self, retcode[1])
return False return False
except OSError as e: except OSError as e:
if errormsg: if errormsg:

Loading…
Cancel
Save