I want a way to write a daemon in a shell script, which runs another application in a loop, restarting it if it dies.
- When run using
./myscript.shfrom an SSH session, it shall launch a new instance of the daemon, except if the daemon is already running. - When the SSH session ends, the daemon shall persist.
- There shall be a parameter (
./myscript -stop) that kills any existing daemon.
(Notes on edit - The original question specified that nohup and similar tools may not be used. This artificial requirement was an "XY question", and the accepted answer in fact uses all the tools the OP claimed were not possible to use.)