Automatic Server Restart Script

Post Reply
User avatar
jojoa1997
Member
Posts: 2890
Joined: Thu Dec 13, 2012 05:11
Location: Earth

Automatic Server Restart Script

by jojoa1997 » Post

does anyone have a script to automatically restart servers if they crash.
Coding;
1X coding
3X debugging
12X tweaking to be just right

User avatar
VanessaE
Moderator
Posts: 4564
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

by VanessaE » Post

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

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.
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

User avatar
12Me22
Member
Posts: 38
Joined: Fri Apr 12, 2013 21:20
Location: Earth

by 12Me22 » Post

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):

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.

User avatar
Menche
Member
Posts: 1001
Joined: Sat Jul 02, 2011 00:43
IRC: Menchers
In-game: Menche
Location: An island in a lava lake.

by Menche » Post

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.
An innocent kitten dies every time you top-post.

User avatar
12Me22
Member
Posts: 38
Joined: Fri Apr 12, 2013 21:20
Location: Earth

by 12Me22 » Post

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?
Last edited by 12Me22 on Sat Apr 13, 2013 13:29, edited 1 time in total.

User avatar
12Me22
Member
Posts: 38
Joined: Fri Apr 12, 2013 21:20
Location: Earth

by 12Me22 » Post

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):

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.

User avatar
VanessaE
Moderator
Posts: 4564
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

by VanessaE » Post

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.
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

User avatar
12Me21
Member
Posts: 873
Joined: Tue Mar 05, 2013 00:36
GitHub: 12Me21
Location: (Ignore all of my posts before 2018)

by 12Me21 » Post

Thx!
Shoutouts to Simpleflips

User avatar
12Me22
Member
Posts: 38
Joined: Fri Apr 12, 2013 21:20
Location: Earth

by 12Me22 » Post

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
Last edited by 12Me22 on Sat May 04, 2013 16:26, edited 1 time in total.

WGA7
New member
Posts: 1
Joined: Sat May 09, 2020 13:58
GitHub: WGA7
IRC: WGA7
In-game: WGA7

Re: Automatic Server Restart Script

by WGA7 » Post

Someone tell me how to do it

User avatar
orwell
Member
Posts: 859
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
IRC: orwell96_mt
In-game: orwell
Location: Raxacoricofallapatorius

Re: Automatic Server Restart Script

by orwell » Post

If it's still relevant: you might want to have a look at https://github.com/orwell96/minetest_server_initd
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests