How do I inform a manuscript to await a process to start approving demands on a port?
The ideal examination to see if a web server is approving links is to in fact attempt attaching. Make use of a normal customer for whatever method your web server talks and also attempt a no - op command.
If you desire a light-weight TCP or UDP customer you can drive merely from the shell, usage netcat. Just how to program a discussion relies on the method ; several methods have the web server close the link on a particular input, and also netcat will certainly after that exit.
while ! echo exit | nc localhost 13000; do sleep 10; done
You can additionally inform netcat to exit after developing the link. It returns 1 if there is no link and also 0 if there is so we negate its result. Relying on your variation of netcat, it might sustain one or both of the adhering to commands:
while ! nc -z localhost 13000 </dev/null; do sleep 10; done
while ! nc -q 1 localhost 13000 </dev/null; do sleep 10; done
A different strategy is to await the web server process to open a paying attention outlet.
while netstat -lnt | awk '$4 ~ /:13000$/ {exit 1}'; do sleep 10; done
Or you could intend to target a details process ID:
while ! lsof -n -Fn -p $pid | grep -q '^n.*:13000$'; do sleep 10; done
I can not consider any kind of means to respond to the process beginning to pay attention to the outlet (which would certainly stay clear of a ballot strategy) except making use of ptrace
.
Related questions