From f8981881c4d5b4cc5aff5319ee9cdd5e0812e109 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Thu, 8 Aug 2024 10:59:11 +0530 Subject: [PATCH] fix(proxy): Remove conflicting site before adding a new site This is to avoid failures like this on add/rename site jobs ```shell systemd[1]: Reloading A high performance web server and a reverse proxy server. nginx[541919]: nginx: [emerg] conflicting parameter "frappemail.frappe.cloud" in /etc/nginx/conf.d/proxy.conf:3722 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE systemd[1]: Reload failed for A high performance web server and a reverse proxy server. ``` Reference: https://frappecloud.com/app/agent-job/3d4bd1ab06 --- agent/proxy.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/agent/proxy.py b/agent/proxy.py index 534300f8..5559f810 100644 --- a/agent/proxy.py +++ b/agent/proxy.py @@ -75,12 +75,21 @@ def add_wildcard_hosts(self, wildcards): @job("Add Site to Upstream") def add_site_to_upstream_job(self, upstream, site, skip_reload=False): + self.remove_conflicting_site(site) self.add_site_to_upstream(upstream, site) self.generate_proxy_config() if skip_reload: return self.reload_nginx() + @step("Remove Conflicting Site") + def remove_conflicting_site(self, site): + # Go through all upstreams and remove the site file matching the site name + for upstream in self.upstreams: + conflict = os.path.join(self.upstreams_directory, upstream, site) + if os.path.exists(conflict): + os.remove(conflict) + @step("Add Site File to Upstream Directory") def add_site_to_upstream(self, upstream, site): upstream_directory = os.path.join(self.upstreams_directory, upstream) @@ -147,6 +156,7 @@ def rename_site_on_upstream_job( new_name: str, skip_reload=False, ): + self.remove_conflicting_site(new_name) self.rename_site_on_upstream(upstream, site, new_name) site_host_dir = os.path.join(self.hosts_directory, site) if os.path.exists(site_host_dir):