1

I'm facing the following problem:

A Minecraft Forge Modded Server 1.15.2 is running on my Debian 10 VM that is running OpenJDK JAVA 1.8.0_275-8u275-b01-1-b01. Due to the instability of the Modpack, the server sometimes crashes.

I've tried a solution from Stackoverflow: https://stackoverflow.com/questions/62143022/how-do-i-automatically-restart-a-minecraft-spigot-server-in-the-event-of-a-crash but unfortunately this doesn't work for me.

The problem I'm facing is, that if the Minecraft server gets stopped or crashes, the server is stopped but the JVM is still running. Resulting in not getting an exit code from the process... Currently the server is getting started as shown in the link above. Even when I'm on my Windows machine, I get the same behavior. Server stops, but JVM keeps running. CMD and Powershell.

Process Explorer on Windows 10

I couldn't find anything helpful so far.

Thanks ahead, DaNeubi

1 Answer 1

0

Normally, you would restart based on the exit code. But if the application hangs then you need to take more drastic actions.

In concept, your script needs to understand that you intend to stop the server. This might involve parsing stdout for the /stop command, or more simply systemctl stop minecraft.

When your script understands that you intend to stop, it should wait a reasonable amount of time for the application to close down gracefully. When that time expires, it means the application is hanging, so you'll need to send a more agressive signal such as SIGKILL to force the application to stop.

In practice, this might be a little tough with the screen implementation. But this is easy if you use systemd to manage your minecraft server.

See this answer for an implementation of managing a minecraft server with systemd. Specifically note Restart=:

[System]
Restart=on-failure

This means if the service fails, it'll automatically restart. You may also want to try Restart=always which will cause it to start up, even if it stops with a clean exit code.

In addition, systemd provides these defaults which you can customize by adding them to your service and modifying as desired:

[Service]
TimeoutStopSec=90s
KillSignal=SIGTERM
FinalKillSignal=SIGKILL

If you try to systemctl stop or systemctl restart and nothing happens, systemd will wait 90s for a graceful exit before destorying the process. The time and signals can be modified from default by changing the numbers above.

Of course all of this assumes that you send (or a script you wrote sends) systemctl restart minecraft when you want to restart the server. It does not detect if the server freezes during your gameplay.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .