Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Emulate behaviour of haproxy-systemd-wrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
brndnmtthws committed Dec 24, 2016
1 parent e804f5d commit 96023d4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions haproxy_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
import os
import sys


def create_haproxy_pipe():
pipefd = os.pipe()
return pipefd


def close_and_swallow(fd):
try:
os.close(fd)
except OSError:
# swallow
pass


def wait_on_haproxy_pipe(pipefd):
try:
ret = os.read(pipefd[0], 1)
except OSError as e:
if e.args[0] != errno.EINTR:
close_and_swallow(pipefd[0])
close_and_swallow(pipefd[1])
return False
return True

pipefd = create_haproxy_pipe()

pid = os.fork()

if not pid:
os.environ["HAPROXY_WRAPPER_FD"] = str(pipefd[1])
# Close the read side
os.close(pipefd[0])
os.execv(sys.argv[1], sys.argv[1:])

# Close the write side
os.close(pipefd[1])
wait_on_haproxy_pipe(pipefd)
2 changes: 1 addition & 1 deletion service/haproxy/run
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ reload() {

# Trigger reload
LATEST_HAPROXY_PID=$(cat $PIDFILE)
haproxy -p $PIDFILE -f /marathon-lb/haproxy.cfg -D -sf $LATEST_HAPROXY_PID 200>&-
/marathon-lb/haproxy_wrapper.py `which haproxy` -p $PIDFILE -f /marathon-lb/haproxy.cfg -D -sf $LATEST_HAPROXY_PID 200>&-
if [ -n "${HAPROXY_RELOAD_SIGTERM_DELAY-}" ]; then
sleep $HAPROXY_RELOAD_SIGTERM_DELAY && kill $LATEST_HAPROXY_PID 200>&- 2>/dev/null &
fi
Expand Down

0 comments on commit 96023d4

Please sign in to comment.