From ebce934cdd73bede905f6345b831cf2b471d0506 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Fri, 21 Aug 2020 14:33:48 +0500 Subject: [PATCH] allow ElasticRearch remove --- manageServices/serviceManager.py | 47 ++++++++++++++++++++++++++++++++ manageServices/views.py | 2 ++ 2 files changed, 49 insertions(+) diff --git a/manageServices/serviceManager.py b/manageServices/serviceManager.py index 7d14b4285..333d47021 100755 --- a/manageServices/serviceManager.py +++ b/manageServices/serviceManager.py @@ -206,6 +206,51 @@ type=rpm-md "Packages successfully installed.[200]\n", 1) return 0 + @staticmethod + def RemoveElasticSearch(): + + statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w') + + if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + command = 'rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch' + ServerStatusUtil.executioner(command, statusFile) + + repoPath = '/etc/yum.repos.d/elasticsearch.repo' + + try: + os.remove(repoPath) + except: + pass + + command = 'yum erase elasticsearch -y' + ServerStatusUtil.executioner(command, statusFile) + else: + + try: + os.remove('/etc/apt/sources.list.d/elastic-7.x.list') + except: + pass + + + command = 'apt-get remove elasticsearch -y' + ServerStatusUtil.executioner(command, statusFile) + + ### Tmp folder configurations + + command = 'rm -rf /home/elasticsearch/tmp' + ServerStatusUtil.executioner(command, statusFile) + + + jvmOptions = '/etc/elasticsearch/jvm.options' + + + command = 'rm -f /home/cyberpanel/elasticsearch' + ServerStatusUtil.executioner(command, statusFile) + + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + "ElasticSearch successfully removed.[200]\n", 1) + return 0 + def main(): parser = argparse.ArgumentParser(description='CyberPanel Application Manager') @@ -216,6 +261,8 @@ def main(): if args["function"] == "InstallElasticSearch": ServiceManager.InstallElasticSearch() + elif args["function"] == "RemoveElasticSearch": + ServiceManager.RemoveElasticSearch() diff --git a/manageServices/views.py b/manageServices/views.py index 2c2c8b02e..577899fe8 100755 --- a/manageServices/views.py +++ b/manageServices/views.py @@ -351,6 +351,8 @@ def removeInstall(request): if appName == 'Elastic Search': if status == 'Installing': command = '/usr/local/CyberCP/bin/python /usr/local/CyberCP/manageServices/serviceManager.py --function InstallElasticSearch' + else: + command = '/usr/local/CyberCP/bin/python /usr/local/CyberCP/manageServices/serviceManager.py --function RemoveElasticSearch' ProcessUtilities.popenExecutioner(command) data_ret = {'status': 1}