Scheduled shutdown

Rochambeau
Member
 
Posts: 68
Joined: Tue Sep 23, 2014 11:37

Scheduled shutdown

by Rochambeau » Sun Oct 12, 2014 12:57

Hi,

I am running a small private server and would like to automatically create backups over night.

For that I created a bash script which loops starting the server, copying the map files to a backup folder when the server gets shut down and starts the server again.

By now, I manually shutdown the server from time to time to activate the backup.

Is it possible to shutdown (not kill!) the minetest server on a specific time?

For bukkit, there was/is the plug in "scheduled shutdown". Does something similar exist for minetest?
 

Nore
Member
 
Posts: 468
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

Re: Scheduled shutdown

by Nore » Sun Oct 12, 2014 13:38

VanessaE uses such a script to restart her servers every day at fixed times, you should try to ask her.
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Scheduled shutdown

by Hybrid Dog » Tue Oct 14, 2014 17:58

try cron
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Scheduled shutdown

by kaeza » Tue Oct 14, 2014 20:33

Maybe something like this would help:
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
-- Time to shut down server.
local H, M = 23, 30

local timer = 0
minetest.register_globalstep(function(dtime)
   timer = timer + dtime
   if timer < 1 then return end
   timer = 0
   local t = os.date("*t")
   if (t.hour == H) and (t.min == M) and (t.sec <= 5) then
      minetest.chat_send_all("Scheduled shutdown. "
            .."Please come back in a few minutes.")
      minetest.after(2, minetest.request_shutdown)
   end
end)


Save this code as e.g. `mods/restart_schedule/init.lua` (`restart_schedule` can be anything you want, it doesn't matter in this case).

NOTE: This assumes the server takes at least 5 seconds for a restart, so be sure to add an appropriate `sleep` call in your shell script, or edit the `(t.sec <= 5)` part of the condition (don't make it too low or it may miss the time if the server lags).
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
Minetestforfun
Member
 
Posts: 936
Joined: Tue Aug 05, 2014 14:09
GitHub: Darcidride
IRC: Darcidride + MinetestForFun
In-game: Darcidride + MinetestForFun

Re: Scheduled shutdown

by Minetestforfun » Tue Oct 14, 2014 21:13

@kaeza

interresting simple code for shutting down a server in lua, can you add days in your code, please ?
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Scheduled shutdown

by kaeza » Tue Oct 14, 2014 23:32

Minetestforfun wrote:@kaeza

interresting simple code for shutting down a server in lua, can you add days in your code, please ?

Sure:
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
-- Time to shut down server.
local H, M = 23, 30

-- Day to shut down server.
-- 1=Sunday, ..., 7=Saturday, nil=Shutdown daily
local D = nil

local timer = 0
minetest.register_globalstep(function(dtime)
   timer = timer + dtime
   if timer < 1 then return end
   timer = 0
   local t = os.date("*t")
   if ((t.hour == H) and (t.min == M) and (t.sec <= 5)
         and ((D == nil) or (t.wday == D))) then
      minetest.chat_send_all("Scheduled shutdown. "
            .."Please come back in a few minutes.")
      minetest.after(2, minetest.request_shutdown)
   end
end)
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
srifqi
Member
 
Posts: 508
Joined: Sat Jun 28, 2014 04:31
GitHub: srifqi
IRC: srifqi
In-game: srifqi

Re: Scheduled shutdown

by srifqi » Wed Oct 15, 2014 12:45

Maybe a scheduled startup?
I'm from Indonesia! Saya dari Indonesia!
Terjemahkan Minetest!
Mods by me. Modifikasi oleh saya.

Pronounce my nick as in: es-rifqi (IPA: /es rifˈki/)
 

Fixerol
Member
 
Posts: 633
Joined: Sun Jul 31, 2011 11:23
IRC: Fixer
In-game: Fixer

Re: Scheduled shutdown

by Fixerol » Sat Sep 26, 2015 14:55

kaeza wrote:
Minetestforfun wrote:@kaeza

interresting simple code for shutting down a server in lua, can you add days in your code, please ?

Sure:
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
-- Time to shut down server.
local H, M = 23, 30

-- Day to shut down server.
-- 1=Sunday, ..., 7=Saturday, nil=Shutdown daily
local D = nil

local timer = 0
minetest.register_globalstep(function(dtime)
   timer = timer + dtime
   if timer < 1 then return end
   timer = 0
   local t = os.date("*t")
   if ((t.hour == H) and (t.min == M) and (t.sec <= 5)
         and ((D == nil) or (t.wday == D))) then
      minetest.chat_send_all("Scheduled shutdown. "
            .."Please come back in a few minutes.")
      minetest.after(2, minetest.request_shutdown)
   end
end)


There is a server that becomes unstable after 20000 sec of uptime, could you make it shutdown after N uptime seconds? For example, after reaching 20000 sec uptime -> do server shutdown. Thanks!
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Scheduled shutdown

by rubenwardy » Sat Sep 26, 2015 16:22

I use a bash script to restart the server at midnight. It sends SIGINT.
 

theshadow900
Member
 
Posts: 19
Joined: Tue Jun 23, 2015 04:52
In-game: theshadow

Re: Scheduled shutdown

by theshadow900 » Mon Oct 12, 2015 08:07

I found a mod called external command. By adding full privs to the server creators name in game, (the name used in the server config file) and using that mod, I then send an external command by script to shutdown the server. This allows everything to save correctly before running the other scripts for backups and cleanups. My server now resets itself twice a day this way and loses no info. Using this mod also allows me to send warning messages to the players that the server is about to reset. I'm sure there are other methods but this has worked well for me so far.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Scheduled shutdown

by rubenwardy » Mon Oct 12, 2015 08:09

Minetest accepts SIGINT and runs minetest.register_on_shutdown etc.
 

theshadow900
Member
 
Posts: 19
Joined: Tue Jun 23, 2015 04:52
In-game: theshadow

Re: Scheduled shutdown

by theshadow900 » Sat Nov 07, 2015 09:34

rubenwardy wrote:Minetest accepts SIGINT and runs minetest.register_on_shutdown etc.


Could you include a link here to something that explains SIGINT usage in minetest a bit more?
Would be much appreciated for future reference.
 

User avatar
Ben
Member
 
Posts: 157
Joined: Tue Mar 31, 2015 20:09

Re: Scheduled shutdown

by Ben » Sun Nov 08, 2015 20:15

Quick sidenote: I recommend running the MineTest server under supervisord. I haven't used it for MineTest itself, but various other programs. There are several benefits: the server is restarted automatically if it crashes, you gain a shell command to restart the server (basically "supervisorctl" non-interactive), and even get a small web page with server status, start/stop/restart buttons and log tailing.

rubenwardy wrote:Minetest accepts SIGINT and runs minetest.register_on_shutdown etc.


I just checked: supervisord (a recent enough version, at least) can be configured to use SIGINT as the "stop process" signal. For a "stop - backup - start" cycle, though, you should probably script something, for which cron would be the most obvious solution.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Scheduled shutdown

by rubenwardy » Sun Nov 08, 2015 20:22

I use cron to execute a batch script.

killall -INT minetestserver

Will kill all servers.
 


Return to Minetest Servers

Who is online

Users browsing this forum: No registered users and 29 guests

cron