Shutting Down Server

A new update is now available, introducing a lot of new content!
Latest hotfix: 0.7.5.2 (2024-09-10)
  • Hi, I would like to create an automated/controlled server shutdown. Now, firstly, is this already possible? In which case show me the way to Tipperary!


    What I would like to do is something similar to this:


    Step 1, global announcement to players that server is rebooting soon (easily done)
    Step 2, stop any new connections to the server (not sure if this is possible? maybe set max players to 0?)
    Step 3, after x period of time, kick any remaining players that are online (so that there are zero players online)
    Step 4, restart server script (not sure how to automate via java? (which is preferable)

  • Now, firstly, is this already possible? In which case show me the way to Tipperary!

    Through the API you can shutdown the server but you cannot restart it after atm

    Step 2, stop any new connections to the server (not sure if this is possible? maybe set max players to 0?)

    Well you can use the .setCancelled(true) method in the PlayerConnectEvent for this ;)

    Step 4, restart server script (not sure how to automate via java? (which is preferable)

    There are some restart scripts on the forum but none for java, server restarts are moslty done via shell commands, not sure if SteamCMD has any options like that too :/

  • I can always write a script starting the server, then call that script from Java.

    I know python has a subprocess module (https://docs.python.org/3/library/subprocess.html) in which you specify what code and in which language to execute it at that works really well for shell commands. Probably java has something similar but I haven't personally looked into it.

  • That's how I'm going to run a script from Java. 8)

  • The only issue when spawning a new process from within the JVM is that it's treated as a child process. This means if the JVM is closed, all child processes will be killed as well :/ You can add shutdown hooks to the JVM though (and start a new process there), but they're still affected by the death of the JVM (it kinda works on Windows but becomes very awkward on Linux)...

  • The only issue when spawning a new process from within the JVM is that it's treated as a child process. This means if the JVM is closed, all child processes will be killed as well :/ You can add shutdown hooks to the JVM though (and start a new process there), but they're still affected by the death of the JVM (it kinda works on Windows but becomes very awkward on Linux)...

    Thanks for that. I'm by no means knowledgeable about the real ins and outs of java. Still learning! :D


    So.


    I guess the easiest way around this is to schedule (via a plugin) a "clean shutdown" at say midnight.


    Then at, say 2 minutes past midnight set a Scheduled Task to run the server.


    :thumbup:

  • I guess the easiest way around this is to schedule (via a plugin) a "clean shutdown" at say midnight.

    Yes, that would work. You can either create a plugin which sends the messages and shuts the server down, or alternatively you can just send input commands to the server process (e.g. "shutdown" to shutdown the server, or "say" or "yell" to send a message to all players). In case you create a script to handle the restart, the input commands may be handier (so there is no need to use the plugin API at all) :)

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!