Coded in python, managed by cron. I had one before but I lost it. Wondering if anyone still has any sort of python code that checks for whether the cs2d server process is down then starts it again (should work for multiple servers (different ports) in different directories).
Such a script is usually useful when the server crashes, etc.
I've looked across the forum and all I found were dead pastie links, so would appreciate anyone sending it.
Thanks!
edit - sneaking in the solution to this:
Here's the bash script, go ahead and save it with a .sh extension anywhere with whatever you named it. Be sure to remember the path to it, as we'll be using it to set it up.
As an example, we'll be naming it autorestartscript.sh
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/server/cs2d_dedicated" if pgrep -f $serverPath > /dev/null; then echo "Server is running"; else echo "Restarting server"; nohup $serverPath >/dev/null 2>&1; fi
Once you're down, give it execution permissions with this command:
1
chmod u+x autorestartscript.sh
That script will work for you but for autorestart, you need to add it to cron.
Go ahead and enter cron with this command:
crontab -e
And now, type this stuff in:
1
2
3
4
2
3
4
MAILTO="" SHELL=/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin * * * * * sh /path/to/autorestartscript.sh
Now exit the crontab (usually with Ctrl+X)
And now it should work!
For errors, check the system logs. Available in the file (/var/log/syslog) for Ubuntu.
Worked for me, hope this works for anyone else looking for this script.
Cheers.
edited 3×, last 30.04.17 04:07:12 pm