I’m running a dotnet application on a VPS running Ubuntu, and the application has to be running continuously 24/7. When I start up the application, I use “nohup dotnet (name).dll”, and in HTOP those processes will simply have the command “dotnet (name).dll” attached to them. However, because of the nature of the application, it has to run in multiple processes, meaning multiple PIDs. I’ve seen multiple examples of restarting processes if they crash, but they all seem to be based on PIDs from what I’ve seen. What kind of script would I need that would look for “dotnet” commands that stop running and run several lines of code (including a sleep command so that it doesn’t restart the process again while it’s already starting up), and how would I go about making sure that it constantly runs in the background?
There are actually many ways to accomplish this goal, and it can go from trivial home-grown (eg,
while true; do my_process; done (ps: don't do that)) to more complicated patterns (eg involving
my_process.pid with init scripts and custom log file rotations)... but before going down that rabbit hole, look at existing solutions that accomplish the same thing. For example: supervisor (see also this tutorial ) or monit, both available via
apt install ..., but both just requiring some additional configuration.