Page 1 of 1

Scheduled shutdown

PostPosted: Sun Oct 12, 2014 12:57
by Rochambeau
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?

Re: Scheduled shutdown

PostPosted: Sun Oct 12, 2014 13:38
by Nore
VanessaE uses such a script to restart her servers every day at fixed times, you should try to ask her.

Re: Scheduled shutdown

PostPosted: Tue Oct 14, 2014 17:58
by Hybrid Dog
try cron

Re: Scheduled shutdown

PostPosted: Tue Oct 14, 2014 20:33
by kaeza
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).

Re: Scheduled shutdown

PostPosted: Tue Oct 14, 2014 21:13
by Minetestforfun
@kaeza

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

Re: Scheduled shutdown

PostPosted: Tue Oct 14, 2014 23:32
by kaeza
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)

Re: Scheduled shutdown

PostPosted: Wed Oct 15, 2014 12:45
by srifqi
Maybe a scheduled startup?

Re: Scheduled shutdown

PostPosted: Sat Sep 26, 2015 14:55
by Fixerol
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!

Re: Scheduled shutdown

PostPosted: Sat Sep 26, 2015 16:22
by rubenwardy
I use a bash script to restart the server at midnight. It sends SIGINT.

Re: Scheduled shutdown

PostPosted: Mon Oct 12, 2015 08:07
by theshadow900
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.

Re: Scheduled shutdown

PostPosted: Mon Oct 12, 2015 08:09
by rubenwardy
Minetest accepts SIGINT and runs minetest.register_on_shutdown etc.

Re: Scheduled shutdown

PostPosted: Sat Nov 07, 2015 09:34
by theshadow900
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.

Re: Scheduled shutdown

PostPosted: Sun Nov 08, 2015 20:15
by Ben
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.

Re: Scheduled shutdown

PostPosted: Sun Nov 08, 2015 20:22
by rubenwardy
I use cron to execute a batch script.

killall -INT minetestserver

Will kill all servers.