From fd2f1705bdff8a0a5f84491a54efd4d4aeae605b Mon Sep 17 00:00:00 2001 From: usmannasir Date: Fri, 22 Dec 2023 07:41:48 +0500 Subject: [PATCH] adjust some functions --- plogical/DockerSites.py | 26 +++++++++++++++++++++++++- websiteFunctions/models.py | 2 +- websiteFunctions/website.py | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/plogical/DockerSites.py b/plogical/DockerSites.py index 3e6cbac99..729856e3b 100644 --- a/plogical/DockerSites.py +++ b/plogical/DockerSites.py @@ -525,6 +525,30 @@ def DeleteDockerApp(self): command = f'rm -f /home/{self.data["domain"]}/public_html/.htaccess' ProcessUtilities.executioner(command) + + ### forcefully delete containers + + import docker + + # Create a Docker client + client = docker.from_env() + + # Define the label to filter containers + label_filter = {'name': self.data['name'].replace(' ', '-')} + + # List containers matching the label filter + containers = client.containers.list(filters=label_filter) + + logging.writeToFile(f'List of containers {str(containers)}') + + + for container in containers: + command = f'docker stop {container.short_id}' + ProcessUtilities.executioner(command) + + command = f'docker rm {container.short_id}' + ProcessUtilities.executioner(command) + from plogical.installUtilities import installUtilities installUtilities.reStartLiteSpeed() @@ -542,7 +566,7 @@ def ListContainers(self): client = docker.from_env() # Define the label to filter containers - label_filter = {'name': self.data['name']} + label_filter = {'name': self.data['name'].replace(' ', '-')} # List containers matching the label filter containers = client.containers.list(filters=label_filter) diff --git a/websiteFunctions/models.py b/websiteFunctions/models.py index 57b181556..8344d3e56 100755 --- a/websiteFunctions/models.py +++ b/websiteFunctions/models.py @@ -181,7 +181,7 @@ class DockerSites(models.Model): port = models.CharField(max_length=100) CPUsSite = models.CharField(max_length=100) MemorySite = models.CharField(max_length=100) - SiteName = models.TextField() + SiteName = models.TextField(unique=True) finalURL = models.TextField() blogTitle = models.TextField() adminUser = models.CharField(max_length=100) diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index c490ce699..916c41cfd 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -6906,6 +6906,7 @@ def ListDockerSites(self, request=None, userID=None, data=None, DeleteID=None): passdata={} passdata["domain"] = DockerSitesDelete.admin.domain passdata["JobID"] = None + passdata['name'] = DockerSitesDelete.SiteName da = Docker_Sites(None, passdata) da.DeleteDockerApp() DockerSitesDelete.delete()