From c2ed387ed6a5b7ec046cb39f89119d2b9f573a29 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Thu, 15 Jan 2015 16:54:51 +0530 Subject: [PATCH 1/9] ee info command done --- config/plugins.d/info.conf | 11 ++ ee/cli/bootstrap.py | 2 - ee/cli/controllers/info.py | 26 ---- ee/cli/plugins/info.py | 197 +++++++++++++++++++++++++++ ee/cli/plugins/stack.py | 8 ++ ee/cli/templates/info_mysql.mustache | 9 ++ ee/cli/templates/info_nginx.mustache | 10 ++ ee/cli/templates/info_php.mustache | 35 +++++ 8 files changed, 270 insertions(+), 28 deletions(-) create mode 100644 config/plugins.d/info.conf delete mode 100644 ee/cli/controllers/info.py create mode 100644 ee/cli/plugins/info.py create mode 100644 ee/cli/templates/info_mysql.mustache create mode 100644 ee/cli/templates/info_nginx.mustache create mode 100644 ee/cli/templates/info_php.mustache diff --git a/config/plugins.d/info.conf b/config/plugins.d/info.conf new file mode 100644 index 00000000..59f51a03 --- /dev/null +++ b/config/plugins.d/info.conf @@ -0,0 +1,11 @@ +### Example Plugin Configuration for EasyEngine + +[info] + +### If enabled, load a plugin named `example` either from the Python module +### `ee.cli.plugins.example` or from the file path +### `/var/lib/ee/plugins/example.py` +enable_plugin = true + +### Additional plugin configuration settings +foo = bar diff --git a/ee/cli/bootstrap.py b/ee/cli/bootstrap.py index 48b62d3b..a14aacd2 100644 --- a/ee/cli/bootstrap.py +++ b/ee/cli/bootstrap.py @@ -6,10 +6,8 @@ from cement.core import handler from ee.cli.controllers.base import EEBaseController from ee.cli.controllers.isl import EEImportslowlogController -from ee.cli.controllers.info import EEInfoController def load(app): handler.register(EEBaseController) - handler.register(EEInfoController) handler.register(EEImportslowlogController) diff --git a/ee/cli/controllers/info.py b/ee/cli/controllers/info.py deleted file mode 100644 index 70e56ae3..00000000 --- a/ee/cli/controllers/info.py +++ /dev/null @@ -1,26 +0,0 @@ -from cement.core.controller import CementBaseController, expose - - -class EEInfoController(CementBaseController): - class Meta: - label = 'info' - stacked_on = 'base' - stacked_type = 'nested' - description = 'info command used for debugging issued with stack or \ - site specific configuration' - arguments = [ - (['--mysql'], - dict(help='get mysql configuration information', - action='store_true')), - (['--php'], - dict(help='get php configuration information', - action='store_true')), - (['--nginx'], - dict(help='get nginx configuration information', - action='store_true')), - ] - - @expose(hide=True) - def default(self): - # TODO Default action for ee debug command - print("Inside EEInfoController.default().") diff --git a/ee/cli/plugins/info.py b/ee/cli/plugins/info.py new file mode 100644 index 00000000..58a81ab5 --- /dev/null +++ b/ee/cli/plugins/info.py @@ -0,0 +1,197 @@ +"""EEInfo Plugin for EasyEngine.""" + +from cement.core.controller import CementBaseController, expose +from cement.core import handler, hook +from pynginxconfig import NginxConfig +from ee.core.aptget import EEAptGet +from ee.core.shellexec import EEShellExec +import os +import configparser + + +def info_plugin_hook(app): + # do something with the ``app`` object here. + pass + + +class EEInfoController(CementBaseController): + class Meta: + label = 'info' + stacked_on = 'base' + stacked_type = 'nested' + description = 'info command used for debugging issued with stack or \ + site specific configuration' + arguments = [ + (['--mysql'], + dict(help='get mysql configuration information', + action='store_true')), + (['--php'], + dict(help='get php configuration information', + action='store_true')), + (['--nginx'], + dict(help='get nginx configuration information', + action='store_true')), + ] + + @expose(hide=True) + def info_nginx(self): + version = os.popen("nginx -v 2>&1 | cut -d':' -f2 | cut -d' ' -f2 | " + "cut -d'/' -f2 | tr -d '\n'").read() + allow = os.popen("grep ^allow /etc/nginx/common/acl.conf | " + "cut -d' ' -f2 | cut -d';' -f1 | tr '\n' ' '").read() + nc = NginxConfig() + nc.loadf('/etc/nginx/nginx.conf') + user = nc.get('user')[1] + worker_processes = nc.get('worker_processes')[1] + worker_connections = nc.get([('events',), 'worker_connections'])[1] + keepalive_timeout = nc.get([('http',), 'keepalive_timeout'])[1] + if os.path.isfile('/etc/nginx/conf.d/ee-nginx.conf'): + nc.loadf('/etc/nginx/conf.d/ee-nginx.conf') + fastcgi_read_timeout = nc.get('fastcgi_read_timeout')[1] + client_max_body_size = nc.get('client_max_body_size')[1] + else: + fastcgi_read_timeout = nc.get([('http',), + 'fastcgi_read_timeout'])[1] + client_max_body_size = nc.get([('http',), + 'client_max_body_size'])[1] + data = dict(version=version, allow=allow, user=user, + worker_processes=worker_processes, + keepalive_timeout=keepalive_timeout, + worker_connections=worker_connections, + fastcgi_read_timeout=fastcgi_read_timeout, + client_max_body_size=client_max_body_size) + self.app.render((data), 'info_nginx.mustache') + + @expose(hide=True) + def info_php(self): + version = os.popen("php -v | head -n1 | cut -d' ' -f2 |" + " cut -d'+' -f1 | tr -d '\n'").read + config = configparser.ConfigParser() + config.read('/etc/php5/fpm/php.ini') + expose_php = config['PHP']['expose_php'] + memory_limit = config['PHP']['memory_limit'] + post_max_size = config['PHP']['post_max_size'] + upload_max_filesize = config['PHP']['upload_max_filesize'] + max_execution_time = config['PHP']['max_execution_time'] + + config.read('/etc/php5/fpm/pool.d/www.conf') + www_listen = config['www']['listen'] + www_ping_path = config['www']['ping.path'] + www_pm_status_path = config['www']['pm.status_path'] + www_pm = config['www']['pm'] + www_pm_max_requests = config['www']['pm.max_requests'] + www_pm_max_children = config['www']['pm.max_children'] + www_pm_start_servers = config['www']['pm.start_servers'] + www_pm_min_spare_servers = config['www']['pm.min_spare_servers'] + www_pm_max_spare_servers = config['www']['pm.max_spare_servers'] + www_request_terminate_time = (config['www'] + ['request_terminate_timeout']) + try: + www_xdebug = (config['www']['php_admin_flag[xdebug.profiler_enable' + '_trigger]']) + except Exception as e: + www_xdebug = 'off' + + config.read('/etc/php5/fpm/pool.d/debug.conf') + debug_listen = config['debug']['listen'] + debug_ping_path = config['debug']['ping.path'] + debug_pm_status_path = config['debug']['pm.status_path'] + debug_pm = config['debug']['pm'] + debug_pm_max_requests = config['debug']['pm.max_requests'] + debug_pm_max_children = config['debug']['pm.max_children'] + debug_pm_start_servers = config['debug']['pm.start_servers'] + debug_pm_min_spare_servers = config['debug']['pm.min_spare_servers'] + debug_pm_max_spare_servers = config['debug']['pm.max_spare_servers'] + debug_request_terminate = (config['debug'] + ['request_terminate_timeout']) + try: + debug_xdebug = (config['debug']['php_admin_flag[xdebug.profiler_' + 'enable_trigger]']) + except Exception as e: + debug_xdebug = 'off' + + data = dict(version=version, expose_php=expose_php, + memory_limit=memory_limit, post_max_size=post_max_size, + upload_max_filesize=upload_max_filesize, + max_execution_time=max_execution_time, + www_listen=www_listen, www_ping_path=www_ping_path, + www_pm_status_path=www_pm_status_path, www_pm=www_pm, + www_pm_max_requests=www_pm_max_requests, + www_pm_max_children=www_pm_max_children, + www_pm_start_servers=www_pm_start_servers, + www_pm_min_spare_servers=www_pm_min_spare_servers, + www_pm_max_spare_servers=www_pm_max_spare_servers, + www_request_terminate_timeout=www_request_terminate_time, + www_xdebug_profiler_enable_trigger=www_xdebug, + debug_listen=debug_listen, debug_ping_path=debug_ping_path, + debug_pm_status_path=debug_pm_status_path, + debug_pm=debug_pm, + debug_pm_max_requests=debug_pm_max_requests, + debug_pm_max_children=debug_pm_max_children, + debug_pm_start_servers=debug_pm_start_servers, + debug_pm_min_spare_servers=debug_pm_min_spare_servers, + debug_pm_max_spare_servers=debug_pm_max_spare_servers, + debug_request_terminate_timeout=debug_request_terminate, + debug_xdebug_profiler_enable_trigger=debug_xdebug) + self.app.render((data), 'info_php.mustache') + + @expose(hide=True) + def info_mysql(self): + version = os.popen("mysql -V | awk '{print($5)}' | cut -d ',' " + "-f1 | tr -d '\n'").read() + host = "localhost" + port = os.popen("mysql -e \"show variables\" | grep ^port | awk " + "'{print($2)}' | tr -d '\n'").read() + wait_timeout = os.popen("mysql -e \"show variables\" | grep " + "^wait_timeout | awk '{print($2)}' | " + "tr -d '\n'").read() + interactive_timeout = os.popen("mysql -e \"show variables\" | grep " + "^interactive_timeout | awk " + "'{print($2)}' | tr -d '\n'").read() + max_used_connections = os.popen("mysql -e \"show global status\" | " + "grep Max_used_connections | awk " + "'{print($2)}' | tr -d '\n'").read() + datadir = os.popen("mysql -e \"show variables\" | grep datadir | awk" + " '{print($2)}' | tr -d '\n'").read() + socket = os.popen("mysql -e \"show variables\" | grep \"^socket\" | " + "awk '{print($2)}' | tr -d '\n'").read() + data = dict(version=version, host=host, port=port, + wait_timeout=wait_timeout, + interactive_timeout=interactive_timeout, + max_used_connections=max_used_connections, + datadir=datadir, socket=socket) + self.app.render((data), 'info_mysql.mustache') + + @expose(hide=True) + def default(self): + if (not self.app.pargs.nginx and not self.app.pargs.php + and not self.app.pargs.mysql): + self.app.pargs.nginx = True + self.app.pargs.php = True + self.app.pargs.mysql = True + + if self.app.pargs.nginx: + if EEAptGet.is_installed('nginx-common'): + self.info_nginx() + else: + print("Nginx is not installed") + + if self.app.pargs.php: + if EEAptGet.is_installed('php5-fpm'): + self.info_php() + else: + print("PHP5 is installed") + + if self.app.pargs.mysql: + if EEShellExec.cmd_exec(self, "mysqladmin ping"): + self.info_mysql() + else: + print("MySQL is not installed") + + +def load(app): + # register the plugin class.. this only happens if the plugin is enabled + handler.register(EEInfoController) + + # register a hook (function) to run after arguments are parsed. + hook.register('post_argument_parsing', info_plugin_hook) diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index 1e9f1c5a..51d3ef3f 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -388,6 +388,14 @@ class EEStackController(CementBaseController): Log.debug(self, "writting PHP5 configartion into " " /etc/php5/fpm/pool.d/debug.conf") config.write(confifile) + + with open("/etc/php5/fpm/pool.d/debug.conf", "a") as myfile: + myfile.write("php_admin_value[xdebug.profiler_output_dir] " + "= /tmp/ \nphp_admin_value[xdebug.profiler_" + "output_name] = cachegrind.out.%p-%H-%R " + "\nphp_admin_flag[xdebug.profiler_enable" + "_trigger] = on \nphp_admin_flag[xdebug." + "profiler_enable] = off\n") EEGit.add(self, ["/etc/php5"], msg="Adding PHP into Git") EEService.reload_service(self, 'php5-fpm') diff --git a/ee/cli/templates/info_mysql.mustache b/ee/cli/templates/info_mysql.mustache new file mode 100644 index 00000000..29a5d81e --- /dev/null +++ b/ee/cli/templates/info_mysql.mustache @@ -0,0 +1,9 @@ + +MySQL ({{version}}) on {{host}}: + +port {{port}} +wait_timeout {{wait_timeout}} +interactive_timeout {{interactive_timeout}} +max_used_connections {{max_used_connections}} +datadir {{datadir}} +socket {{socket}} diff --git a/ee/cli/templates/info_nginx.mustache b/ee/cli/templates/info_nginx.mustache new file mode 100644 index 00000000..6420405b --- /dev/null +++ b/ee/cli/templates/info_nginx.mustache @@ -0,0 +1,10 @@ + +NGINX ({{version}}): + +user {{user}} +worker_processes {{worker_processes}} +worker_connections {{worker_connections}} +keepalive_timeout {{keepalive_timeout}} +fastcgi_read_timeout {{fastcgi_read_timeout}} +client_max_body_size {{client_max_body_size}} +allow {{allow}} diff --git a/ee/cli/templates/info_php.mustache b/ee/cli/templates/info_php.mustache new file mode 100644 index 00000000..1638cf8a --- /dev/null +++ b/ee/cli/templates/info_php.mustache @@ -0,0 +1,35 @@ + +PHP ({{version}}): + +user {{user}} +expose_php {{expose_php}} +memory_limit {{memory_limit}} +post_max_size {{post_max_size}} +upload_max_filesize {{upload_max_filesize}} +max_execution_time {{max_execution_time}} + +Information about www.conf +ping.path {{www_ping_path}} +pm.status_path {{www_pm_status_path}} +process_manager {{www_pm}} +pm.max_requests {{www_pm_max_requests}} +pm.max_children {{www_pm_max_children}} +pm.start_servers {{www_pm_start_servers}} +pm.min_spare_servers {{www_pm_min_spare_servers}} +pm.max_spare_servers {{www_pm_max_spare_servers}} +request_terminate_timeout {{www_request_terminate_timeout}} +xdebug.profiler_enable_trigger {{www_xdebug_profiler_enable_trigger}} +listen {{www_listen}} + +Information about debug.conf +ping.path {{debug_ping_path}} +pm.status_path {{debug_pm_status_path}} +process_manager {{debug_pm}} +pm.max_requests {{debug_pm_max_requests}} +pm.max_children {{debug_pm_max_children}} +pm.start_servers {{debug_pm_start_servers}} +pm.min_spare_servers {{debug_pm_min_spare_servers}} +pm.max_spare_servers {{debug_pm_max_spare_servers}} +request_terminate_timeout {{debug_request_terminate_timeout}} +xdebug.profiler_enable_trigger {{debug_xdebug_profiler_enable_trigger}} +listen {{debug_listen}} From c3c8eccf1e74c60046e1f08386b5d6cce28f3239 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Thu, 15 Jan 2015 17:09:59 +0530 Subject: [PATCH 2/9] ee stack purge --mail pkgResolveProblem solved --- ee/cli/plugins/stack.py | 17 +++--- ee/core/aptget.py | 122 ++++++++++++++++------------------------ ee/core/logging.py | 1 + 3 files changed, 60 insertions(+), 80 deletions(-) diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index 1e9f1c5a..b82d5d25 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -919,7 +919,7 @@ class EEStackController(CementBaseController): self.app.pargs.mysql = True self.app.pargs.postfix = True - if not EEAptGet.is_installed('dovecot-core'): + if not EEAptGet.is_installed(self, 'dovecot-core'): Log.debug(self, "Setting apt_packages variable for mail") apt_packages = apt_packages + EEVariables.ee_mail packages = packages + [["https://github.com/opensolutions/" @@ -938,13 +938,13 @@ class EEStackController(CementBaseController): if self.app.pargs.nginx: Log.debug(self, "Setting apt_packages variable for Nginx") - if not EEAptGet.is_installed('nginx-common'): + if not EEAptGet.is_installed(self, 'nginx-common'): apt_packages = apt_packages + EEVariables.ee_nginx else: Log.info(self, "Nginx allready installed") if self.app.pargs.php: Log.debug(self, "Setting apt_packages variable for PHP") - if not EEAptGet.is_installed('php5-common'): + if not EEAptGet.is_installed(self, 'php5-fpm'): apt_packages = apt_packages + EEVariables.ee_php else: Log.info(self, "PHP allready installed") @@ -956,7 +956,7 @@ class EEStackController(CementBaseController): Log.info(self, "MySQL connection is allready alive") if self.app.pargs.postfix: Log.debug(self, "Setting apt_packages variable for PostFix") - if not EEAptGet.is_installed('postfix'): + if not EEAptGet.is_installed(self, 'postfix'): apt_packages = apt_packages + EEVariables.ee_postfix else: Log.info(self, "Postfix is allready installed") @@ -1022,9 +1022,10 @@ class EEStackController(CementBaseController): if len(apt_packages): EESwap.add(self) Log.debug(self, "Updating apt-cache") - EEAptGet.update() + EEAptGet.update(self) Log.debug(self, "Installing all apt_packages") - EEAptGet.install(apt_packages) + print(apt_packages) + EEAptGet.install(self, apt_packages) if len(packages): Log.debug(self, "Downloading all packages") EEDownload.download(self, packages) @@ -1095,7 +1096,7 @@ class EEStackController(CementBaseController): if len(apt_packages): Log.debug(self, "Removing apt_packages") - EEAptGet.remove(apt_packages) + EEAptGet.remove(self, apt_packages) if len(packages): EEFileUtils.remove(self, packages) Log.info(self, "Successfully removed packages") @@ -1160,7 +1161,7 @@ class EEStackController(CementBaseController): ] if len(apt_packages): - EEAptGet.remove(apt_packages, purge=True) + EEAptGet.remove(self, apt_packages, purge=True) if len(packages): EEFileUtils.remove(self, packages) Log.info(self, "Successfully purged packages") diff --git a/ee/core/aptget.py b/ee/core/aptget.py index 40d03b0c..9a499d4b 100644 --- a/ee/core/aptget.py +++ b/ee/core/aptget.py @@ -1,13 +1,16 @@ """EasyEngine package installation using apt-get module.""" import apt +import apt_pkg import sys +from ee.core.logging import Log class EEAptGet(): """Generic apt-get intialisation""" - def update(): + def update(self): """Similar to apt-get update""" + # app.log.debug("Update cache") cache = apt.Cache() fprogress = apt.progress.text.AcquireProgress() @@ -15,7 +18,7 @@ class EEAptGet(): cache.update(fprogress) cache.close() - def upgrade(packages): + def upgrade(self, packages): """Similar to apt-get update""" cache = apt.Cache() fprogress = apt.progress.text.AcquireProgress() @@ -63,7 +66,7 @@ class EEAptGet(): return(False) return(True) - def install(packages): + def install(self, packages): """Installation of packages""" cache = apt.Cache() fprogress = apt.progress.text.AcquireProgress() @@ -97,6 +100,7 @@ class EEAptGet(): with cache.actiongroup(): # Mark Package for Installation pkg.mark_install() + pkg.mark_auto(auto=False) my_selected_packages.append(pkg.name) # Check if packages available for install. @@ -110,7 +114,7 @@ class EEAptGet(): .format(req_download=cache.required_download)) print("After this operation, {space} bytes of" "additional disk space will be used." - .format(space=cache.required_space)) + .format(space=cache.required_space/1e6)) try: # Commit changes in cache (actually install) cache.commit(fprogress, iprogress) @@ -122,7 +126,7 @@ class EEAptGet(): cache.close() return(True) - def remove(packages, auto=True, purge=False): + def remove(self, packages, auto=False, purge=False): def __dependencies_loop(cache, deplist, pkg, onelevel=True): """ Loops through pkg's dependencies. Returns a list with every package found. """ @@ -132,15 +136,18 @@ class EEAptGet(): return for depf in pkg.installed.dependencies: for dep in depf: - if (dep.name in cache and not cache[dep.name] - in deplist): - deplist.append(cache[dep.name]) - __dependencies_loop(cache, deplist, cache[dep.name]) - if onelevel: - if dep.name in cache: + # if (dep.name in cache and not cache[dep.name] + # in deplist): + # deplist.append(cache[dep.name]) + # __dependencies_loop(cache, deplist, cache[dep.name]) + # if onelevel: + if dep.name in cache: + if (cache[dep.name].is_installed and + not cache[dep.name].is_auto_installed and + not cache[dep.name].marked_delete): onelevellist.append(cache[dep.name]) - if onelevel: - return onelevellist + # if onelevel: + return onelevellist cache = apt.Cache() fprogress = apt.progress.text.AcquireProgress() @@ -154,68 +161,37 @@ class EEAptGet(): cache.open() for package in packages: print("processing", package) - package = cache[package] - if not package.is_installed: - print("Package '{package_name}' is not installed," - " so not removed." - .format(package_name=package.name)) + try: + pkg = cache[package] + except KeyError as e: + Log.debug(self, "{0}".format(e)) continue - if package.marked_delete: - my_selected_packages.append(package.name) - # Mark for deletion the first package, to fire up - # auto_removable Purge? - if purge: - package.mark_delete(purge=True) - else: - package.mark_delete(purge=False) + if not pkg.is_installed: + Log.info(self, "Package '{package_name}' is not installed," + " so not removed." + .format(package_name=pkg.name)) continue - else: - my_selected_packages.append(package.name) - print(my_selected_packages) - # How logic works: - # 1) We loop trough dependencies's dependencies and add them to - # the list. - # 2) We sequentially remove every package in list - # - via is_auto_installed we check if we can safely remove it - deplist = [] - onelevel = __dependencies_loop(cache, deplist, package, - onelevel=True) - # Mark for deletion the first package, to fire up - # auto_removable Purge? + my_selected_packages.append(pkg.name) + print(my_selected_packages) + # How logic works: + # 1) We loop trough dependencies's dependencies and add them to + # the list. + # 2) We sequentially remove every package in list + # - via is_auto_installed we check if we can safely remove it + deplist = [] + onelevel = __dependencies_loop(cache, deplist, pkg, + onelevel=True) + # Mark for deletion the first package, to fire up + # auto_removable Purge? + packages = packages + onelevel + try: if purge: - package.mark_delete(purge=True) - else: - package.mark_delete(purge=False) - - # Also ensure we remove AT LEAST the first level of - # dependencies (that is, the actual package's dependencies). - if auto: - markedauto = [] - for pkg in onelevel: - if (not pkg.marked_install and pkg.is_installed - and not pkg.is_auto_installed): - pkg.mark_auto() - markedauto.append(pkg) - - for pkg in deplist: - if (not pkg.marked_install and pkg.is_installed and - pkg.is_auto_removable): - # Purge? - if purge: - pkg.mark_delete(purge=True) - else: - pkg.mark_delete(purge=False) - # Restore auted items - for pkg in markedauto: - if not pkg.marked_delete: - pkg.mark_auto(False) + pkg.mark_delete(purge=True) else: - # We need to ensure that the onelevel packages are not - # marked as automatically installed, otherwise the user may - # drop them via autoremove or aptitude. - for pkg in onelevel: - if pkg.is_installed and pkg.is_auto_installed: - pkg.mark_auto(auto=False) + pkg.mark_delete(purge=False) + except SystemError as e: + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to purge packages.") # Check if packages available for remove/update. if cache.delete_count > 0: @@ -239,7 +215,7 @@ class EEAptGet(): cache.close() return(True) - def is_installed(package): + def is_installed(self, package): cache = apt.Cache() fprogress = apt.progress.text.AcquireProgress() iprogress = apt.progress.base.InstallProgress() @@ -258,6 +234,8 @@ class EEAptGet(): else: cache.close() return False + except KeyError as e: + Log.debug(self, "{0}".format(e)) except Exception as e: cache.close() return False diff --git a/ee/core/logging.py b/ee/core/logging.py index 86c72278..8e44ca3f 100644 --- a/ee/core/logging.py +++ b/ee/core/logging.py @@ -12,6 +12,7 @@ class Log: def error(self, msg): self.app.log.error(Log.FAIL + msg + Log.ENDC) + self.app.close(1) def info(self, msg): self.app.log.info(Log.OKBLUE + msg + Log.ENDC) From c8aaa8b91eeb97b478b1c03671c9ed1020cd2839 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Thu, 15 Jan 2015 19:51:01 +0530 Subject: [PATCH 3/9] minor change --- ee/core/aptget.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ee/core/aptget.py b/ee/core/aptget.py index 9a499d4b..cfa7509c 100644 --- a/ee/core/aptget.py +++ b/ee/core/aptget.py @@ -100,7 +100,6 @@ class EEAptGet(): with cache.actiongroup(): # Mark Package for Installation pkg.mark_install() - pkg.mark_auto(auto=False) my_selected_packages.append(pkg.name) # Check if packages available for install. @@ -143,8 +142,7 @@ class EEAptGet(): # if onelevel: if dep.name in cache: if (cache[dep.name].is_installed and - not cache[dep.name].is_auto_installed and - not cache[dep.name].marked_delete): + cache[dep.name].is_auto_installed): onelevellist.append(cache[dep.name]) # if onelevel: return onelevellist @@ -183,7 +181,18 @@ class EEAptGet(): onelevel=True) # Mark for deletion the first package, to fire up # auto_removable Purge? - packages = packages + onelevel + + for dep in onelevel: + my_selected_packages.append(dep.name) + try: + if purge: + dep.mark_delete(purge=True) + else: + dep.mark_delete(purge=False) + except SystemError as e: + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to purge depedencies.") + try: if purge: pkg.mark_delete(purge=True) From b5f04c1912ad8d93f96487875fd5894073ac7eaa Mon Sep 17 00:00:00 2001 From: gau1991 Date: Fri, 16 Jan 2015 11:58:36 +0530 Subject: [PATCH 4/9] Disabled Cement debug messages, source: https://github.com/datafolklabs/cement/issues/290#issuecomment-70128449 --- ee/cli/main.py | 11 +++++++++++ setup.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ee/cli/main.py b/ee/cli/main.py index 17c8281f..fd2c5285 100644 --- a/ee/cli/main.py +++ b/ee/cli/main.py @@ -1,4 +1,13 @@ """EasyEngine main application entry point.""" +import sys + +# this has to happen after you import sys, but before you import anything +# from Cement "source: https://github.com/datafolklabs/cement/issues/290" +if '--debug' in sys.argv: + sys.argv.remove('--debug') + TOGGLE_DEBUG = True +else: + TOGGLE_DEBUG = False from cement.core import foundation from cement.utils.misc import init_defaults @@ -42,6 +51,8 @@ class EEApp(foundation.CementApp): # default output handler output_handler = 'mustache' + debug = TOGGLE_DEBUG + class EETestApp(EEApp): """A test app that is better suited for testing.""" diff --git a/setup.py b/setup.py index 3064be7d..d98e9f4d 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ setup(name='ee', # "nose", # "coverage", # Required to function - 'cement>=2.4', + 'cement == 2.4', 'pystache', 'python-apt', 'pynginxconfig', From 5748abc5decafd90429ebc38013f8614c96f3e48 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Fri, 16 Jan 2015 12:54:45 +0530 Subject: [PATCH 5/9] added sqlite db model --- ee/cli/plugins/site.py | 326 ++++++++++++++++++------------- ee/cli/plugins/site_functions.py | 30 ++- ee/cli/plugins/sitedb.py | 124 +++++------- ee/cli/plugins/stack.py | 2 +- ee/core/database.py | 19 ++ ee/core/models.py | 40 ++++ ee/core/services.py | 2 +- ee/core/variables.py | 2 +- 8 files changed, 325 insertions(+), 220 deletions(-) create mode 100644 ee/core/database.py create mode 100644 ee/core/models.py diff --git a/ee/cli/plugins/site.py b/ee/cli/plugins/site.py index b0b69962..21505028 100644 --- a/ee/cli/plugins/site.py +++ b/ee/cli/plugins/site.py @@ -17,7 +17,8 @@ from subprocess import Popen def ee_site_hook(app): # do something with the ``app`` object here. - pass + from ee.core.database import init_db + init_db() class EESiteController(CementBaseController): @@ -48,8 +49,7 @@ class EESiteController(CementBaseController): '/etc/nginx/sites-enabled/{0}.conf' .format(ee_domain_name)]) else: - Log.error(self, "site {0} does not exists".format(ee_domain)) - sys.exit(1) + Log.error(self, "!! site {0} does not exists".format(ee_domain)) @expose(help="disable site example.com") def disable(self): @@ -62,8 +62,7 @@ class EESiteController(CementBaseController): '/etc/nginx/sites-enabled/{0}.conf' .format(ee_domain_name)]) else: - Log.error(self, "site {0} does not exists".format(ee_domain)) - sys.exit(1) + Log.error(self, "!! site {0} does not exists".format(ee_domain)) @expose(help="get example.com information") def info(self): @@ -95,8 +94,7 @@ class EESiteController(CementBaseController): dbpass=ee_db_pass) self.app.render((data), 'siteinfo.mustache') else: - Log.error(self, "site {0} does not exists".format(ee_domain)) - sys.exit(1) + Log.error(self, "!! site {0} does not exists".format(ee_domain)) @expose(help="Monitor example.com logs") def log(self): @@ -106,8 +104,7 @@ class EESiteController(CementBaseController): EEShellExec.cmd_exec(self, 'tail -f /var/log/nginx/{0}.*.log' .format(ee_domain)) else: - Log.error(self, "site {0} does not exists".format(ee_domain)) - sys.exit(1) + Log.error(self, "!! site {0} does not exists".format(ee_domain)) @expose(help="Edit example.com's nginx configuration") def edit(self): @@ -123,8 +120,7 @@ class EESiteController(CementBaseController): # Reload NGINX EEService.reload_service(self, 'nginx') else: - Log.error(self, "site {0} does not exists".format(ee_domain)) - sys.exit(1) + Log.error(self, "!! site {0} does not exists".format(ee_domain)) @expose(help="Display example.com's nginx configuration") def show(self): @@ -139,8 +135,7 @@ class EESiteController(CementBaseController): print(text) f.close() else: - Log.error(self, "site {0} does not exists".format(ee_domain)) - sys.exit(1) + Log.error(self, "!! site {0} does not exists".format(ee_domain)) @expose(help="list sites currently available") def list(self): @@ -158,9 +153,8 @@ class EESiteController(CementBaseController): try: subprocess.call(['bash']) except OSError as e: - Log.error(self, "Unable to edit file \ {0}{1}" - .format(e.errno, e.strerror)) - sys.exit(1) + Log.debug(self, "{0}{1}".format(e.errno, e.strerror)) + Log.error(self, "!! cannot change directory") class EESiteCreateController(CementBaseController): @@ -205,9 +199,8 @@ class EESiteCreateController(CementBaseController): # Check if doain previously exists or not if os.path.isfile('/etc/nginx/sites-available/{0}' .format(ee_domain)): - self.app.log.error(self, "site {0} already exists" - .format(ee_domain)) - sys.exit(1) + Log.error(self, "!! site {0} already exists" + .format(ee_domain)) # setup nginx configuration for site # HTML @@ -425,12 +418,12 @@ class EESiteCreateController(CementBaseController): data['ee_db_pass'], data['ee_db_host'])) eedbconfig.close() - stype = mysql + stype = 'mysql' except IOError as e: - self.app.log.error("Unable to create ee-config.php for " - "{2} ({0}): {1}" - .format(e.errno, e.strerror, ee_domain)) - sys.exit(1) + Log.debug(self, "{2} ({0}): {1}" + .format(e.errno, e.strerror, ee_domain)) + Log.error(self, "!! Unable to create ee-config.php for ") + # Setup WordPress if Wordpress site if data['wp']: ee_wp_creds = SetupWordpress(self, data) @@ -492,11 +485,13 @@ class EESiteUpdateController(CementBaseController): check_site = getSiteInfo(self, ee_domain) if check_site is None: - Log.error(self, "Site {0} does not exist.".format(ee_domain)) + Log.error(self, "!! Site {0} does not exist.".format(ee_domain)) else: oldsitetype = check_site.site_type oldcachetype = check_site.cache_type + print(oldsitetype, oldcachetype) + if (self.app.pargs.html and not (self.app.pargs.php or self.app.pargs.mysql or self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or self.app.pargs.wpsc or @@ -510,14 +505,17 @@ class EESiteUpdateController(CementBaseController): self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)): if oldsitetype != 'html': - Log.error("Cannot update {0} to php".format(ee_domain)) - sys.exit(1) + + Log.error(self, "!! Cannot update {0} {1} to php" + .format(ee_domain, oldsitetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=True, wp=False, w3tc=False, wpfc=False, wpsc=False, multisite=False, wpsubdir=False, webroot=ee_site_webroot, currsitetype=oldsitetype, currcachetype=oldcachetype) + stype = 'php' + cache = 'basic' #MySQL if (self.app.pargs.mysql and not (self.app.pargs.html or @@ -525,9 +523,9 @@ class EESiteUpdateController(CementBaseController): or self.app.pargs.wpfc or self.app.pargs.wpsc or self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)): - if oldsitetype != 'html' or oldsitetype != 'php': - Log.error("Cannot update {0} to mysql".format(ee_domain)) - sys.exit(1) + if oldsitetype not in ['html', 'php']: + Log.error(self, "!! Cannot update {0}, {1} to mysql" + .format(ee_domain, oldsitetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=True, wp=False, w3tc=False, @@ -536,6 +534,8 @@ class EESiteUpdateController(CementBaseController): ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) + stype = 'mysql' + cache = 'basic' #WP if ((self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or @@ -545,11 +545,11 @@ class EESiteUpdateController(CementBaseController): if (self.app.pargs.wp and not (self.app.pargs.w3tc or self.app.pargs.wpfc or self.app.pargs.wpsc)): - if (oldsitetype not in ['html', 'php', 'wp'] - and oldsitetype not in ['w3tc', 'wpfc', 'wpsc']): - Log.error("Cannot update {0} to wp basic" - .format(ee_domain)) - sys.exit(1) + if ((oldsitetype in ['html', 'php', 'mysql', 'wp']) + and (oldcachetype not in ['w3tc', 'wpfc', 'wpsc'])): + print(oldsitetype, oldcachetype) + Log.error(self, "!! Cannot update {0}, {1} {2} to wp basic" + .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=True, wp=True, w3tc=False, @@ -558,14 +558,16 @@ class EESiteUpdateController(CementBaseController): ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) + stype = 'wp' + cache = 'basic' if (self.app.pargs.w3tc and not (self.app.pargs.wpfc or self.app.pargs.wpsc)): - if (oldsitetype not in ['html', 'php', 'wp'] - and oldsitetype not in ['basic', 'wpfc', 'wpsc']): - Log.error("Cannot update {0} to wp w3tc".format(ee_domain)) - sys.exit(1) + if (oldsitetype in ['html', 'php', 'mysql', 'wp'] + and oldcachetype not in ['basic', 'wpfc', 'wpsc']): + Log.error(self, "!! Cannot update {0}, {1} {2}to wp w3tc" + .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=False, wp=True, w3tc=True, @@ -575,13 +577,16 @@ class EESiteUpdateController(CementBaseController): ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) + stype = 'wp' + cache = 'w3tc' + if (self.app.pargs.wpfc and not (self.app.pargs.wpsc or self.app.pargs.w3tc)): - if (oldsitetype not in ['html', 'php', 'wp'] - and oldsitetype not in ['basic', 'w3tc', 'wpsc']): - Log.error("Cannot update {0} to wp wpfc".format(ee_domain)) - sys.exit(1) + if (oldsitetype in ['html', 'php', 'mysql', 'wp'] + and oldcachetype not in ['basic', 'w3tc', 'wpsc']): + Log.error(self, "Cannot update {0}, {1} {2} to wp wpfc" + .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=False, wp=True, w3tc=False, @@ -590,14 +595,16 @@ class EESiteUpdateController(CementBaseController): ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) + stype = 'wp' + cache = 'wpfc' if (self.app.pargs.wpsc and not (self.app.pargs.w3tc or self.app.pargs.wpfc)): - if (oldsitetype not in ['html', 'php', 'wp'] - and oldsitetype not in ['basic', 'w3tc', 'wpfc']): - Log.error("Cannot update {0} to wp wpsc".format(ee_domain)) - sys.exit(1) + if (oldsitetype in ['html', 'php', 'mysql', 'wp'] + and oldcachetype not in ['basic', 'w3tc', 'wpfc']): + Log.error(self, "Cannot update {0}, {1} {2} to wp wpsc" + .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=False, wp=True, w3tc=False, @@ -606,6 +613,8 @@ class EESiteUpdateController(CementBaseController): ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) + stype = 'wp' + cache = 'wpsc' #WPSUBDIR if (self.app.pargs.wpsubdir and not (self.app.pargs.html or @@ -614,11 +623,11 @@ class EESiteUpdateController(CementBaseController): if (self.app.pargs.wpsubdir and not (self.app.pargs.w3tc or self.app.pargs.wpfc or self.app.pargs.wpsc)): - if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdir'] - and oldsitetype not in ['w3tc', 'wpfc', 'wpsc']): - Log.error("Cannot update {0} to wpsubdir basic" - .format(ee_domain)) - sys.exit(1) + if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir'] + and oldcachetype not in ['w3tc', 'wpfc', 'wpsc']): + Log.error(self, "!! Cannot update {0}, {1} {2} " + "to wpsubdir basic" + .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=True, wp=True, w3tc=False, @@ -627,15 +636,17 @@ class EESiteUpdateController(CementBaseController): ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) + stype = 'wpsubdir' + cache = 'basic' if (self.app.pargs.w3tc and not (self.app.pargs.wpfc or self.app.pargs.wpsc)): - if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdir'] - and oldsitetype not in ['basic', 'wpfc', 'wpsc']): - Log.error("Cannot update {0} to wpsubdir w3tc" - .format(ee_domain)) - sys.exit(1) + if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir'] + and oldcachetype not in ['basic', 'wpfc', 'wpsc']): + Log.error(self, "!! Cannot update {0} {1} {2}" + "to wpsubdir w3tc" + .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=False, wp=True, w3tc=True, @@ -645,14 +656,17 @@ class EESiteUpdateController(CementBaseController): ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) + stype = 'wpsubdir' + cache = 'w3tc' + if (self.app.pargs.wpfc and not (self.app.pargs.wpsc or self.app.pargs.w3tc)): - if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdir'] - and oldsitetype not in ['basic', 'w3tc', 'wpsc']): - Log.error("Cannot update {0} to wpsubdir wpfc" - .format(ee_domain)) - sys.exit(1) + if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir'] + and oldcachetype not in ['basic', 'w3tc', 'wpsc']): + Log.error(self, "!! Cannot update {0} {1} {2}" + " to wpsubdir wpfc" + .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=False, wp=True, w3tc=False, @@ -661,15 +675,17 @@ class EESiteUpdateController(CementBaseController): ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) + stype = 'wpsubdir' + cache = 'wpfc' if (self.app.pargs.wpsc and not (self.app.pargs.w3tc or self.app.pargs.wpfc)): - if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdir'] - and oldsitetype not in ['basic', 'w3tc', 'wpfc']): - Log.error("Cannot update {0} to wpsubdir wpsc" - .format(ee_domain)) - sys.exit(1) + if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir'] + and oldcachetype not in ['basic', 'w3tc', 'wpfc']): + Log.error(self, "!! Cannot update {0} {1} {2}" + " to wpsubdir wpsc" + .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=False, wp=True, w3tc=False, @@ -678,16 +694,18 @@ class EESiteUpdateController(CementBaseController): ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) + stype = 'wpsubdir' + cache = 'wpsc' 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.wpsubdir or self.app.pargs.wp)): - if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdomain'] - and oldsitetype not in ['w3tc', 'wpfc', 'wpsc']): - Log.error("Cannot update {0} to wpsubdomain basic" - .format(ee_domain)) - sys.exit(1) + if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdomain'] + and oldcachetype not in ['w3tc', 'wpfc', 'wpsc']): + Log.error(self, "!! Cannot update {0} {1} {2}" + " to wpsubdomain basic" + .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=True, wp=True, w3tc=False, @@ -697,14 +715,18 @@ class EESiteUpdateController(CementBaseController): ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) + stype = 'wpsubdomain' + cache = 'basic' + if (self.app.pargs.w3tc and not (self.app.pargs.wpfc or self.app.pargs.wpsc)): - if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdomain'] - and oldsitetype not in ['basic', 'wpfc', 'wpsc']): - Log.error("Cannot update {0} to wpsubdomain w3tc" - .format(ee_domain)) - sys.exit(1) + if (oldsitetype in ['html', 'php', 'mysql', 'wp', + 'wpsubdomain'] + and oldcachetype not in ['basic', 'wpfc', 'wpsc']): + Log.error(self, "!! Cannot update {0}, {1} {2}" + " to wpsubdomain w3tc" + .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=False, wp=True, w3tc=True, @@ -714,14 +736,18 @@ class EESiteUpdateController(CementBaseController): ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) + stype = 'wpsubdomain' + cache = 'w3tc' + if (self.app.pargs.wpfc and not (self.app.pargs.wpsc or self.app.pargs.w3tc)): - if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdomain'] - and oldsitetype not in ['basic', 'w3tc', 'wpsc']): - Log.error("Cannot update {0} to wpsubdomain wpfc" - .format(ee_domain)) - sys.exit(1) + if (oldsitetype in ['html', 'php', 'mysql', 'wp', + 'wpsubdomain'] + and oldcachetype not in ['basic', 'w3tc', 'wpsc']): + Log.error(self, "!! Cannot update {0}, {1} {2} " + "to wpsubdomain wpfc" + .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=False, wp=True, w3tc=False, @@ -731,14 +757,18 @@ class EESiteUpdateController(CementBaseController): ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) + stype = 'wpsubdomain' + cache = 'wpfc' + if (self.app.pargs.wpsc and not (self.app.pargs.w3tc or self.app.pargs.wpfc)): - if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdomain'] - and oldsitetype not in ['basic', 'w3tc', 'wpfc']): - Log.error("Cannot update {0} to wpsubdomain wpsc" - .format(ee_domain)) - sys.exit(1) + if (oldsitetype in ['html', 'php', 'mysql', 'wp', + 'wpsubdomain'] + and oldcachetype not in ['basic', 'w3tc', 'wpfc']): + Log.error(self, "!! Cannot update {0}, {1} {2}" + " to wpsubdomain wpsc" + .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=False, wp=True, w3tc=False, @@ -748,7 +778,12 @@ class EESiteUpdateController(CementBaseController): ee_db_host='', currsitetype=oldsitetype, currcachetype=oldcachetype) - # TODO take site backup before site update + stype = 'wpsubdomain' + cache = 'wpsc' + + if not data: + Log.error(self, "!! Cannot update" + .format(ee_domain)) siteBackup(self, data) # TODO Check for required packages before update @@ -769,12 +804,11 @@ class EESiteUpdateController(CementBaseController): data['ee_db_pass'], data['ee_db_host'])) eedbconfig.close() - stype = mysql except IOError as e: - self.app.log.error("Unable to create ee-config.php for " - "{2} ({0}): {1}" - .format(e.errno, e.strerror, ee_domain)) - sys.exit(1) + Log.error(self, "!! Unable to create ee-config.php for " + "{0}" + .format(ee_domain)) + Log.debug(self, "{0} {1}".format(e.errno, e.strerror)) if oldsitetype == 'mysql': config_file = (ee_site_webroot + '/backup/{0}/ee-config.php' @@ -795,24 +829,41 @@ class EESiteUpdateController(CementBaseController): .split(',')[1] .split(')')[0].strip()) - # Setup WordPress if Wordpress site - if data['wp']: + # Setup WordPress if old sites are html/php/mysql sites + if data['wp'] and oldsitetype in ['html', 'php', 'mysql']: ee_wp_creds = SetupWordpress(self, data) + + # Uninstall unnecessary plugins + if oldsitetype in ['wp', 'wpsubdir', 'wpsubdomain']: + # Setup WordPress Network if update option is multisite + # and oldsite is WordPress single site + if data['multisite'] and oldsitetype == 'wp': + SetupWordpressNetwork(self, data) + + if (oldcachetype == 'w3tc' or oldcachetype == 'wpfc' and + not data['w3tc', 'wpfc']): + UnInstallWP_Plugin(self, 'w3-total-cache', data) + + if oldcachetype == 'wpsc' and not data['wpsc']: + UnInstallWP_Plugin(self, 'wp-super-cache', data) + + if oldcachetype != 'w3tc' or oldcachetype != 'wpfc'and data['w3tc']: + InstallWP_Plugin(self, 'w3-total-cache', data) + + if oldcachetype != 'wpsc' and data['wpsc']: + InstallWP_Plugin(self, 'wp-super-cache', data) + # Service Nginx Reload EEService.reload_service(self, 'nginx') EEGit.add(self, ["/etc/nginx"], - msg="{0} created with {1} {2}" + msg="{0} updated with {1} {2}" .format(ee_www_domain, stype, cache)) # Setup Permissions for webroot - SetWebrootPermissions(self, data['webroot']) - if data['wp']: - Log.info(self, '\033[94m'+"WordPress Admin User :" - " {0}".format(ee_wp_creds['wp_user'])+'\033[0m') - Log.info(self, "WordPress Admin User Password : {0}" - .format(ee_wp_creds['wp_pass'])) - addNewSite(self, ee_www_domain, stype, cache, ee_site_webroot) - Log.info(self, "Successfully created site" + #SetWebrootPermissions(self, data['webroot']) + + updateSiteInfo(self, ee_www_domain, stype=stype, cache=cache) + Log.info(self, "Successfully updated site" " http://{0}".format(ee_domain)) @@ -836,7 +887,7 @@ class EESiteDeleteController(CementBaseController): dict(help="delete webroot only", action='store_true')), ] - @expose(help="update example.com") + @expose(help="delete example.com") def default(self): # TODO Write code for ee site update here (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) @@ -851,43 +902,48 @@ class EESiteDeleteController(CementBaseController): if self.app.pargs.db: if not ee_prompt: - ee_db_prompt = input('Do you want to delete database:[Y/N]' - ) + ee_db_prompt = input('Do you want to delete database:' + '[Y/N] ') else: ee_db_prompt = 'Y' if ee_db_prompt == 'Y': - deleteDB(ee_site_webroot) + self.deleteDB(ee_site_webroot) if self.app.pargs.files: if not ee_prompt: - ee_web_prompt = input('Do you want to delete webroot:[Y/N]' - ) + ee_web_prompt = input('Do you want to delete webroot:' + '[Y/N] ') else: ee_web_prompt = 'Y' if ee_web_prompt == 'Y': - deleteWebRoot(ee_site_webroot) + self.deleteWebRoot(ee_site_webroot) if self.app.pargs.all: if not ee_prompt: - ee_db_prompt = input('Do you want to delete database:[Y/N]' + ee_db_prompt = input('Do you want to delete database:' + '[Y/N] ' ) - ee_web_prompt = input('Do you want to delete webroot:[Y/N]' - ) + ee_web_prompt = input('Do you want to delete webroot:' + '[Y/N] ') ee_nginx_prompt = input('Do you want to delete NGINX' - ' configuration:[Y/N]') + ' configuration:[Y/N] ') else: ee_db_prompt = 'Y' ee_web_prompt = 'Y' ee_nginx_prompt = 'Y' - if ee_db_prompt: - deleteDB(self, ee_site_webroot) - if ee_web_prompt: - deleteWebRoot(ee_site_webroot) - if ee_nginx_prompt: - EEFileutils.delete(self, '/etc/nginx/sites-available/{0}' - .format(ee_domain)) + if ee_db_prompt == 'Y': + self.deleteDB(ee_site_webroot) + if ee_web_prompt == 'Y': + self.deleteWebRoot(ee_site_webroot) + if ee_nginx_prompt == 'Y': + EEFileUtils.rm(self, '/etc/nginx/sites-available/{0}' + .format(ee_domain)) + deleteSiteInfo(self, ee_domain) + else: + Log.error(self, "!! site {0} does not exists".format(ee_domain)) + @expose(hide=True) def deleteDB(self, webroot): configfiles = glob.glob(webroot + '/*-config.php') if configfiles: @@ -904,19 +960,23 @@ class EESiteDeleteController(CementBaseController): ee_db_host = (EEFileUtils.grep(self, configfiles[0], 'DB_HOST').split(',')[1] .split(')')[0].strip().replace('\'', '')) - - EEMysql.execute(self, - "drop database {0}" - .format(ee_db_name)) - if ee_db_user != 'root': - EEMysql.execute(self, - "drop user {0}@{1}" - .format(ee_db_user, ee_db_host)) + try: EEMysql.execute(self, - "flush privileges") + "drop database {0}".format(ee_db_name), + errormsg='Unable to drop database {0}' + .format(ee_db_name)) + if ee_db_user != 'root': + EEMysql.execute(self, + "drop user {0}@{1}" + .format(ee_db_user, ee_db_host)) + EEMysql.execute(self, + "flush privileges") + except Exception as e: + Log.error(self, "!! Error occured while deleting database") - def deleteWebRoot(webroot): - EEFileutils.delete(self, webroot) + @expose(hide=True) + def deleteWebRoot(self, webroot): + EEFileUtils.rm(self, webroot) def load(app): diff --git a/ee/cli/plugins/site_functions.py b/ee/cli/plugins/site_functions.py index ef18ae4c..1a5c9ccc 100644 --- a/ee/cli/plugins/site_functions.py +++ b/ee/cli/plugins/site_functions.py @@ -15,7 +15,7 @@ def SetupDomain(self, data): ee_domain_name = data['site_name'] ee_site_webroot = data['webroot'] - self.app.log.info("Creating {0} ...".format(ee_domain_name)) + self.app.log.info("Setting up NGINX config {0} ...".format(ee_domain_name)) # write nginx config for file try: ee_site_nginx_conf = open('/etc/nginx/sites-available/{0}' @@ -138,9 +138,10 @@ def SetupWordpress(self, data): ee_wp_user = '' ee_wp_pass = '' - self.app.log.info("Downloading Wordpress...") + Log.info(self, "Downloading Wordpress...", end='') EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEShellExec.cmd_exec(self, "wp --allow-root core download") + Log.info("[Done]") if not (data['ee_db_name'] and data['ee_db_user'] and data['ee_db_pass']): data = SetupDatabase(self, data) @@ -248,8 +249,9 @@ def SetupWordpress(self, data): def SetupWordpressNetwork(self, data): ee_site_webroot = data['webroot'] EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) + Log.info(self, "Setting up WordPress Network") EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert' - '--title={0} {subdomains}' + ' --title={0} {subdomains}' .format(data['www_domain'], subdomains='--subdomains' if not data['wpsubdir'] else '')) @@ -271,6 +273,16 @@ def InstallWP_Plugin(self, plugin_name, data): .format(plugin_name)) +def UnInstallWP_Plugin(self, plugin_name, data): + ee_site_webroot = data['webroot'] + self.app.log.debug("Uninstalling plugin {0}".format(plugin_name)) + EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) + EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root uninstall " + "{0}".format(plugin_name), + errormsg="Unable to Install plugin {0}" + .format(plugin_name)) + + def SetWebrootPermissions(self, webroot): self.app.log.debug("Setting Up Permissions...") EEFileUtils.chown(self, webroot, EEVariables.ee_php_user, @@ -284,20 +296,24 @@ def siteBackup(self, data): EEFileUtils.mkdir(self, backup_path) Log.info(self, "Backup Location : {0}".format(backup_path)) EEFileUtils.copyfile(self, '/etc/nginx/sites-available/{0}' - .format(data['ee_domain']), backup_path) + .format(data['site_name']), backup_path) if data['currsitetype'] in ['html', 'php', 'mysql']: Log.info(self, "Backup Webroot ...") EEFileUtils.mvfile(self, ee_site_webroot + '/htdocs', backup_path) - configfiles = glob(ee_site_webroot + '/*-config.php') + configfiles = glob.glob(ee_site_webroot + '/*-config.php') if EEFileUtils.isexist(self, configfiles[0]): - ee_db_name = (EEFileUtils.grep(self, file, 'DB_NAME').split(',')[1] + ee_db_name = (EEFileUtils.grep(self, configfiles[0], + 'DB_NAME').split(',')[1] .split(')')[0].strip().replace('\'', '')) Log.info(self, 'Backup Database, please wait') EEShellExec.cmd_exec(self, "mysqldump {0} > {1}/{0}.sql" .format(ee_db_name, backup_path), "Failed: Backup Database") # move wp-config.php/ee-config.php to backup - EEFileUtils.mvfile(self, file, backup_path) + if data['currsitetype'] in ['mysql']: + EEFileUtils.mvfile(self, configfiles[0], backup_path) + else: + EEFileUtils.copyfile(self, configfiles[0], backup_path) diff --git a/ee/cli/plugins/sitedb.py b/ee/cli/plugins/sitedb.py index 165c49c3..c8f2acd6 100644 --- a/ee/cli/plugins/sitedb.py +++ b/ee/cli/plugins/sitedb.py @@ -4,96 +4,66 @@ from sqlalchemy.orm import relationship, backref from sqlalchemy.ext.declarative import declarative_base from ee.core.logging import Log import sys +from ee.core.database import db_session +from ee.core.models import SiteDB -Base = declarative_base() +def addNewSite(self, site, stype, cache, path, + enabled=True, ssl=False, fs='ext4', db='mysql'): + try: + newRec = SiteDB(site, stype, cache, path, enabled, ssl, fs, db) + db_session.add(newRec) + db_session.commit() + except Exception as e: + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to add site to database") -class SiteDB(Base): - __tablename__ = 'Site' - id = Column(Integer, primary_key=True) - sitename = Column(String, unique=True) - site_type = Column(String) - cache_type = Column(String) - site_path = Column(String) +def getSiteInfo(self, site): + try: + q = SiteDB.query.filter(SiteDB.sitename == site).first() + return q + except Exception as e: + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to query database for site info") - # Use default=func.now() to set the default created time - # of a site to be the current time when a - # Site record was created - created_on = Column(DateTime, default=func.now()) - site_enabled = Column(Boolean, unique=False, default=True, nullable=False) - is_ssl = Column(Boolean, unique=False, default=False) - storage_fs = Column(String) - storage_db = Column(String) +def updateSiteInfo(self, site, stype='', cache='', + enabled=True, ssl=False, fs='', db=''): + try: + q = SiteDB.query.filter(SiteDB.sitename == site).first() + except Exception as e: + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to query database for site info") + if stype and q.site_type != stype: + q.site_type = stype - def __init__(self): - # from sqlalchemy import create_engine - # self.engine = create_engine('sqlite:///orm_in_detail.sqlite') - self.sitename = sitename - self.site_type = site_type - self.cache_type = cache_type - self.site_path = site_path - self.created_on = created_on - self.site_enabled = site_enabled - self.is_ssl = is_ssl - self.storage_fs = storage_fs - self.storage_db = storage_db + if cache and q.cache_type != cache: + q.cache_type = cache -# if __name__ == "__main__": -# -# from sqlalchemy import create_engine -# engine = create_engine('sqlite:///orm_in_detail.sqlite') -# from sqlalchemy.orm import sessionmaker -# session = sessionmaker() -# session.configure(bind=engine) -# Base.metadata.create_all(engine) -# s = session() -# newRec = SiteDB(sitename='exa.in', site_type='wp', cache_type='basic', - # site_path='/var/www', site_enabled=True, is_ssl=False, storage_fs='ext4', - # storage_db='mysql') -# s.add(newRec) -# s.commit() -# s.flush() + if enabled and q.is_enabled != enabled: + q.is_enabled = enabled + if ssl and q.is_ssl != ssl: + q.is_ssl = ssl -def addNewSite(self, site, stype, cache, path, - enabled=True, ssl=False, fs='ext4', db='mysql'): - db_path = self.app.config.get('site', 'db_path') try: - from sqlalchemy import create_engine - engine = create_engine(db_path) - from sqlalchemy.orm import sessionmaker - session = sessionmaker() - session.configure(bind=engine) - Base.metadata.create_all(engine) - s = session() - newRec = SiteDB(sitename=site, site_type=stype, cache_type=cache, - site_path=path, site_enabled=enabled, is_ssl=ssl, - storage_fs=fs, storage_db=db) - s.add(newRec) - s.commit() - s.flush() + q.created_on = func.now() + db_session.commit() except Exception as e: - Log.error(self, "Unable to add site to database : {0}" - .format(e)) - sys.exit(1) + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to update site info in application database.") -def getSiteInfo(self, site): - db_path = self.app.config.get('site', 'db_path') +def deleteSiteInfo(self, site): try: - from sqlalchemy import create_engine - engine = create_engine(db_path) - from sqlalchemy.orm import sessionmaker - session = sessionmaker() - session.configure(bind=engine) - Base.metadata.create_all(engine) - s = session() - q = s.query(SiteDB).filter_by(sitename=site).first() - s.flush() - return q + q = SiteDB.query.filter(SiteDB.sitename == site).first() + except Exception as e: + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to query database :") + try: + db_session.delete(q) + db_session.commit() except Exception as e: - Log.error(self, "Unable to add site to database : {0}" - .format(e)) - sys.exit(1) + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to delete site from application database.") diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index a8595c5d..ee1f3657 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -1042,7 +1042,7 @@ class EEStackController(CementBaseController): if len(self.msg): for msg in self.msg: Log.info(self, msg) - Log.info(self, "Successfully installed packages") + Log.info(self, "Successfully installed packages") @expose() def remove(self): diff --git a/ee/core/database.py b/ee/core/database.py new file mode 100644 index 00000000..1cac3452 --- /dev/null +++ b/ee/core/database.py @@ -0,0 +1,19 @@ +from sqlalchemy import create_engine +from sqlalchemy.orm import scoped_session, sessionmaker +from sqlalchemy.ext.declarative import declarative_base + +#db_path = self.app.config.get('site', 'db_path') +engine = create_engine('sqlite:////var/lib/ee/ee.sqlite', convert_unicode=True) +db_session = scoped_session(sessionmaker(autocommit=False, + autoflush=False, + bind=engine)) +Base = declarative_base() +Base.query = db_session.query_property() + + +def init_db(): + # import all modules here that might define models so that + # they will be registered properly on the metadata. Otherwise + # you will have to import them first before calling init_db() + import ee.core.models + Base.metadata.create_all(bind=engine) diff --git a/ee/core/models.py b/ee/core/models.py new file mode 100644 index 00000000..bd62fc43 --- /dev/null +++ b/ee/core/models.py @@ -0,0 +1,40 @@ +from sqlalchemy import Column, DateTime, String, Integer, Boolean, func +from ee.core.database import Base + + +class SiteDB(Base): + __tablename__ = 'sites' + id = Column(Integer, primary_key=True) + sitename = Column(String, unique=True) + + site_type = Column(String) + cache_type = Column(String) + site_path = Column(String) + + # Use default=func.now() to set the default created time + # of a site to be the current time when a + # Site record was created + + created_on = Column(DateTime, default=func.now()) + is_enabled = Column(Boolean, unique=False, default=True, nullable=False) + is_ssl = Column(Boolean, unique=False, default=False) + storage_fs = Column(String) + storage_db = Column(String) + + def __init__(self, sitename=None, site_type=None, cache_type=None, + site_path=None, site_enabled=None, + is_ssl=None, storage_fs=None, storage_db=None): + self.sitename = sitename + self.site_type = site_type + self.cache_type = cache_type + self.site_path = site_path + self.is_enabled = site_enabled + self.is_ssl = is_ssl + self.storage_fs = storage_fs + self.storage_db = storage_db + + # def __repr__(self): + # return '' % (self.site_type) + # + # def getType(self): + # return '%r>' % (self.site_type) diff --git a/ee/core/services.py b/ee/core/services.py index 961710c3..556c8231 100644 --- a/ee/core/services.py +++ b/ee/core/services.py @@ -67,7 +67,7 @@ class EEService(): .format(service_name, "[OK]")) return True else: - Log.debug("{0}".format(retcode[1])) + Log.debug(self, "{0}".format(retcode[1])) Log.error(self, "reload : {0}".format(service_name)) return False diff --git a/ee/core/variables.py b/ee/core/variables.py index 36797587..9077de93 100644 --- a/ee/core/variables.py +++ b/ee/core/variables.py @@ -77,7 +77,7 @@ class EEVariables(): ee_mail = ["dovecot-core", "dovecot-imapd", "dovecot-pop3d", "dovecot-lmtpd", "dovecot-mysql", "dovecot-sieve", "dovecot-managesieved", "postfix-mysql", "php5-cgi", - "php5-json", "php-gettext"] + "php-gettext"] # Mailscanner repo and packages ee_mailscanner_repo = () From 303db4635dd93de062eed47c695569e5fbb0d792 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Fri, 16 Jan 2015 12:55:55 +0530 Subject: [PATCH 6/9] Now log messages goes to log file and screen will display only messages --- config/ee.conf | 2 +- ee/core/logging.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config/ee.conf b/config/ee.conf index d3d8aafb..ce68b3e5 100644 --- a/config/ee.conf +++ b/config/ee.conf @@ -27,7 +27,7 @@ file = /var/log/ee/ee.log level = debug ### Whether or not to log to console -to_console = true +to_console = false ### Whether or not to rotate the log file when it reaches `max_bytes` rotate = true diff --git a/ee/core/logging.py b/ee/core/logging.py index 8e44ca3f..5feb15e1 100644 --- a/ee/core/logging.py +++ b/ee/core/logging.py @@ -14,7 +14,8 @@ class Log: self.app.log.error(Log.FAIL + msg + Log.ENDC) self.app.close(1) - def info(self, msg): + def info(self, msg, end='\n'): + print(Log.OKBLUE + msg + Log.ENDC, end=end) self.app.log.info(Log.OKBLUE + msg + Log.ENDC) def warn(self, msg): From 5ef5392a33af8a067907381328c0d0476cde72fa Mon Sep 17 00:00:00 2001 From: gau1991 Date: Fri, 16 Jan 2015 13:14:40 +0530 Subject: [PATCH 7/9] Fixed minor bugs --- config/ee.conf | 2 +- ee/cli/plugins/site_functions.py | 2 +- ee/core/logging.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config/ee.conf b/config/ee.conf index ce68b3e5..d3d8aafb 100644 --- a/config/ee.conf +++ b/config/ee.conf @@ -27,7 +27,7 @@ file = /var/log/ee/ee.log level = debug ### Whether or not to log to console -to_console = false +to_console = true ### Whether or not to rotate the log file when it reaches `max_bytes` rotate = true diff --git a/ee/cli/plugins/site_functions.py b/ee/cli/plugins/site_functions.py index 1a5c9ccc..bde91af8 100644 --- a/ee/cli/plugins/site_functions.py +++ b/ee/cli/plugins/site_functions.py @@ -141,7 +141,7 @@ def SetupWordpress(self, data): Log.info(self, "Downloading Wordpress...", end='') EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEShellExec.cmd_exec(self, "wp --allow-root core download") - Log.info("[Done]") + Log.info(self, "[Done]") if not (data['ee_db_name'] and data['ee_db_user'] and data['ee_db_pass']): data = SetupDatabase(self, data) diff --git a/ee/core/logging.py b/ee/core/logging.py index 5feb15e1..56847a38 100644 --- a/ee/core/logging.py +++ b/ee/core/logging.py @@ -11,6 +11,7 @@ class Log: UNDERLINE = '\033[4m' def error(self, msg): + print(Log.FAIL + msg + Log.ENDC) self.app.log.error(Log.FAIL + msg + Log.ENDC) self.app.close(1) From b5005967a724923e128e54fcca8452b8bae05e66 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Fri, 16 Jan 2015 16:07:37 +0530 Subject: [PATCH 8/9] Added package insttallation during site creation, finally :) --- ee/cli/plugins/site.py | 23 +-- ee/cli/plugins/site_functions.py | 41 ++++- ee/cli/plugins/stack.py | 288 ++++++++++++++++--------------- 3 files changed, 202 insertions(+), 150 deletions(-) diff --git a/ee/cli/plugins/site.py b/ee/cli/plugins/site.py index 21505028..784bb5f0 100644 --- a/ee/cli/plugins/site.py +++ b/ee/cli/plugins/site.py @@ -216,7 +216,7 @@ class EESiteCreateController(CementBaseController): stype = 'html' cache = 'basic' - #PHP + # PHP if (self.app.pargs.php and not (self.app.pargs.html or self.app.pargs.mysql or self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or self.app.pargs.wpsc or @@ -228,7 +228,7 @@ class EESiteCreateController(CementBaseController): wpsubdir=False, webroot=ee_site_webroot) stype = 'php' cache = 'basic' - #MySQL + # MySQL if (self.app.pargs.mysql and not (self.app.pargs.html or self.app.pargs.php or self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or self.app.pargs.wpsc or @@ -242,7 +242,7 @@ class EESiteCreateController(CementBaseController): ee_db_host='') stype = 'mysql' cache = 'basic' - #WP + # WP 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.php or self.app.pargs.mysql or @@ -296,7 +296,7 @@ class EESiteCreateController(CementBaseController): stype = 'wp' cache = 'wpsc' - #WPSUBDIR + # WPSUBDIR 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.wpsubdomain or self.app.pargs.wp)): @@ -348,7 +348,7 @@ class EESiteCreateController(CementBaseController): stype = 'wpsubdir' cache = 'wpsc' - #WPSUBDOAIN + # WPSUBDOAIN 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.wpsubdir or self.app.pargs.wp)): @@ -401,6 +401,9 @@ class EESiteCreateController(CementBaseController): stype = 'wpsubdomain' cache = 'wpsc' + # Check rerequired packages are installed or not + site_package_check(self, stype) + # setup NGINX configuration, and webroot SetupDomain(self, data) # Setup database for MySQL site @@ -498,7 +501,7 @@ class EESiteUpdateController(CementBaseController): self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)): pass - #PHP + # PHP if (self.app.pargs.php and not (self.app.pargs.html or self.app.pargs.mysql or self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or self.app.pargs.wpsc or @@ -517,7 +520,7 @@ class EESiteUpdateController(CementBaseController): stype = 'php' cache = 'basic' - #MySQL + # MySQL if (self.app.pargs.mysql and not (self.app.pargs.html or self.app.pargs.php or self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or self.app.pargs.wpsc or @@ -537,7 +540,7 @@ class EESiteUpdateController(CementBaseController): stype = 'mysql' cache = 'basic' - #WP + # WP 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.php or self.app.pargs.mysql or @@ -616,7 +619,7 @@ class EESiteUpdateController(CementBaseController): stype = 'wp' cache = 'wpsc' - #WPSUBDIR + # WPSUBDIR 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.wpsubdomain or self.app.pargs.wp)): @@ -860,7 +863,7 @@ class EESiteUpdateController(CementBaseController): msg="{0} updated with {1} {2}" .format(ee_www_domain, stype, cache)) # Setup Permissions for webroot - #SetWebrootPermissions(self, data['webroot']) + # SetWebrootPermissions(self, data['webroot']) updateSiteInfo(self, ee_www_domain, stype=stype, cache=cache) Log.info(self, "Successfully updated site" diff --git a/ee/cli/plugins/site_functions.py b/ee/cli/plugins/site_functions.py index bde91af8..0bc7fa5e 100644 --- a/ee/cli/plugins/site_functions.py +++ b/ee/cli/plugins/site_functions.py @@ -3,10 +3,12 @@ import random import string import sys import getpass +from ee.cli.plugins.stack import EEStackController from ee.core.fileutils import EEFileUtils from ee.core.mysql import EEMysql from ee.core.shellexec import EEShellExec from ee.core.variables import EEVariables +from ee.core.aptget import EEAptGet from ee.core.logging import Log import glob @@ -178,9 +180,9 @@ def SetupWordpress(self, data): + "--dbuser={0} --dbpass={1} " "--extra-php< 1024: - apt_packages = apt_packages + EEVariables.ee_mailscanner - else: - Log.info(self, "Mail server is allready installed") - - if self.app.pargs.nginx: - Log.debug(self, "Setting apt_packages variable for Nginx") - if not EEAptGet.is_installed(self, 'nginx-common'): - apt_packages = apt_packages + EEVariables.ee_nginx - else: - Log.info(self, "Nginx allready installed") - if self.app.pargs.php: - Log.debug(self, "Setting apt_packages variable for PHP") - if not EEAptGet.is_installed(self, 'php5-fpm'): - apt_packages = apt_packages + EEVariables.ee_php - else: - Log.info(self, "PHP allready installed") - if self.app.pargs.mysql: - Log.debug(self, "Setting apt_packages variable for MySQL") - if not EEShellExec.cmd_exec(self, "mysqladmin ping"): - apt_packages = apt_packages + EEVariables.ee_mysql - else: - Log.info(self, "MySQL connection is allready alive") - if self.app.pargs.postfix: - Log.debug(self, "Setting apt_packages variable for PostFix") - if not EEAptGet.is_installed(self, 'postfix'): - apt_packages = apt_packages + EEVariables.ee_postfix - else: - Log.info(self, "Postfix is allready installed") - if self.app.pargs.wpcli: - Log.debug(self, "Setting packages variable for WPCLI") - if not EEShellExec.cmd_exec(self, "which wp"): - packages = packages + [["https://github.com/wp-cli/wp-cli/" - "releases/download/v0.17.1/" - "wp-cli.phar", "/usr/bin/wp", - "WP_CLI"]] - else: - Log.info(self, "WP-CLI is allready installed") - if self.app.pargs.phpmyadmin: - Log.debug(self, "Setting packages varible for phpMyAdmin ") - packages = packages + [["https://github.com/phpmyadmin/phpmyadmin" - "/archive/STABLE.tar.gz", - "/tmp/pma.tar.gz", "phpMyAdmin"]] - - if self.app.pargs.adminer: - Log.debug(self, "Setting packages variable for Adminer ") - packages = packages + [["http://downloads.sourceforge.net/adminer" - "/adminer-4.1.0.php", "/var/www/22222/" - "htdocs/db/adminer/index.php", "Adminer"]] + try: + if self.app.pargs.web: + Log.debug(self, "Setting apt_packages variable for Nginx ,PHP" + " ,MySQL ") + self.app.pargs.nginx = True + self.app.pargs.php = True + self.app.pargs.mysql = True + self.app.pargs.wpcli = True + self.app.pargs.postfix = True + + if self.app.pargs.admin: + self.app.pargs.nginx = True + self.app.pargs.php = True + self.app.pargs.mysql = True + self.app.pargs.adminer = True + self.app.pargs.phpmyadmin = True + self.app.pargs.utils = True + + if self.app.pargs.mail: + self.app.pargs.nginx = True + self.app.pargs.php = True + self.app.pargs.mysql = True + self.app.pargs.postfix = True + + if not EEAptGet.is_installed(self, 'dovecot-core'): + Log.debug(self, "Setting apt_packages variable for mail") + apt_packages = apt_packages + EEVariables.ee_mail + packages = packages + [["https://github.com/opensolutions/" + "ViMbAdmin/archive/3.0.10.tar.gz", + "/tmp/vimbadmin.tar.gz", + "ViMbAdmin"], + ["https://github.com/roundcube/" + "roundcubemail/releases/download/" + "1.0.4/roundcubemail-1.0.4.tar.gz", + "/tmp/roundcube.tar.gz", + "Roundcube"]] + + if EEVariables.ee_ram > 1024: + apt_packages = (apt_packages + + EEVariables.ee_mailscanner) + else: + Log.info(self, "Mail server is allready installed") - if self.app.pargs.utils: - Log.debug(self, "Setting packages variable for utils") - packages = packages + [["http://phpmemcacheadmin.googlecode.com/" - "files/phpMemcachedAdmin-1.2.2" - "-r262.tar.gz", '/tmp/memcache.tar.gz', - 'phpMemcachedAdmin'], - ["https://raw.githubusercontent.com/rtCamp/" - "eeadmin/master/cache/nginx/clean.php", - "/var/www/22222/htdocs/cache/" - "nginx/clean.php", "clean.php"], - ["https://raw.github.com/rlerdorf/opcache-" - "status/master/opcache.php", - "/var/www/22222/htdocs/cache/" - "opcache/opcache.php", "opcache.php"], - ["https://raw.github.com/amnuts/opcache-gui" - "/master/index.php", - "/var/www/22222/htdocs/" - "cache/opcache/opgui.php", "index.php"], - ["https://gist.github.com/ck-on/4959032/raw" - "/0b871b345fd6cfcd6d2be030c1f33d1ad6a475cb" - "/ocp.php", - "/var/www/22222/htdocs/cache/" - "opcache/ocp.php", "ocp.php"], - ["https://github.com/jokkedk/webgrind/" - "archive/master.tar.gz", - '/tmp/webgrind.tar.gz', 'Webgrind'], - ["http://bazaar.launchpad.net/~percona-too" - "lkit-dev/percona-toolkit/2.1/download/he" - "ad:/ptquerydigest-20110624220137-or26tn4" - "expb9ul2a-16/pt-query-digest", - "/usr/bin/pt-query-advisor", - "pt-query-digest"], - ["https://github.com/box/Anemometer/archive" - "/master.tar.gz", - '/tmp/anemometer.tar.gz', 'Anemometer'] - ] - Log.debug(self, "Calling pre_pref ") - self.pre_pref(apt_packages) - if len(apt_packages): - EESwap.add(self) - Log.debug(self, "Updating apt-cache") - EEAptGet.update(self) - Log.debug(self, "Installing all apt_packages") - print(apt_packages) - EEAptGet.install(self, apt_packages) - if len(packages): - Log.debug(self, "Downloading all packages") - EEDownload.download(self, packages) - Log.debug(self, "Calling post_pref") - self.post_pref(apt_packages, packages) - if len(self.msg): - for msg in self.msg: - Log.info(self, msg) - Log.info(self, "Successfully installed packages") + if self.app.pargs.nginx: + Log.debug(self, "Setting apt_packages variable for Nginx") + if not EEAptGet.is_installed(self, 'nginx-common'): + apt_packages = apt_packages + EEVariables.ee_nginx + else: + Log.info(self, "Nginx allready installed") + if self.app.pargs.php: + Log.debug(self, "Setting apt_packages variable for PHP") + if not EEAptGet.is_installed(self, 'php5-fpm'): + apt_packages = apt_packages + EEVariables.ee_php + else: + Log.info(self, "PHP allready installed") + if self.app.pargs.mysql: + Log.debug(self, "Setting apt_packages variable for MySQL") + if not EEShellExec.cmd_exec(self, "mysqladmin ping"): + apt_packages = apt_packages + EEVariables.ee_mysql + else: + Log.info(self, "MySQL connection is allready alive") + if self.app.pargs.postfix: + Log.debug(self, "Setting apt_packages variable for PostFix") + if not EEAptGet.is_installed(self, 'postfix'): + apt_packages = apt_packages + EEVariables.ee_postfix + else: + Log.info(self, "Postfix is allready installed") + if self.app.pargs.wpcli: + Log.debug(self, "Setting packages variable for WPCLI") + if not EEShellExec.cmd_exec(self, "which wp"): + packages = packages + [["https://github.com/wp-cli/wp-cli/" + "releases/download/v0.17.1/" + "wp-cli.phar", "/usr/bin/wp", + "WP_CLI"]] + else: + Log.info(self, "WP-CLI is allready installed") + if self.app.pargs.phpmyadmin: + Log.debug(self, "Setting packages varible for phpMyAdmin ") + packages = packages + [["https://github.com/phpmyadmin/" + "phpmyadmin/archive/STABLE.tar.gz", + "/tmp/pma.tar.gz", "phpMyAdmin"]] + + if self.app.pargs.adminer: + Log.debug(self, "Setting packages variable for Adminer ") + packages = packages + [["http://downloads.sourceforge.net/" + "adminer/adminer-4.1.0.php", + "/var/www/22222/" + "htdocs/db/adminer/index.php", + "Adminer"]] + + if self.app.pargs.utils: + Log.debug(self, "Setting packages variable for utils") + packages = packages + [["http://phpmemcacheadmin.googlecode" + ".com/files/phpMemcachedAdmin-1.2.2" + "-r262.tar.gz", '/tmp/memcache.tar.gz', + 'phpMemcachedAdmin'], + ["https://raw.githubusercontent.com" + "/rtCamp/eeadmin/master/cache/nginx/" + "clean.php", + "/var/www/22222/htdocs/cache/" + "nginx/clean.php", "clean.php"], + ["https://raw.github.com/rlerdorf/" + "opcache-status/master/opcache.php", + "/var/www/22222/htdocs/cache/" + "opcache/opcache.php", "opcache.php"], + ["https://raw.github.com/amnuts/" + "opcache-gui/master/index.php", + "/var/www/22222/htdocs/" + "cache/opcache/opgui.php", + "index.php"], + ["https://gist.github.com/ck-on/4959032" + "/raw/0b871b345fd6cfcd6d2be030c1f33d1" + "ad6a475cb/ocp.php", + "/var/www/22222/htdocs/cache/" + "opcache/ocp.php", "ocp.php"], + ["https://github.com/jokkedk/webgrind/" + "archive/master.tar.gz", + '/tmp/webgrind.tar.gz', 'Webgrind'], + ["http://bazaar.launchpad.net/~" + "percona-toolkit-dev/percona-toolkit/" + "2.1/download/head:/ptquerydigest-" + "20110624220137-or26tn4" + "expb9ul2a-16/pt-query-digest", + "/usr/bin/pt-query-advisor", + "pt-query-digest"], + ["https://github.com/box/Anemometer/" + "archive/master.tar.gz", + '/tmp/anemometer.tar.gz', 'Anemometer'] + ] + except Exception as e: + pass + + if len(apt_packages) or len(packages): + Log.debug(self, "Calling pre_pref ") + self.pre_pref(apt_packages) + if len(apt_packages): + EESwap.add(self) + Log.debug(self, "Updating apt-cache") + EEAptGet.update(self) + Log.debug(self, "Installing all apt_packages") + print(apt_packages) + EEAptGet.install(self, apt_packages) + if len(packages): + Log.debug(self, "Downloading all packages") + EEDownload.download(self, packages) + Log.debug(self, "Calling post_pref") + self.post_pref(apt_packages, packages) + if len(self.msg): + for msg in self.msg: + Log.info(self, msg) + Log.info(self, "Successfully installed packages") @expose() def remove(self): From 5d8923e67ad857e3a26a43a239a5f94c2fcbedc1 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Fri, 16 Jan 2015 16:27:44 +0530 Subject: [PATCH 9/9] updated messages --- ee/cli/plugins/site.py | 165 ++++++++++++++++++------------- ee/cli/plugins/site_functions.py | 117 +++++++++++++--------- 2 files changed, 167 insertions(+), 115 deletions(-) diff --git a/ee/cli/plugins/site.py b/ee/cli/plugins/site.py index 21505028..cdaa284b 100644 --- a/ee/cli/plugins/site.py +++ b/ee/cli/plugins/site.py @@ -35,8 +35,7 @@ class EESiteController(CementBaseController): @expose(hide=True) def default(self): - # TODO Default action for ee site command - print("Inside EESiteController.default().") + self.app.args.print_help() @expose(help="enable site example.com") def enable(self): @@ -44,12 +43,13 @@ class EESiteController(CementBaseController): if os.path.isfile('/etc/nginx/sites-available/{0}' .format(ee_domain)): EEFileUtils.create_symlink(self, - ['/etc/nginx/sites-available/{0}.conf' - .format(ee_domain_name), - '/etc/nginx/sites-enabled/{0}.conf' - .format(ee_domain_name)]) + ['/etc/nginx/sites-available/{0}' + .format(ee_domain), + '/etc/nginx/sites-enabled/{0}' + .format(ee_domain)]) + updateSiteInfo(self, ee_domain, enabled=True) else: - Log.error(self, "!! site {0} does not exists".format(ee_domain)) + Log.error(self, " site {0} does not exists".format(ee_domain)) @expose(help="disable site example.com") def disable(self): @@ -57,12 +57,11 @@ class EESiteController(CementBaseController): if os.path.isfile('/etc/nginx/sites-available/{0}' .format(ee_domain)): EEFileUtils.remove_symlink(self, - ['/etc/nginx/sites-available/{0}.conf' - .format(ee_domain_name), - '/etc/nginx/sites-enabled/{0}.conf' - .format(ee_domain_name)]) + '/etc/nginx/sites-enabled/{0}' + .format(ee_domain)) + updateSiteInfo(self, ee_domain, enabled=False) else: - Log.error(self, "!! site {0} does not exists".format(ee_domain)) + Log.error(self, " site {0} does not exists".format(ee_domain)) @expose(help="get example.com information") def info(self): @@ -94,7 +93,7 @@ class EESiteController(CementBaseController): dbpass=ee_db_pass) self.app.render((data), 'siteinfo.mustache') else: - Log.error(self, "!! site {0} does not exists".format(ee_domain)) + Log.error(self, " site {0} does not exists".format(ee_domain)) @expose(help="Monitor example.com logs") def log(self): @@ -104,7 +103,7 @@ class EESiteController(CementBaseController): EEShellExec.cmd_exec(self, 'tail -f /var/log/nginx/{0}.*.log' .format(ee_domain)) else: - Log.error(self, "!! site {0} does not exists".format(ee_domain)) + Log.error(self, " site {0} does not exists".format(ee_domain)) @expose(help="Edit example.com's nginx configuration") def edit(self): @@ -120,7 +119,7 @@ class EESiteController(CementBaseController): # Reload NGINX EEService.reload_service(self, 'nginx') else: - Log.error(self, "!! site {0} does not exists".format(ee_domain)) + Log.error(self, " site {0} does not exists".format(ee_domain)) @expose(help="Display example.com's nginx configuration") def show(self): @@ -135,14 +134,9 @@ class EESiteController(CementBaseController): print(text) f.close() else: - Log.error(self, "!! site {0} does not exists".format(ee_domain)) + Log.error(self, " site {0} does not exists".format(ee_domain)) - @expose(help="list sites currently available") - def list(self): - # TODO Write code for ee site list command here - print("Inside EESiteController.list().") - - @expose(help="change to example.com's webroot") + @expose(help="change directory to site webroot") def cd(self): (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) @@ -154,7 +148,7 @@ class EESiteController(CementBaseController): subprocess.call(['bash']) except OSError as e: Log.debug(self, "{0}{1}".format(e.errno, e.strerror)) - Log.error(self, "!! cannot change directory") + Log.error(self, " cannot change directory") class EESiteCreateController(CementBaseController): @@ -166,31 +160,35 @@ class EESiteCreateController(CementBaseController): help of the following subcommands' arguments = [ (['site_name'], - dict(help='the notorious foo option')), + dict(help='domain name for the site to be created.')), (['--html'], - dict(help="html site", action='store_true')), + dict(help="create html site", action='store_true')), (['--php'], - dict(help="php site", action='store_true')), + dict(help="create php site", action='store_true')), (['--mysql'], - dict(help="mysql site", action='store_true')), + dict(help="create mysql site", action='store_true')), (['--wp'], - dict(help="wordpress site", action='store_true')), + dict(help="create wordpress single site", + action='store_true')), (['--wpsubdir'], - dict(help="wpsubdir site", action='store_true')), + dict(help="create wordpress multisite with subdirectory setup", + action='store_true')), (['--wpsubdomain'], - dict(help="wpsubdomain site", action='store_true')), + dict(help="create wordpress multisite with subdomain setup", + action='store_true')), (['--w3tc'], - dict(help="w3tc", action='store_true')), + dict(help="create wordpress single/multi site with w3tc cache", + action='store_true')), (['--wpfc'], - dict(help="wpfc", action='store_true')), + dict(help="create wordpress single/multi site with wpfc cache", + action='store_true')), (['--wpsc'], - dict(help="wpsc", action='store_true')), + dict(help="create wordpress single/multi site with wpsc cache", + action='store_true')), ] @expose(hide=True) def default(self): - # TODO Default action for ee site command - # data = dict(foo='EESiteCreateController.default().') # self.app.render((data), 'default.mustache') # Check domain name validation (ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name) @@ -199,7 +197,7 @@ class EESiteCreateController(CementBaseController): # Check if doain previously exists or not if os.path.isfile('/etc/nginx/sites-available/{0}' .format(ee_domain)): - Log.error(self, "!! site {0} already exists" + Log.error(self, " site {0} already exists" .format(ee_domain)) # setup nginx configuration for site @@ -401,11 +399,15 @@ class EESiteCreateController(CementBaseController): stype = 'wpsubdomain' cache = 'wpsc' + if not data: + self.app.args.print_help() + self.app.close(1) + # setup NGINX configuration, and webroot - SetupDomain(self, data) + setupDomain(self, data) # Setup database for MySQL site if 'ee_db_name' in data.keys() and not data['wp']: - data = SetupDatabase(self, data) + data = setupDatabase(self, data) try: eedbconfig = open("{0}/ee-config.php".format(ee_site_webroot), 'w') @@ -422,11 +424,11 @@ class EESiteCreateController(CementBaseController): except IOError as e: Log.debug(self, "{2} ({0}): {1}" .format(e.errno, e.strerror, ee_domain)) - Log.error(self, "!! Unable to create ee-config.php for ") + Log.error(self, " Unable to create ee-config.php for ") # Setup WordPress if Wordpress site if data['wp']: - ee_wp_creds = SetupWordpress(self, data) + ee_wp_creds = setupWordpress(self, data) # Service Nginx Reload EEService.reload_service(self, 'nginx') @@ -485,7 +487,7 @@ class EESiteUpdateController(CementBaseController): check_site = getSiteInfo(self, ee_domain) if check_site is None: - Log.error(self, "!! Site {0} does not exist.".format(ee_domain)) + Log.error(self, " Site {0} does not exist.".format(ee_domain)) else: oldsitetype = check_site.site_type oldcachetype = check_site.cache_type @@ -506,7 +508,7 @@ class EESiteUpdateController(CementBaseController): if oldsitetype != 'html': - Log.error(self, "!! Cannot update {0} {1} to php" + Log.error(self, " Cannot update {0} {1} to php" .format(ee_domain, oldsitetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, @@ -524,7 +526,7 @@ class EESiteUpdateController(CementBaseController): self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)): if oldsitetype not in ['html', 'php']: - Log.error(self, "!! Cannot update {0}, {1} to mysql" + Log.error(self, " Cannot update {0}, {1} to mysql" .format(ee_domain, oldsitetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, @@ -548,7 +550,7 @@ class EESiteUpdateController(CementBaseController): if ((oldsitetype in ['html', 'php', 'mysql', 'wp']) and (oldcachetype not in ['w3tc', 'wpfc', 'wpsc'])): print(oldsitetype, oldcachetype) - Log.error(self, "!! Cannot update {0}, {1} {2} to wp basic" + Log.error(self, " Cannot update {0}, {1} {2} to wp basic" .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, @@ -566,7 +568,7 @@ class EESiteUpdateController(CementBaseController): if (oldsitetype in ['html', 'php', 'mysql', 'wp'] and oldcachetype not in ['basic', 'wpfc', 'wpsc']): - Log.error(self, "!! Cannot update {0}, {1} {2}to wp w3tc" + Log.error(self, " Cannot update {0}, {1} {2}to wp w3tc" .format(ee_domain, oldsitetype, oldcachetype)) data = dict(site_name=ee_domain, www_domain=ee_www_domain, @@ -625,7 +627,7 @@ class EESiteUpdateController(CementBaseController): if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir'] and oldcachetype not in ['w3tc', 'wpfc', 'wpsc']): - Log.error(self, "!! Cannot update {0}, {1} {2} " + Log.error(self, " Cannot update {0}, {1} {2} " "to wpsubdir basic" .format(ee_domain, oldsitetype, oldcachetype)) @@ -644,7 +646,7 @@ class EESiteUpdateController(CementBaseController): if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir'] and oldcachetype not in ['basic', 'wpfc', 'wpsc']): - Log.error(self, "!! Cannot update {0} {1} {2}" + Log.error(self, " Cannot update {0} {1} {2}" "to wpsubdir w3tc" .format(ee_domain, oldsitetype, oldcachetype)) @@ -664,7 +666,7 @@ class EESiteUpdateController(CementBaseController): if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir'] and oldcachetype not in ['basic', 'w3tc', 'wpsc']): - Log.error(self, "!! Cannot update {0} {1} {2}" + Log.error(self, " Cannot update {0} {1} {2}" " to wpsubdir wpfc" .format(ee_domain, oldsitetype, oldcachetype)) @@ -683,7 +685,7 @@ class EESiteUpdateController(CementBaseController): if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdir'] and oldcachetype not in ['basic', 'w3tc', 'wpfc']): - Log.error(self, "!! Cannot update {0} {1} {2}" + Log.error(self, " Cannot update {0} {1} {2}" " to wpsubdir wpsc" .format(ee_domain, oldsitetype, oldcachetype)) @@ -703,7 +705,7 @@ class EESiteUpdateController(CementBaseController): if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdomain'] and oldcachetype not in ['w3tc', 'wpfc', 'wpsc']): - Log.error(self, "!! Cannot update {0} {1} {2}" + Log.error(self, " Cannot update {0} {1} {2}" " to wpsubdomain basic" .format(ee_domain, oldsitetype, oldcachetype)) @@ -724,7 +726,7 @@ class EESiteUpdateController(CementBaseController): if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdomain'] and oldcachetype not in ['basic', 'wpfc', 'wpsc']): - Log.error(self, "!! Cannot update {0}, {1} {2}" + Log.error(self, " Cannot update {0}, {1} {2}" " to wpsubdomain w3tc" .format(ee_domain, oldsitetype, oldcachetype)) @@ -745,7 +747,7 @@ class EESiteUpdateController(CementBaseController): if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdomain'] and oldcachetype not in ['basic', 'w3tc', 'wpsc']): - Log.error(self, "!! Cannot update {0}, {1} {2} " + Log.error(self, " Cannot update {0}, {1} {2} " "to wpsubdomain wpfc" .format(ee_domain, oldsitetype, oldcachetype)) @@ -766,7 +768,7 @@ class EESiteUpdateController(CementBaseController): if (oldsitetype in ['html', 'php', 'mysql', 'wp', 'wpsubdomain'] and oldcachetype not in ['basic', 'w3tc', 'wpfc']): - Log.error(self, "!! Cannot update {0}, {1} {2}" + Log.error(self, " Cannot update {0}, {1} {2}" " to wpsubdomain wpsc" .format(ee_domain, oldsitetype, oldcachetype)) @@ -782,16 +784,16 @@ class EESiteUpdateController(CementBaseController): cache = 'wpsc' if not data: - Log.error(self, "!! Cannot update" + Log.error(self, " Cannot update" .format(ee_domain)) siteBackup(self, data) # TODO Check for required packages before update # setup NGINX configuration, and webroot - SetupDomain(self, data) + setupDomain(self, data) if 'ee_db_name' in data.keys() and not data['wp']: - data = SetupDatabase(self, data) + data = setupDatabase(self, data) try: eedbconfig = open("{0}/ee-config.php".format(ee_site_webroot), 'w') @@ -805,7 +807,7 @@ class EESiteUpdateController(CementBaseController): data['ee_db_host'])) eedbconfig.close() except IOError as e: - Log.error(self, "!! Unable to create ee-config.php for " + Log.error(self, " Unable to create ee-config.php for " "{0}" .format(ee_domain)) Log.debug(self, "{0} {1}".format(e.errno, e.strerror)) @@ -831,27 +833,27 @@ class EESiteUpdateController(CementBaseController): # Setup WordPress if old sites are html/php/mysql sites if data['wp'] and oldsitetype in ['html', 'php', 'mysql']: - ee_wp_creds = SetupWordpress(self, data) + ee_wp_creds = setupWordpress(self, data) # Uninstall unnecessary plugins if oldsitetype in ['wp', 'wpsubdir', 'wpsubdomain']: # Setup WordPress Network if update option is multisite # and oldsite is WordPress single site if data['multisite'] and oldsitetype == 'wp': - SetupWordpressNetwork(self, data) + setupWordpressNetwork(self, data) if (oldcachetype == 'w3tc' or oldcachetype == 'wpfc' and not data['w3tc', 'wpfc']): - UnInstallWP_Plugin(self, 'w3-total-cache', data) + uninstallWP_Plugin(self, 'w3-total-cache', data) if oldcachetype == 'wpsc' and not data['wpsc']: - UnInstallWP_Plugin(self, 'wp-super-cache', data) + uninstallWP_Plugin(self, 'wp-super-cache', data) - if oldcachetype != 'w3tc' or oldcachetype != 'wpfc'and data['w3tc']: - InstallWP_Plugin(self, 'w3-total-cache', data) + if (oldcachetype != 'w3tc' or oldcachetype != 'wpfc') and data['w3tc']: + installWP_Plugin(self, 'w3-total-cache', data) if oldcachetype != 'wpsc' and data['wpsc']: - InstallWP_Plugin(self, 'wp-super-cache', data) + installWP_Plugin(self, 'wp-super-cache', data) # Service Nginx Reload EEService.reload_service(self, 'nginx') @@ -941,7 +943,7 @@ class EESiteDeleteController(CementBaseController): .format(ee_domain)) deleteSiteInfo(self, ee_domain) else: - Log.error(self, "!! site {0} does not exists".format(ee_domain)) + Log.error(self, " site {0} does not exists".format(ee_domain)) @expose(hide=True) def deleteDB(self, webroot): @@ -972,19 +974,48 @@ class EESiteDeleteController(CementBaseController): EEMysql.execute(self, "flush privileges") except Exception as e: - Log.error(self, "!! Error occured while deleting database") + Log.error(self, " Error occured while deleting database") @expose(hide=True) def deleteWebRoot(self, webroot): EEFileUtils.rm(self, webroot) +class EESiteListController(CementBaseController): + class Meta: + label = 'list' + stacked_on = 'site' + stacked_type = 'nested' + description = 'list websites' + arguments = [ + (['--enabled'], + dict(help='list enabled sites', action='store_true')), + (['--disabled'], + dict(help="list disabled sites", action='store_true')), + ] + + @expose(help="delete example.com") + def default(self): + sites = getAllsites(self) + if not sites: + self.app.close(1) + + if self.app.pargs.enabled: + for site in sites: + if site.is_enabled: + Log.info(self, "{0}".format(site.sitename)) + elif self.app.pargs.disabled: + for site in sites: + if not site.is_enabled: + Log.info(self, "{0}".format(site.sitename)) + + def load(app): # register the plugin class.. this only happens if the plugin is enabled handler.register(EESiteController) handler.register(EESiteCreateController) handler.register(EESiteUpdateController) handler.register(EESiteDeleteController) - + handler.register(EESiteListController) # register a hook (function) to run after arguments are parsed. hook.register('post_argument_parsing', ee_site_hook) diff --git a/ee/cli/plugins/site_functions.py b/ee/cli/plugins/site_functions.py index bde91af8..b636a952 100644 --- a/ee/cli/plugins/site_functions.py +++ b/ee/cli/plugins/site_functions.py @@ -11,11 +11,11 @@ from ee.core.logging import Log import glob -def SetupDomain(self, data): +def setupDomain(self, data): ee_domain_name = data['site_name'] ee_site_webroot = data['webroot'] - self.app.log.info("Setting up NGINX config {0} ...".format(ee_domain_name)) + Log.info(self, "Setting up NGINX configuration ", end='') # write nginx config for file try: ee_site_nginx_conf = open('/etc/nginx/sites-available/{0}' @@ -25,12 +25,12 @@ def SetupDomain(self, data): out=ee_site_nginx_conf) ee_site_nginx_conf.close() except IOError as e: - Log.error(self, "Unable to create nginx conf for {2} ({0}): {1}" - .format(e.errno, e.strerror, ee_domain_name)) - sys.exit(1) + Log.debug(self, "{0}".format(e)) + Log.error(self, "\nUnable to create NGINX configuration") except Exception as e: - Log.error(self, "{0}".format(e)) - sys.exit(1) + Log.debug(self, "{0}".format(e)) + Log.error(self, "\nUnable to create NGINX configuration") + Log.info(self, "[Done]") # create symbolic link for EEFileUtils.create_symlink(self, ['/etc/nginx/sites-available/{0}' @@ -39,14 +39,15 @@ def SetupDomain(self, data): .format(ee_domain_name)]) # Creating htdocs & logs directory + Log.info(self, "Setting up webroot ", end='') try: if not os.path.exists('{0}/htdocs'.format(ee_site_webroot)): os.makedirs('{0}/htdocs'.format(ee_site_webroot)) if not os.path.exists('{0}/logs'.format(ee_site_webroot)): os.makedirs('{0}/logs'.format(ee_site_webroot)) except Exception as e: - Log.error(self, "{0}".format(e)) - sys.exit(1) + Log.debug(self, "{0}".format(e)) + Log.error(self, "\nUnable to setup webroot") EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.access.log' .format(ee_domain_name), @@ -56,9 +57,10 @@ def SetupDomain(self, data): .format(ee_domain_name), '{0}/logs/error.log' .format(ee_site_webroot)]) + Log.info(self, "[Done]") -def SetupDatabase(self, data): +def setupDatabase(self, data): ee_domain_name = data['site_name'] ee_random = (''.join(random.sample(string.ascii_uppercase + string.ascii_lowercase + string.digits, 15))) @@ -75,8 +77,8 @@ def SetupDatabase(self, data): ee_db_name = input('Enter the MySQL database name [{0}]:' .format(ee_replace_dot)) except EOFError as e: - Log.error(self, "{0} {1}".format(e.errorno, e.strerror)) - sys.exit(0) + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to input database name") if not ee_db_name: ee_db_name = ee_replace_dot @@ -88,8 +90,8 @@ def SetupDatabase(self, data): ee_db_password = input('Enter the MySQL database password [{0}]: ' .format(ee_random)) except EOFError as e: - Log.error(self, "{0} {1}".format(e.errorno, e.strerror)) - sys.exit(1) + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to input database credentials") if not ee_db_username: ee_db_username = ee_replace_dot @@ -97,26 +99,31 @@ def SetupDatabase(self, data): ee_db_password = ee_random if len(ee_db_username) > 16: - self.app.log.info('Autofix MySQL username (ERROR 1470 (HY000)),' - ' please wait...') + Log.info(self, 'Autofix MySQL username (ERROR 1470 (HY000)),' + ' please wait...') ee_random10 = (''.join(random.sample(string.ascii_uppercase + string.ascii_lowercase + string.digits, 10))) ee_db_name = (ee_db_name[0:6] + ee_random10) # create MySQL database - self.app.log.info("Setting Up Database ...") + Log.info(self, "Setting Up Database ", end='') + Log.debug(self, "creating databse {0}".format(ee_db_name)) EEMysql.execute(self, "create database {0}" .format(ee_db_name)) # Create MySQL User + Log.debug(self, "creating user {0}".format(ee_db_username)) EEMysql.execute(self, "create user {0}@{1} identified by '{2}'" .format(ee_db_username, ee_mysql_host, ee_db_password)) # Grant permission + Log.debug(self, "setting up user privileges") EEMysql.execute(self, "grant all privileges on {0}.* to {1}@{2}" .format(ee_db_name, ee_db_username, ee_mysql_host)) + Log.info(self, "[Done]") + data['ee_db_name'] = ee_db_name data['ee_db_user'] = ee_db_username data['ee_db_pass'] = ee_db_password @@ -124,7 +131,7 @@ def SetupDatabase(self, data): return(data) -def SetupWordpress(self, data): +def setupWordpress(self, data): ee_domain_name = data['site_name'] ee_site_webroot = data['webroot'] prompt_wpprefix = self.app.config.get('wordpress', 'prefix') @@ -138,25 +145,25 @@ def SetupWordpress(self, data): ee_wp_user = '' ee_wp_pass = '' - Log.info(self, "Downloading Wordpress...", end='') + Log.info(self, "Downloading Wordpress ", end='') EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEShellExec.cmd_exec(self, "wp --allow-root core download") Log.info(self, "[Done]") if not (data['ee_db_name'] and data['ee_db_user'] and data['ee_db_pass']): - data = SetupDatabase(self, data) + data = setupDatabase(self, data) if prompt_wpprefix == 'True' or prompt_wpprefix == 'true': try: ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: ' .format(ee_replace_dot)) while re.match('^[A-Za-z0-9_]*$', ee_wp_prefix): - self.app.log.warn("table prefix can only " - "contain numbers, letters, and underscores") + Log.warn(self, "table prefix can only " + "contain numbers, letters, and underscores") ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: ' ) except EOFError as e: - Log.error(self, "{0} {1}".format(e.errorno, e.strerror)) - sys.exit(1) + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to input table prefix") if not ee_wp_prefix: ee_wp_prefix = 'wp_' @@ -164,14 +171,16 @@ def SetupWordpress(self, data): # Modify wp-config.php & move outside the webroot EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) - self.app.log.debug("Setting Up WordPress Configuration...") + Log.debug(self, "Setting up wp-config file") if not data['multisite']: + Log.debug(self, "Generating wp-config for WordPress Single site") EEShellExec.cmd_exec(self, "wp --allow-root core config " + "--dbname={0} --dbprefix={1} --dbuser={2} " .format(data['ee_db_name'], ee_wp_prefix, data['ee_db_user']) + "--dbpass={0}".format(data['ee_db_pass'])) else: + Log.debug(self, "Generating wp-config for WordPress multisite") EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root core config " + "--dbname={0} --dbprefix={1} " .format(data['ee_db_name'], ee_wp_prefix) @@ -183,16 +192,19 @@ def SetupWordpress(self, data): var2= "\n define('WPMU_ACCEL_REDIRECT', true);") ) - EEFileUtils.mvfile(self, './wp-config.php', '../') if not ee_wp_user: ee_wp_user = EEVariables.ee_user while not ee_wp_user: - self.app.log.warn("Usernames can have only alphanumeric" - "characters, spaces, underscores, hyphens," - "periods and the @ symbol.") - ee_wp_user = input('Enter WordPress username: ') + Log.warn(self, "Usernames can have only alphanumeric" + "characters, spaces, underscores, hyphens," + "periods and the @ symbol.") + try: + ee_wp_user = input('Enter WordPress username: ') + except EOFError as e: + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to input wp user name") if not ee_wp_pass: ee_wp_pass = ee_random @@ -200,11 +212,16 @@ def SetupWordpress(self, data): if not ee_wp_email: ee_wp_email = EEVariables.ee_email while not ee_wp_email: - ee_wp_email = input('Enter WordPress email: ') + try: + ee_wp_email = input('Enter WordPress email: ') + except EOFError as e: + Log.debug(self, "{0}".format(e)) + Log.error(self, "Unable to input wp user email") - self.app.log.debug("Setting up WordPress Tables, please wait...") + Log.debug(self, "setting up WordPress Tables") if not data['multisite']: + Log.debug(self, "creating tables for WordPress Single site") EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root core install " "--url={0} --title={0} --admin_name={1} " .format(data['www_domain'], ee_wp_user) @@ -212,6 +229,7 @@ def SetupWordpress(self, data): .format(ee_wp_pass, ee_wp_email), errormsg="Unable to setup WordPress Tables") else: + Log.debug(self, "creating tables for WordPress multisite") EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root " "core multisite-install " "--url={0} --title={0} --admin_name={1} " @@ -223,22 +241,22 @@ def SetupWordpress(self, data): if not data['wpsubdir'] else ''), errormsg="Unable to setup WordPress Tables") - self.app.log.debug("Updating WordPress permalink, please wait...") + Log.debug(self, "Updating WordPress permalink") EEShellExec.cmd_exec(self, " php /usr/bin/wp --allow-root " "rewrite structure " "/%year%/%monthnum%/%day%/%postname%/", errormsg="Unable to Update WordPress permalink") """Install nginx-helper plugin """ - InstallWP_Plugin(self, 'nginx-helper', data) + installWP_Plugin(self, 'nginx-helper', data) """Install Wp Super Cache""" if data['wpsc']: - InstallWP_Plugin(self, 'wp-super-cache', data) + installWP_Plugin(self, 'wp-super-cache', data) """Install W3 Total Cache""" if data['w3tc'] or data['wpfc']: - InstallWP_Plugin(self, 'w3-total-cache', data) + installWP_Plugin(self, 'w3-total-cache', data) wp_creds = dict(wp_user=ee_wp_user, wp_pass=ee_wp_pass, wp_email=ee_wp_email) @@ -246,19 +264,20 @@ def SetupWordpress(self, data): return(wp_creds) -def SetupWordpressNetwork(self, data): +def setupWordpressNetwork(self, data): ee_site_webroot = data['webroot'] EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) - Log.info(self, "Setting up WordPress Network") + Log.info(self, "Setting up WordPress Network ", end='') EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert' ' --title={0} {subdomains}' .format(data['www_domain'], subdomains='--subdomains' if not data['wpsubdir'] else '')) + Log.info(self, "Done") -def InstallWP_Plugin(self, plugin_name, data): +def installWP_Plugin(self, plugin_name, data): ee_site_webroot = data['webroot'] - self.app.log.debug("Installing plugin {0}".format(plugin_name)) + Log.debug(self, "Installing plugin {0}".format(plugin_name)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root install " "{0}".format(plugin_name), @@ -273,18 +292,18 @@ def InstallWP_Plugin(self, plugin_name, data): .format(plugin_name)) -def UnInstallWP_Plugin(self, plugin_name, data): +def uninstallWP_Plugin(self, plugin_name, data): ee_site_webroot = data['webroot'] - self.app.log.debug("Uninstalling plugin {0}".format(plugin_name)) + Log.debug(self, "Uninstalling plugin {0}".format(plugin_name)) EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root uninstall " "{0}".format(plugin_name), - errormsg="Unable to Install plugin {0}" + errormsg="Unable to UnInstall plugin {0}" .format(plugin_name)) def SetWebrootPermissions(self, webroot): - self.app.log.debug("Setting Up Permissions...") + Log.debug(self, "Setting Up Permissions...") EEFileUtils.chown(self, webroot, EEVariables.ee_php_user, EEVariables.ee_php_user, recursive=True) @@ -299,19 +318,21 @@ def siteBackup(self, data): .format(data['site_name']), backup_path) if data['currsitetype'] in ['html', 'php', 'mysql']: - Log.info(self, "Backup Webroot ...") + Log.info(self, "Backing up Webroot ", end='') EEFileUtils.mvfile(self, ee_site_webroot + '/htdocs', backup_path) + Log.info(self, "[Done]") configfiles = glob.glob(ee_site_webroot + '/*-config.php') - if EEFileUtils.isexist(self, configfiles[0]): + if configfiles and EEFileUtils.isexist(self, configfiles[0]): ee_db_name = (EEFileUtils.grep(self, configfiles[0], 'DB_NAME').split(',')[1] .split(')')[0].strip().replace('\'', '')) - Log.info(self, 'Backup Database, please wait') + Log.info(self, 'Backing up Database ', end='') EEShellExec.cmd_exec(self, "mysqldump {0} > {1}/{0}.sql" .format(ee_db_name, backup_path), - "Failed: Backup Database") + errormsg="\nFailed: Backup Database") + Log.info(self, "[Done]") # move wp-config.php/ee-config.php to backup if data['currsitetype'] in ['mysql']: EEFileUtils.mvfile(self, configfiles[0], backup_path)