This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emulate behaviour of
haproxy-systemd-wrapper
. (#390)
This also drops the `HAPROXY_RELOAD_SIGTERM_DELAY` param. For reference, see: http://git.haproxy.org/?p=haproxy.git;a=blob;f=src/haproxy-systemd-wrapper.c;h=f6a9c852b277b5f193d6a952119a149b4cfe3e8b;hb=HEAD
- Loading branch information
1 parent
8b0bdba
commit e493bad
Showing
5 changed files
with
53 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
import os | ||
import sys | ||
import time | ||
import errno | ||
|
||
|
||
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) | ||
if len(ret) == 0: | ||
close_and_swallow(pipefd[0]) | ||
close_and_swallow(pipefd[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]) | ||
while wait_on_haproxy_pipe(pipefd): | ||
time.sleep(0.005) | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters