File: test-inherited-fd.py

package info (click to toggle)
haproxy 3.2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 23,880 kB
  • sloc: ansic: 267,692; sh: 3,277; xml: 1,756; python: 1,345; makefile: 1,155; perl: 168; cpp: 21
file content (23 lines) | stat: -rw-r--r-- 655 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/python
"""
Python wrapper example to test the fd@ function,
You have to bind on fd@${NEWFD} in your haproxy configuration

The configuration parsing should still work upon a reload with the master-worker
mode.

"""

import socket, subprocess, fcntl

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
flags = fcntl.fcntl(s.fileno(), fcntl.F_GETFD)
flags &= ~fcntl.FD_CLOEXEC
fcntl.fcntl(s.fileno(), fcntl.F_SETFD, flags)

s.bind((socket.gethostname(), 5555))
s.listen(1)
FD = s.fileno()

subprocess.Popen('NEWFD={} ./haproxy -W -f haproxy.cfg'.format(FD), shell=True, close_fds=False)