Forum

> > CS2D > Servers > [Tutorial] How to make server auto restart script
Forums overviewCS2D overview Servers overviewLog in to reply

English [Tutorial] How to make server auto restart script

4 replies
To the start Previous 1 Next To the start

old [Tutorial] How to make server auto restart script

Nekomata
User Off Offline

Quote
A lot of people have been PMing me for this, so I'll make a single thread for this.

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
#!/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.

old Re: [Tutorial] How to make server auto restart script

_3yrus
User Off Offline

Quote
just do this :
1
2
3
4
5
6
7
8
9
function resetLua()
	parse("luareset")
	local open = io.open
	local file = open(path_to_your_lua_file, "rb") 
	if not file then return nil end
	local lua_code = file:read "*a" 
	file:close()
	parse("lua '".. lua_code .."'")
end

old Re: [Tutorial] How to make server auto restart script

Rainoth
Moderator Off Offline

Quote
@user _3yrus: The task is not to restart the script of the server. The task is to write a script that restarts the server. You misunderstood it fundamentally because you did not see (or understand) the tag '[Tutorial]' which signifies that this thread is meant to teach something rather than ask something.

Still, maybe someone will actually need to restart a script on their server and by some kind of miracle stumble upon this thread
To the start Previous 1 Next To the start
Log in to reply Servers overviewCS2D overviewForums overview