gekware / minecraft-server-hibernation

Autostart and stop minecraft-server when players join/leave
GNU General Public License v3.0
379 stars 37 forks source link

Warn players when manually stopping server #196

Open Br31zh opened 1 year ago

Br31zh commented 1 year ago

Is there an existing feature request for this?

Describe the feature you would like to see.

When I stop the server manually (system reboot, maintenance, mods upgrade…), I would like to warn connected players, if there is any (otherwise, or if it’s frozen, then stop it directly).

Describe the solution you'd like.

Maybe two options: warn delay, warn message? Eventually, changing the MOTD and/or prevent users to login during this time.

Another way is to allow to use an external program to stop the server (like the start command). And add some commands to the msh shell too (like one to change the MOTD). That way it would be even more customizable (but then it’s another request I guess).

Additional context to this request.

No response

gekigek99 commented 1 year ago

add some commands to the msh shell too (like one to change the MOTD). That way it would be even more customizable (but then it’s another request I guess).

yeah can you open an other request for that?

gekigek99 commented 1 year ago

Maybe two options: warn delay, warn message? Eventually, changing the MOTD and/or prevent users to login during this time.

Idk... why do you need it? If you really have to stop the server immediately then you wont wait anyway for players, plus even with a forceful shutdown msh tries to save the world so no data lost.

It might make admin life a bit weird as when msh receive a ctrl+c signal it would have to wait 30 or so seconds after player warning

Br31zh commented 1 year ago

I have two OSes on the computer that run Minecraft, and I often (several times a week, sometimes even twice in the same day) need to reboot from one to the another. And I don’t want to kick all players without any warning that often. This delay give them the time to safely stop their current action. Currently I’m manually checking if there is a player, then sending a mine say Reboot in 30 seconds then wait 30 seconds and do the reboot. I know it can be weird to wait, so it can be optional.

While writing all this, I realized that I can run a custom script next to msh rather than from msh:

#!/bin/bash

# some magic to get PID and process state
mcpid="$(pgrep -nu minecraft java)"
mcstatus="$(ps -q "${mcpid}" -o state --no-headers 2>/dev/null)"

if [[ "$mcstatus" != "T" ]] # T = frozen, so no player
then
    echo "mine say Stopping the server in 30 seconds" > /run/minecraft-server.stdin # it’s the standard input, via a socket
    sleep 30
fi

echo "msh exit" > /run/minecraft-server.stdin

and I’m saying to my system (SystemD on Linux) to run this script instead of sending SIGTERM signal to msh.

So on my side, everything is ok with this workaround (well, a way to prevent new players from login can be great).

gekigek99 commented 1 year ago

Sounds reasonable, I can't give you a definitive opinion but it's a nice idea.

But if i ever implement it, it will be done after 2.5.0 (which is almost ready).