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
.
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
e804f5d
commit 96023d4
Showing
2 changed files
with
42 additions
and
1 deletion.
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
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) |
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