Page 1 of 1

Automatic Server Restart Script

PostPosted: Mon Jan 28, 2013 02:09
by jojoa1997
does anyone have a script to automatically restart servers if they crash.

PostPosted: Mon Jan 28, 2013 02:14
by VanessaE
I use this (with stuff specific to my needs filled-in, of course):

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
#!/bin/bash

while true
    do
    sleep 1
    minetestserver --config /path/to/your/minetest.conf \
            --worldname name_of_your_world_here \
            --gameid your_game_here \
            --port 30000 \
            --logfile /path/to/servers/debug.txt
done


Pretty simple stuff. It just loops, always waiting one second before restarting after a crash. Nothing fancy.

Note that something this simple can't protect against a server just locking up and consuming CPU - it'll only protect against the server crashing and exiting. For that, you'll need to write a script that scrapes the output from top or ps or something and measures how long the server stays in that state, then deliberately kills and restarts it if it exceeds some reasonable threshold.

PostPosted: Fri Apr 12, 2013 21:22
by 12Me22
I am new to Minetest and am working with 12Me21 to create our own server and I have a few questions about this cron job.
-how do I determine my worldname and gameid?
-where do i store this cron job? cron.d?

Thanks!


VanessaE wrote:I use this (with stuff specific to my needs filled-in, of course):

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
#!/bin/bash

while true
    do
    sleep 1
    minetestserver --config /path/to/your/minetest.conf \
            --worldname name_of_your_world_here \
            --gameid your_game_here \
            --port 30000 \
            --logfile /path/to/servers/debug.txt
done


Pretty simple stuff. It just loops, always waiting one second before restarting after a crash. Nothing fancy.

Note that something this simple can't protect against a server just locking up and consuming CPU - it'll only protect against the server crashing and exiting. For that, you'll need to write a script that scrapes the output from top or ps or something and measures how long the server stays in that state, then deliberately kills and restarts it if it exceeds some reasonable threshold.

PostPosted: Fri Apr 12, 2013 22:18
by Menche
The worldname is the path to your world folder; if the folder doesn't exist Minetest will create a new world there. The gameid is which game mode the server uses. The current official game modes are build, survival, minetest, and minimal.

PostPosted: Fri Apr 12, 2013 23:02
by 12Me22
I found if use "minetest --gamed list" I can verify that. Do you know where I put that cron job? Is it a cron job?

PostPosted: Tue Apr 16, 2013 11:06
by 12Me22
VanessaE ,

Can you help me with this script? I have my worldname and gamed I just don't know where to put the script.

Thanks


VanessaE wrote:I use this (with stuff specific to my needs filled-in, of course):

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
#!/bin/bash

while true
    do
    sleep 1
    minetestserver --config /path/to/your/minetest.conf \
            --worldname name_of_your_world_here \
            --gameid your_game_here \
            --port 30000 \
            --logfile /path/to/servers/debug.txt
done


Pretty simple stuff. It just loops, always waiting one second before restarting after a crash. Nothing fancy.

Note that something this simple can't protect against a server just locking up and consuming CPU - it'll only protect against the server crashing and exiting. For that, you'll need to write a script that scrapes the output from top or ps or something and measures how long the server stays in that state, then deliberately kills and restarts it if it exceeds some reasonable threshold.

PostPosted: Tue Apr 16, 2013 11:28
by VanessaE
You can place the script anywhere you want, the point is to run it. I keep it in the home directory for the user that the server runs as, and it is run from /etc/rc.local at system boot (via su and screen, so that it runs as the proper userid).

On my regular user account, I keep all my various scripts in ~/Scripts.

PostPosted: Tue Apr 16, 2013 12:01
by 12Me21
Thx!

PostPosted: Sat May 04, 2013 16:21
by 12Me22
I get the following error:

Terminate called after throwing and instance of 'std::logic_error'
what (): basic_strig::_S_construct null not valid
/home/12Me22/scripts/restartminetest.sh: line 8: 1056 Aborted

#!/bin/bash

while true
do
sleep 1
minetestserver --config /home/12Me22/minetest/minetest.conf --world /home/12Me22/minetest/worlds/world \
--logfile /home/12Me22/backups/debug.txt
done