Automatic Server Restart Script

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

Automatic Server Restart Script

by jojoa1997 » Mon Jan 28, 2013 02:09

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: 4468
Joined: Sun Apr 01, 2012 12:38
Location: Waynesville, NC
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE

by VanessaE » Mon Jan 28, 2013 02:14

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 » Fri Apr 12, 2013 21:22

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: 997
Joined: Sat Jul 02, 2011 00:43
Location: An island in a lava lake.
IRC: Menche
In-game: Menche

by Menche » Fri Apr 12, 2013 22:18

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 » Fri Apr 12, 2013 23:02

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 » Tue Apr 16, 2013 11:06

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: 4468
Joined: Sun Apr 01, 2012 12:38
Location: Waynesville, NC
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE

by VanessaE » Tue Apr 16, 2013 11:28

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
Location: (Ignore all of my posts before 2018)
GitHub: 12Me21

by 12Me21 » Tue Apr 16, 2013 12:01

Thx!
Shoutouts to Simpleflips
 

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

by 12Me22 » Sat May 04, 2013 16:21

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.
 


Return to Servers



Who is online

Users browsing this forum: No registered users and 4 guests