liab-deployments/liab_deployments/operations/network.py

16 lines
473 B
Python

from pyinfra.api import operation
from pyinfra.operations import server
@operation()
def wait_host_port_active(host_port: int, ip4: str = '127.0.0.1'):
# use an alternative to server.wait(port=) with a bounded tcp probe.
# requires no netstat/ss to be available
yield from server.shell._inner(
commands=[
"bash -c 'until"
f' (echo > /dev/tcp/{ip4}/{host_port})'
" 2>/dev/null; do sleep 1; done'",
],
)