if you have some important apps running in the context of a service, meaning you can start them by running systemctl start myApp
you can also configure them to automatically restart if they die.
- locate your unit’s service file by running
sudo systemctl status myApp
. - read the
loaded
line, this tells you where systemctl found the service file to load. - open this service file in your editor of choice.
- in the
[Service]
unit, add this:Restart=always
- in the
[Unit]
unit, add these:StartLimitIntervalSec=10
StartLimitBurst=5 - run
sudo systemctl daemon-reload
that’s it. your service will now restart itself if it ever dies, and if it dies and doesn’t successfully start due to error 5 times in 10 seconds, it will stop automatically trying to restart itself.