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?
Asked
Active
Viewed 3,629 times
1
-
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
1 Answers
1
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.
NZD
- 2,600
- 16
- 22