Skip to content

Commit

Permalink
chore: Use home path for haproxy pid file (#229)
Browse files Browse the repository at this point in the history
* chore: Use home path for haproxy pid file

* Fix issort lint error

---------

Co-authored-by: okozachenko1203 <[email protected]>
  • Loading branch information
okozachenko1203 and okozachenko1203 authored Jan 12, 2024
1 parent 89f058b commit e41069d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion magnum_cluster_api/privsep/haproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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)
6 changes: 5 additions & 1 deletion magnum_cluster_api/proxy/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion magnum_cluster_api/proxy/templates/haproxy.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions magnum_cluster_api/proxy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# under the License.

import fcntl
import os
import socket
import struct
from contextlib import closing
Expand Down Expand Up @@ -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")

0 comments on commit e41069d

Please sign in to comment.