I've found that until loop is a great way to monitor and restart a process if it dies for whatever reason
until myserver; do
echo "Server 'myserver' crashed with exit code $?. Respawning.." >&2
sleep 1
done
is there any way to get something like
until myserver; myserver2 , myserver3 ; do
echo "Server 'myserver1' crashed with exit code $?. Respawning.." >&2
echo "Server 'myserver2' crashed with exit code $?. Respawning.." >&2
echo "Server 'myserver3' crashed with exit code $?. Respawning.." >&2
sleep 1
done
Sorry for being a noob...
CodePudding user response:
You need to run three separate loops in parallel.
until myserver; do
echo "...." >&2
sleep 1
done &
until myserver2; do
echo "...." >&2
sleep 1
done &
until myserver3; do
echo "...." >&2
sleep 1
done &
wait
Once all the loops have been started in the background, use wait
to wait for each loop to complete successfully.