English [Tutorial] How to make server auto restart script

4 replies
Goto Page
To the start Previous 1 Next To the start
Up
Nekomata
User
Offline Off
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
Code:
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:

Code:
1
nano /home/servername/autorestart.sh


Paste this in
Code:

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:

Code:
1
crontab -e


Add a cron config to run that script every second.
Code:

Code:
1
* * * * * /home/servername/autorestart.sh



That's it.
02.05.18 04:36:41 pm
Up
minos
User
Offline Off
Thank you nekomata
l
02.05.18 11:42:51 pm
Up
cs2d_is_a_Gem
User
Offline Off
@user Nekomata: this is very useful, very good contribution in my opinion. 10/10
03.05.18 08:24:31 am
Up
_3yrus
User
Offline Off
just do this :
Code:
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
here we go !
03.05.18 08:44:54 am
Up
Rainoth
Moderator
Offline Off
@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
MAL • DeviantArt • For Wallpaper Engine users • Check YT for playlists... •
To the start Previous 1 Next To the start