linux - How to wait till all services are up in parallel using bash? -
i have script starts 5 services on 4000-4004 ports. want script blocked till of them up. following works me.
while ! nc -vz localhost 4000; sleep 1; done while ! nc -vz localhost 4001; sleep 1; done while ! nc -vz localhost 4002; sleep 1; done while ! nc -vz localhost 4003; sleep 1; done while ! nc -vz localhost 4004; sleep 1; done
the problem above if 4002 still not up, keep on waiting while have no information 4003 & 4004.
what run of these in parallel somehow , print out status of each port. , when of them up, continues after block else blocks , prints out ports , down.
(optionally need add timeout well, should doable once how above.)
thanks lot.
edit:
following worked great me:
$ parallel --timeout 300 -j0 'while ! nc -vz localhost {}; sleep 10; done; echo {} open' ::: {4000..4004} 5001 || { echo "one or more serves failed start. exiting.."; exit 1; }
note: make sure run following after installation. ref-link
$ sudo rm /etc/parallel/config
with gnu parallel can do:
parallel --timeout 30 -j0 'while ! nc -vz localhost {}; sleep 1; done; echo {} open' ::: {4000..4004}
10 seconds installation:
wget -o - pi.dk/3 | sh
watch intro video quick introduction: https://www.youtube.com/playlist?list=pl284c9ff2488bc6d1
Comments
Post a Comment