In a shell script, I do the following:
while true; do <some application>; sleep 1; done &
... rest of the scrip ...
This guarantees that the application is always running, as this is needed for the rest of the script. The script is resilient however, so if the application does not seem to be run and answer incorrectly, it will retry later on.
When the main script dies, for example due to a
SIGINT, I want that
while loop to stop as well. There is no need to keep the applicaiton running after the main script dies.
What is the common approach to do this in shell scripting? Note that I want two things:
- prevent re-execution of the application
- stop the current ongoing application instance as soon as possible
I am not sure how to do all this in shell scripting. I could trap
TERM, but I'm not sure how to inject logic into the
while loop and also how to stop the application as well.
Note that I am currently working in plain
sh, but I can move on to
bash if needed.