William Lallemand | 51606fe | 2017-11-15 19:17:23 +0100 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | """ |
| 3 | Python wrapper example to test the fd@ function, |
| 4 | You have to bind on fd@${NEWFD} in your haproxy configuration |
| 5 | |
| 6 | The configuration parsing should still work upon a reload with the master-worker |
| 7 | mode. |
| 8 | |
| 9 | """ |
| 10 | |
| 11 | import socket, subprocess, fcntl |
| 12 | |
| 13 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 14 | s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
| 15 | flags = fcntl.fcntl(s.fileno(), fcntl.F_GETFD) |
| 16 | flags &= ~fcntl.FD_CLOEXEC |
| 17 | fcntl.fcntl(s.fileno(), fcntl.F_SETFD, flags) |
| 18 | |
| 19 | s.bind((socket.gethostname(), 5555)) |
| 20 | s.listen(1) |
| 21 | FD = s.fileno() |
| 22 | |
| 23 | subprocess.Popen('NEWFD={} ./haproxy -W -f haproxy.cfg'.format(FD), shell=True, close_fds=False) |