0

This question already has an answer here:

I'm on a shared sever without sudo. I'm using a program running off mono that crashes frequently on a Debian server. What's the best way to have the process auto-restart?

marked as duplicate by allquixotic, Pimp Juice IT, fixer1234, Journeyman Geek Jun 23 '17 at 23:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You might want to re-word the question as "How can I have the process auto-restart?" instead of "What's the best way", because "best way" is opinion-based and could cause the question to be closed. – allquixotic Jun 12 '17 at 20:40
  • Also, it depends on how you're starting this process. Is it via /etc/init.d? Are you using a version of Debian that runs systemd (e.g. does systemctl exist as a valid command?) Or are you just running it from the CLI like mono foo.exe? – allquixotic Jun 12 '17 at 20:41
  • I'm running the program from CLI. It is running systemd. – user737944 Jun 12 '17 at 21:38
0

In systemd you can create a service file to (re)start your process. You can add this file in /etc/systemd/system or in /etc/systemd/user.

This will take care of starting your program when the server reboots or when your program crashes. You can look at the existing files there for examples and also have a look at the manual.

If you just want to start it from the commandline and have it restart when it exits, you can create a bash script that wraps your command. For example:

#!/bin/bash

while (true) do
   echo starting...
   # your command goes here instead of sleep
   sleep 4
   # show result
   exitcode=$?
   echo "exit code of command is $exitcode"
done

This is the simplest form, which does no checking at all.

  • your shell script worked wonderfully, thank you. – user737944 Jun 14 '17 at 2:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.