From 19b3e37cec65fa4f5808d6b329154827f7d3fdfb Mon Sep 17 00:00:00 2001 From: gau1991 Date: Wed, 22 Apr 2015 19:09:29 +0530 Subject: [PATCH] Added ee stack upgrade command, fixes #458 --- ee/cli/plugins/stack.py | 4 ++- ee/cli/plugins/stack_upgrade.py | 48 +++++++++++++++++++++++++++++++ ee/core/aptget.py | 51 +++++++++++++++++++++++---------- 3 files changed, 87 insertions(+), 16 deletions(-) create mode 100644 ee/cli/plugins/stack_upgrade.py diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index f13d33a0..0235cb9c 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -27,6 +27,7 @@ import grp import codecs from ee.cli.plugins.stack_services import EEStackStatusController from ee.cli.plugins.stack_migrate import EEStackMigrateController +from ee.cli.plugins.stack_upgrade import EEStackUpgradeController from ee.core.logging import Log @@ -590,7 +591,7 @@ class EEStackController(CementBaseController): if set(EEVariables.ee_hhvm).issubset(set(apt_packages)): EEShellExec.cmd_exec(self, "update-rc.d hhvm defaults") - + EEFileUtils.searchreplace(self, "/etc/hhvm/server.ini", "9000", "8000") EEFileUtils.searchreplace(self, "/etc/nginx/hhvm.conf", @@ -1803,6 +1804,7 @@ def load(app): handler.register(EEStackController) handler.register(EEStackStatusController) handler.register(EEStackMigrateController) + handler.register(EEStackUpgradeController) # register a hook (function) to run after arguments are parsed. hook.register('post_argument_parsing', ee_stack_hook) diff --git a/ee/cli/plugins/stack_upgrade.py b/ee/cli/plugins/stack_upgrade.py new file mode 100644 index 00000000..512728fc --- /dev/null +++ b/ee/cli/plugins/stack_upgrade.py @@ -0,0 +1,48 @@ +from cement.core.controller import CementBaseController, expose +from cement.core import handler, hook +from ee.core.logging import Log +from ee.core.variables import EEVariables +from ee.core.aptget import EEAptGet +from ee.core.apt_repo import EERepo +from ee.core.services import EEService +import configparser +import os + + +class EEStackUpgradeController(CementBaseController): + class Meta: + label = 'upgrade' + stacked_on = 'stack' + stacked_type = 'nested' + description = ('UPgrade stack safely') + arguments = [ + (['--php56'], + dict(help="Upgrade to PHP5.6 from PHP5.5", + action='store_true')), + (['--no-prompt'], + dict(help="Upgrade Packages without any prompt", + action='store_true')), + + ] + + @expose(hide=True) + def upgrade_php56(self): + pass + + @expose(hide=True) + def default(self): + if ((not self.app.pargs.php56)): + # apt-get update + EEAptGet.update(self) + # display packges update + EEAptGet.check_upgrade(self) + Log.info(self, "During package update process non nginx-cached" + " parts of your site may remain down") + # Check prompt + if (self.app.pargs.no_prompt): + start_upgrade = input("Do you want to continue:[y/N]") + if start_upgrade != "Y" and start_upgrade != "y": + Log.error(self, "Not starting package update") + # Update packages + Log.info("Updating packages, please wait...") + EEAptGet.dist_upgrade(self) diff --git a/ee/core/aptget.py b/ee/core/aptget.py index 5eff0cf7..2a57d1dc 100644 --- a/ee/core/aptget.py +++ b/ee/core/aptget.py @@ -32,25 +32,46 @@ class EEAptGet(): Log.error(self, "Error while installing packages, " "apt-get exited with error") - def dist_upgrade(): + def check_upgrade(self): """ Similar to `apt-get upgrade` """ try: - apt_cache = apt.cache.Cache() - apt_cache.update() - apt_cache.open(None) - apt_cache.upgrade(True) - success = (apt_cache.commit( - apt.progress.text.AcquireProgress(), - apt.progress.base.InstallProgress())) - # apt_cache.close() - return success - except AttributeError as e: - Log.error(self, 'AttributeError: ' + str(e)) - except FetchFailedException as e: - Log.debug(self, 'SystemError: ' + str(e)) - Log.error(self, 'Unable to Fetch update') + check_update = subprocess.Popen(['apt-get upgrade -s | grep ' + '\"^Inst\" | wc -l'], + stdout=subprocess.PIPE, + shell=True).communicate()[0] + if check_upadte == b'0\n': + Log.error(self, "No package update available") + Log.info("Following package updates are available:") + subprocess.Popen("apt-get -s dist-upgrade", shell=True, + executable="/bin/bash", + stdout=sys.stdout).communicate() + + except Exception as e: + Log.error(self, "Error while installing packages, " + "apt-get exited with error") + + def dist_upgrade(self): + """ + Similar to `apt-get upgrade` + """ + try: + with open('/var/log/ee/ee.log', 'a') as f: + proc = subprocess.Popen("apt-get dist-upgrade -o " + "Dpkg::Options::=--force-confold -y", + shell=True, + stdin=None, stdout=f, stderr=f, + executable="/bin/bash") + proc.wait() + + if proc.returncode == 0: + return True + else: + Log.error(self, "Unable to run apt-get dist_upgrade") + except Exception as e: + Log.error(self, "Error while installing packages, " + "apt-get exited with error") def install(self, packages): all_packages = ' '.join(packages)