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

Commit

Permalink
Check for new PID after reload.
Browse files Browse the repository at this point in the history
When reloading, make sure there's actually a new PID by doing some basic
set math.

To address #267.
  • Loading branch information
brndnmtthws committed Jul 18, 2016
1 parent f2f23c8 commit f49da7f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions marathon_lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,12 @@ def config(apps, groups, bind_http_https, ssl_certs, templater,

def get_haproxy_pids():
try:
return subprocess.check_output(
return set(map(lambda i: int(i), subprocess.check_output(
"pidof haproxy",
stderr=subprocess.STDOUT,
shell=True)
shell=True).split()))
except subprocess.CalledProcessError as ex:
return ''
return set()


def reloadConfig():
Expand Down Expand Up @@ -596,10 +596,10 @@ def reloadConfig():
logger.info("reloading using %s", " ".join(reloadCommand))
try:
start_time = time.time()
pids = get_haproxy_pids()
old_pids = get_haproxy_pids()
subprocess.check_call(reloadCommand, close_fds=True)
# Wait until the reload actually occurs
while pids == get_haproxy_pids():
# Wait until the reload actually occurs and there's a new PID
while len(get_haproxy_pids() - old_pids) < 1:
time.sleep(0.1)
logger.debug("reload finished, took %s seconds",
time.time() - start_time)
Expand Down

0 comments on commit f49da7f

Please sign in to comment.