This is my solution, there are better solutions out there. If you have one, feel free to post yours.
Note: This tutorial assumes you're on Linux and have crontab installed (most distros have this)
Otherwise just
1
sudo apt-get install crontab
Make a .sh file in the folder wherver your server is located.
For example if your server is in /home/servername/, then simply
Code:
1
nano /home/servername/autorestart.sh
Paste this in
Code:
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash #path to server binary serverPath="/home/servername/cs2d_dedicated" if pgrep -f $serverPath > /dev/null; then echo "Server is running"; else echo "Restarting server"; nohup $serverPath >/dev/null 2>&1; fi
Open up crontab
Code:
1
crontab -e
Add a cron config to run that script every second.
Code:
1
* * * * * /home/servername/autorestart.sh
That's it.