diff --git a/dockerManager/container.py b/dockerManager/container.py index b03feeda7..69b8fef01 100755 --- a/dockerManager/container.py +++ b/dockerManager/container.py @@ -1098,7 +1098,6 @@ def getDockersiteList(self, userID=None, data=None): da = Docker_Sites(None, passdata) retdata = da.ListContainers() - data_ret = {'status': 1, 'error_message': 'None', 'data':retdata} json_data = json.dumps(data_ret) return HttpResponse(json_data) diff --git a/dockerManager/dockerInstall.py b/dockerManager/dockerInstall.py index 9f32e0251..baa4b3145 100755 --- a/dockerManager/dockerInstall.py +++ b/dockerManager/dockerInstall.py @@ -1,4 +1,5 @@ #!/usr/local/CyberCP/bin/python +import os import sys sys.path.append('/usr/local/CyberCP') import plogical.CyberCPLogFileWriter as logging @@ -20,6 +21,12 @@ def submitInstallDocker(CommandCP = 0): if ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'Docker installation started for cent8/9') + + command = 'sudo yum install -y yum-utils' + ServerStatusUtil.executioner(command, statusFile) + command = 'yum install yum-utils -y' ServerStatusUtil.executioner(command, statusFile) diff --git a/dockerManager/views.py b/dockerManager/views.py index cde8f4d20..c16aeb59f 100755 --- a/dockerManager/views.py +++ b/dockerManager/views.py @@ -421,6 +421,7 @@ def removeImage(request): return coreResult except KeyError: return redirect(loadLoginPage) + @preDockerRun def getDockersiteList(request): import json diff --git a/plogical/DockerSites.py b/plogical/DockerSites.py index d1c8556bc..535cedce7 100644 --- a/plogical/DockerSites.py +++ b/plogical/DockerSites.py @@ -98,8 +98,6 @@ def __init__(self, function_run, data): ProcessUtilities.executioner(execPath) - - def run(self): try: if self.function_run == 'DeployWPContainer': @@ -233,9 +231,16 @@ def DeployWPContainer(self): command = 'docker --help' result = ProcessUtilities.outputExecutioner(command) - print(f'return code of docker install {result}') + + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'return code of docker install {result}') + if result.find("not found") > -1: - DockerInstall.submitInstallDocker(1) + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'About to run docker install function...') + + execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/dockerManager/dockerInstall.py" + ProcessUtilities.executioner(execPath) logging.statusWriter(self.JobID, 'Docker is ready to use..,10') @@ -316,7 +321,12 @@ def DeployWPContainer(self): #### - command = f"docker-compose -f {self.data['ComposePath']} -p '{self.data['SiteName']}' up -d" + if ProcessUtilities.decideDistro() == ProcessUtilities.cent8 or ProcessUtilities.decideDistro() == ProcessUtilities.centos: + dockerCommand = 'docker compose' + else: + dockerCommand = 'docker-compose' + + command = f"{dockerCommand} -f {self.data['ComposePath']} -p '{self.data['SiteName']}' up -d" result, message = ProcessUtilities.outputExecutioner(command, None, None, None, 1) if os.path.exists(ProcessUtilities.debugPath): @@ -330,6 +340,25 @@ def DeployWPContainer(self): time.sleep(25) + ### checking if everything ran properly + + passdata = {} + passdata["JobID"] = None + passdata['name'] = self.data['ServiceName'] + da = Docker_Sites(None, passdata) + retdata, containers = da.ListContainers() + + containers = json.loads(containers) + + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(str(containers)) + + ### it means less then two containers which means something went wrong + if len(containers) < 2: + logging.writeToFile(f'Unkonwn error, containers not running. [DeployWPContainer]') + logging.statusWriter(self.JobID, f'Unkonwn error, containers not running. [DeployWPContainer]') + return 0 + ### Set up Proxy execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/DockerSites.py" @@ -572,6 +601,10 @@ def DeleteDockerApp(self): command = f'docker rm {container.short_id}' ProcessUtilities.executioner(command) + + command = f"rm -rf /home/{self.data['domain']}/public_html/.htaccess'" + ProcessUtilities.executioner(command) + from plogical.installUtilities import installUtilities installUtilities.reStartLiteSpeed() @@ -718,9 +751,16 @@ def DeployN8NContainer(self): command = 'docker --help' result = ProcessUtilities.outputExecutioner(command) - print(f'return code of docker install {result}') + + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'return code of docker install {result}') + if result.find("not found") > -1: - DockerInstall.submitInstallDocker() + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'About to run docker install function...') + + execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/dockerManager/dockerInstall.py" + ProcessUtilities.executioner(execPath) logging.statusWriter(self.JobID, 'Docker is ready to use..,10') @@ -799,9 +839,15 @@ def DeployN8NContainer(self): #### - command = f"docker-compose -f {self.data['ComposePath']} -p '{self.data['SiteName']}' up -d" + if ProcessUtilities.decideDistro() == ProcessUtilities.cent8 or ProcessUtilities.decideDistro() == ProcessUtilities.centos: + dockerCommand = 'docker compose' + else: + dockerCommand = 'docker-compose' + + command = f"{dockerCommand} -f {self.data['ComposePath']} -p '{self.data['SiteName']}' up -d" result, message = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + if result == 0: logging.statusWriter(self.JobID, f'Error {str(message)} . [404]') return 0 @@ -810,6 +856,26 @@ def DeployN8NContainer(self): time.sleep(25) + + ### checking if everything ran properly + + passdata = {} + passdata["JobID"] = None + passdata['name'] = self.data['ServiceName'] + da = Docker_Sites(None, passdata) + retdata, containers = da.ListContainers() + + containers = json.loads(containers) + + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(str(containers)) + + ### it means less then two containers which means something went wrong + if len(containers) < 2: + logging.writeToFile(f'Unkonwn error, containers not running. [DeployN8NContainer]') + logging.statusWriter(self.JobID, f'Unkonwn error, containers not running. [DeployN8NContainer]') + return 0 + ### Set up Proxy execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/DockerSites.py" diff --git a/serverStatus/serverStatusUtil.py b/serverStatus/serverStatusUtil.py index d6deda77f..366c719df 100755 --- a/serverStatus/serverStatusUtil.py +++ b/serverStatus/serverStatusUtil.py @@ -34,6 +34,9 @@ def run(self): @staticmethod def executioner(command, statusFile): try: + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(command) + res = subprocess.call(command, stdout=statusFile, stderr=statusFile, shell=True) if res == 1: return 0 diff --git a/websiteFunctions/templates/websiteFunctions/CreateDockerSite.html b/websiteFunctions/templates/websiteFunctions/CreateDockerSite.html index e9fe979c7..52d53eea1 100644 --- a/websiteFunctions/templates/websiteFunctions/CreateDockerSite.html +++ b/websiteFunctions/templates/websiteFunctions/CreateDockerSite.html @@ -169,7 +169,6 @@