I have a program that must work forever until kill -HUP command. But sometime this program can exit with an error code or it can be killed by OS for overusing memory.
Is there any standard linux command which can monitor any command and restart them on exit?
Something like this: forever my-command -with some parameters
It can be done via bash script:
#!/bin/bash
while true
do
my-command -with some parameters
done
, but I'd better to use somethings standard rather than writing my own scripts.
systemd
and other init systems provide this feature on the system level, you only need to write the proper configuration files.bash
example restarts the command even afterkill -HUP
...