From aca34c6ec96870bb90bd4515d6041435550611cb Mon Sep 17 00:00:00 2001 From: Prabuddha Chakraborty Date: Tue, 12 Jan 2016 16:30:41 +0530 Subject: [PATCH] minimizing Downtime --- ee/cli/plugins/stack.py | 40 +++++++++++++++++++++++++--------------- ee/core/aptget.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index 490f036c..467e7fd0 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -1699,15 +1699,21 @@ class EEStackController(CementBaseController): 'operation.') ee_prompt = input("Type \"YES\" or \"yes\" to continue [n]: ") if ee_prompt == 'YES' or ee_prompt == 'yes': - EEService.stop_service(self, 'nginx') - Log.debug(self, "Removing apt_packages variable of Nginx") - Log.info(self, "Removing packages, please wait...") - EEAptGet.remove(self, EEVariables.ee_nginx_dev) - EEAptGet.auto_remove(self) - Log.info(self, "Removing repository for NGINX MAINLINE,") + Log.info(self,"Initializing... Please Wait") EERepo.remove(self, repo_url=EEVariables.ee_nginx_dev_repo) - Log.info(self, "Successfully removed packages") - apt_packages = apt_packages + EEVariables.ee_nginx + if EEAptGet.download_only(self,EEVariables.ee_nginx,EEVariables.ee_nginx_repo,EEVariables.ee_nginx_key): + EEService.stop_service(self, 'nginx') + Log.debug(self, "Removing apt_packages variable of NGINX") + Log.info(self, "Removing packages, please wait...") + EEAptGet.remove(self, EEVariables.ee_nginx_dev) + EEAptGet.auto_remove(self) + Log.info(self, "Removing repository for NGINX MAINLINE,") + Log.info(self, "Successfully removed packages") + apt_packages = apt_packages + EEVariables.ee_nginx + else: + #revert the changes + EERepo.add(self, repo_url=EEVariables.ee_nginx_dev_repo) + Log.error(self,"Skipped installing NGINX Stable") if self.app.pargs.nginxmainline: if EEVariables.ee_nginx_dev_repo == None: @@ -1731,13 +1737,17 @@ class EEStackController(CementBaseController): 'operation.') ee_prompt = input("Type \"YES\" or \"yes\" to continue [n]: ") if ee_prompt == 'YES' or ee_prompt == 'yes': - EEService.stop_service(self, 'nginx') - Log.debug(self, "Removing apt_packages variable of Nginx") - Log.info(self, "Removing packages, please wait...") - EEAptGet.remove(self, EEVariables.ee_nginx) - EEAptGet.auto_remove(self) - Log.info(self, "Successfully removed packages") - apt_packages = apt_packages + EEVariables.ee_nginx_dev + Log.info(self,"Initializing... Please Wait") + if EEAptGet.download_only(self,EEVariables.ee_nginx_dev,EEVariables.ee_nginx_dev_repo,EEVariables.ee_nginx_key): + EEService.stop_service(self, 'nginx') + Log.debug(self, "Removing apt_packages variable of Nginx") + Log.info(self, "Removing packages, please wait...") + EEAptGet.remove(self, EEVariables.ee_nginx) + EEAptGet.auto_remove(self) + Log.info(self, "Successfully removed packages") + apt_packages = apt_packages + EEVariables.ee_nginx_dev + else: + Log.error(self,"Skipped installing NGINX Mainline") if self.app.pargs.php: Log.debug(self, "Setting apt_packages variable for PHP") diff --git a/ee/core/aptget.py b/ee/core/aptget.py index b8181c6a..1aac6495 100644 --- a/ee/core/aptget.py +++ b/ee/core/aptget.py @@ -195,3 +195,36 @@ class EEAptGet(): return True # apt_cache.close() return False + + def download_only(self,package_name,repo_url=None,repo_key=None): + """ + Similar to `apt-get install --download-only` + """ + try: + with open('/var/log/ee/ee.log', 'a') as f: + if repo_url is not None: + EERepo.add(self, repo_url=repo_url) + if repo_key is not None: + EERepo.add_key(self, repo_key) + proc = subprocess.Popen("DEBIAN_FRONTEND=noninteractive " + "apt-get install -o " + "Dpkg::Options::=\"--force-confdef\"" + " -o " + "Dpkg::Options::=\"--force-confold\"" + " -y --download-only {0}" + .format(package_name), shell=True, + stdin=None, stdout=f, stderr=f, + executable="/bin/bash") + proc.wait() + + if proc.returncode == 0: + return True + else: + Log.error(self,"Error in fetching dpkg package.\nReverting changes ..",False) + if repo_url is not None: + EERepo.remove(self, repo_url=repo_url) + return False + except Exception as e: + Log.error(self, "Error while downloading packages, " + "apt-get exited with error") +