diff --git a/magnum_cluster_api/privsep/haproxy.py b/magnum_cluster_api/privsep/haproxy.py index d054d40a..39f4e874 100644 --- a/magnum_cluster_api/privsep/haproxy.py +++ b/magnum_cluster_api/privsep/haproxy.py @@ -19,6 +19,7 @@ from oslo_log import log as logging import magnum_cluster_api.privsep +from magnum_cluster_api.proxy import utils LOG = logging.getLogger(__name__) @@ -41,7 +42,7 @@ def start(config_file): def reload(): """Reload HAproxy configuration""" - with open("/var/run/haproxy.pid", "r") as fd: + with open(utils.get_haproxy_pid_path(), "r") as fd: pid = int(fd.read().strip()) os.kill(pid, signal.SIGUSR2) diff --git a/magnum_cluster_api/proxy/manager.py b/magnum_cluster_api/proxy/manager.py index b4822f6d..20431195 100644 --- a/magnum_cluster_api/proxy/manager.py +++ b/magnum_cluster_api/proxy/manager.py @@ -53,7 +53,11 @@ def periodic_tasks(self, context, raise_on_error=False): def _sync_haproxy(self, proxied_clusters: list): # Generate HAproxy config - config = self.template.render(port=self.haproxy_port, clusters=proxied_clusters) + config = self.template.render( + pid_file=utils.get_haproxy_pid_path(), + port=self.haproxy_port, + clusters=proxied_clusters, + ) # Skip if no change has been done if self.checksum == hash(config): diff --git a/magnum_cluster_api/proxy/templates/haproxy.cfg.j2 b/magnum_cluster_api/proxy/templates/haproxy.cfg.j2 index 4dfb13cb..18d2c6a0 100644 --- a/magnum_cluster_api/proxy/templates/haproxy.cfg.j2 +++ b/magnum_cluster_api/proxy/templates/haproxy.cfg.j2 @@ -2,7 +2,7 @@ global master-worker log stdout format raw local0 stats socket /var/run/haproxy.sock mode 600 expose-fd listeners level user - pidfile /var/run/haproxy.pid + pidfile {{ pid_file }} defaults log global diff --git a/magnum_cluster_api/proxy/utils.py b/magnum_cluster_api/proxy/utils.py index 46624398..88c2fd3d 100644 --- a/magnum_cluster_api/proxy/utils.py +++ b/magnum_cluster_api/proxy/utils.py @@ -13,6 +13,7 @@ # under the License. import fcntl +import os import socket import struct from contextlib import closing @@ -49,3 +50,8 @@ def find_free_port(port_hint=0): s.bind(("", 0)) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) return s.getsockname()[1] + + +def get_haproxy_pid_path(): + home_dir = os.path.expanduser("~") + return os.path.join(home_dir, ".magnum", "haproxy.pid")