Following this question: How do I write a bash script to restart a process if it dies?
I am trying to make a bash script which simply runs a python script and restarts the script if the script ends with a non-0 output. My bash script looks something like:
#!/bin/bash
trap 'kill $(jobs -p)' SIGTERM SIGKILL;
until python test.py & wait; do
echo "Test Critically Crashed" >&2
sleep 1;
done
While my python script (though not really relevant) looks like:
import logging,sys,signal,time
def signal_term_handler(signal, frame):
print("SIGTERM recieved...quitting")
sys.exit(0)
signal.signal(signal.SIGTERM, signal_term_handler)
while True:
time.sleep(1)
sys.exit(1)
I would like to run the bash script and have it run my process infinitely until I send a sigterm or sigkill to the bash script in which it will send it to the child process (python test.py) and ultimately exit with code 0, thus breaking the until loop and exiting cleanly.
FYI I am using an infinitely running python script, and using this bash script as an entry point to a docker container.