0

I have a web service that runs on Linux. Is there a conventional way to ensure the server is restarted in the event of a crash?

I suppose I might have a shell script which does something like this:

while true; do ./myserver; done

But I think the need to attach the script to a session makes this a poor solution. What is the correct way to do this?

Should there be a daemon process which spawns the server as another daemon? Or is there a better way?

CaptainCodeman
  • 227
  • 2
  • 10

1 Answers1

2

This can be handled by systemd. A very basic service definition file could look like this:

[Unit]
Description=my server

[Service]
Type=simple
ExecStart=/path/to/myserver
Restart=on-failure

[Install]
WantedBy=multi-user.target
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89