Forum

> > CS2D > Servers > Server Auto Restart script [LINUX/VPS] (solved)
Forums overviewCS2D overview Servers overviewLog in to reply

English Server Auto Restart script [LINUX/VPS] (solved)

3 replies
To the start Previous 1 Next To the start

old Server Auto Restart script [LINUX/VPS] (solved)

Nekomata
User Off Offline

Quote
Hi, I'm looking for as stated.

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
#!/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
MAILTO=""
SHELL=/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
* * * * * sh /path/to/autorestartscript.sh
Remember to give the correct path!
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

old Re: Server Auto Restart script [LINUX/VPS] (solved)

VADemon
User Off Offline

Quote
You can use
pgrep -f "Pattern"
in shell to grep all processees including their arguments (making a differentiation on per argument basis)

1
2
3
4
5
6
7
8
9
#!/bin/bash #or your fancier alternative
$pattern1="cs2dbinary -port 3457" #this should definitively identify a server


if pgrep -f $pattern1 > /dev/null; then
	echo "srv1 running";
else
	echo "restart srv1";
fi
To the start Previous 1 Next To the start
Log in to reply Servers overviewCS2D overviewForums overview