Running CADDY on Linux OS Start Up Time and Keeping it Alive like PM2

How to keep CADDY always alive in production?

For a node application, I can use PM2 to keep the web server always alive whenever things go wrong. This makes me feel that it is safe to use it. :grinning:

For CADDY, it is said here that we can use nohup caddy & to run the application in the background. But it seems that it does not guarantee to keep it alive when CADDY is crashed.:weary: So, should I just use nohup caddy & in production use? Or, CADDY will not crash :wink:?

Caddy won’t crash (the guarantee is slightly lessened if using third party plugins) but to keep it alive I recommend using something like a bash script that will re-run it if it terminates or, better yet, an init system that will do the same thing plus run it if your machine reboots.

Most Linux Distros are using systemd these days, so, in my opinion, this is your best bet. Systemd can automatically restart your application on certain conditions. Therefore you have to use the Restart= directive.

If you want to see how you can set it up yourself I suggest this guide. (It uses the Restart=on-failure directive)

PS: Ubuntu 16.04 uses systemd, as well does Debian 8 (Jessie) and CentOS 7.