Restart a process automatically if it dies
I have a hobby server that I’m deploying to a digital ocean droplet. I run this server as any other program and it does what it was programmed to do:
1
./myserver
The problem is that this server is not perfect and I’m OK with that. Nevertheless, I don’t want to have to restart it manually every time it dies. For that reason I did some googling and found an easy way to restart my server if it unexpectedly dies:
1
2
3
4
5
6
7
8
#!/usr/bin/env bash
until /home/tacos/myserver >> myserver.log 2>> myserver.error.log; do
echo "$(date -u) - Server crashed with exit code $?. Respawning..." >> runner.log
sleep 1
done
echo "$(date -u) - Server manually killed" >> runner.log