Stop Spigot server gracefuly - best practices?

Discussion in 'Spigot Help' started by Bongos, May 29, 2015.

Thread Status:
Not open for further replies.
  1. Hey there.

    Using init-script. Spigot spawning as background process without console.
    Is there any way like send kill <process_id> that would shutdown instance gracefully, with saving all chunks?


    console stop command:
    Code (Text):
    [21:38:51 INFO]: Stopping the server
    [21:38:51 INFO]: Stopping server
    [21:38:51 INFO]: Saving players
    [21:38:51 INFO]: Saving worlds
    [21:38:51 INFO]: Saving chunks for level 'world'/Overworld
    [21:38:51 INFO]: Saving chunks for level 'world_nether'/Nether
    [21:38:51 INFO]: Saving chunks for level 'world_the_end'/The End
    [email protected]:~/server$
    killing process:
    looks like kill command do not save server data properly
    Code (Text):
    [21:54:34 INFO]: Stopping server
    [email protected]:~/server$
     
    #1 Bongos, May 29, 2015
    Last edited: May 29, 2015
  2. The only way is to run server through screen, then attaching to it and type "stop"?
     
  3. rcon could work, or print stuff into the screen. i have a way, but i cant find it.
     
    • Like Like x 1
  4. JamesJ

    Supporter

    What?
    What's wrong with the logging? That shows that it's saving the chunks/world/playerdata..
     
    • Like Like x 1
  5. First one method was about entering "/stop" in minecraft console. When stopping, minecraft server saved data immediatly.
    Second one method was about killing minecraft server process by sending SIGTERM. It's not saving data while stopping.

    I was searching for a way to automize Spigot server as service on linux machine by using some kind of init or autorun script, but stuck with this issue about inability to send "/stop" command to minecraft server console, because process would exist at background.
     
    #6 Bongos, Jun 8, 2015
    Last edited: Jun 8, 2015
    • Optimistic Optimistic x 2
  6. JamesJ

    Supporter

    I think you're completely confused about either stopping a Minecraft server, running one or both.
     
  7. No, it's not the case. I'm totally fine with them.
    Probably there's a misunderstanding between "terminal console" and "minecraft server console", and words "server" and "service" - those looks similar and reading them in one sentence could be confusable.

    It is usual practice to run apps or servers as services on Linux servers, so managing them would be as easy as "service minecraft start" or "service minecraft stop".
    All I wanted to know, is what practice here exists related to running Spigot as a service.

    Previously I tried to wrap a standart start line (java -Xms512M -Xmx2048M -XX:MaxPermSize=128M -jar minecraft.jar) as upstart-script on Ubuntu, but the issue is SIGTERM - it's not asking minecraft server to dump world chunks on disk, it's just closing the server.
    "stop" command, on the other hand, is asking server to save chunks before closing it. So I can't use "service minecraft stop" with such upstart script, as it would try to just send "kill" command to spawned process, and it would close itself without saving chunks.
    So the only way to ask server to save chunks is write "stop" in it's console. The problem is - java process spawned by init script is detached from user and don't have any way to receive any console commands, so there is no way I could type "stop" before stopping server (to save chunks), or make it so "service minecraft stop" would send "stop" command to the minecraft server console by itself.

    I tried to ask from anyone of you, if you already managed to create some simple upstart- or init-script to spawn Spigot server and close it correctly, with saving all the chunks.

    Here I mentioned what I used to achieve that, but this init script is quite overloaded with features and "init.d" by itself - kinda outdated technology nowadays. Was interested, if someone had their own solution to this with upstart-script or something else.
     
    #8 Bongos, Jun 8, 2015
    Last edited: Jun 8, 2015
    • Like Like x 2
  8. Hi @Bongos

    Any ideas about it? I don´t want to use Multicraft anymore and ingame stop is not a good option since I´m on work in the day.
     
  9. I ended using this init-script:
    https://github.com/Ahtenus/minecraft-init

    Some of it's options are designed for Vanilla/CraftBukkit, but every basic operation is compatible with Spigot, like start/stop/logs/screen_entering.

    Give it a try ;)
     
  10. My systemd service description (without screen) looks like:
    Code (Text):
    [Unit]
    Description=Minecraft SpigotMC Server
    #remove mariadb.service if you don't need a database for your plugins
    After=network.target mariadb.service

    [Service]
    WorkingDirectory=/opt/minecraft-server

    Type=simple
    ExecStartPre=/usr/bin/mkfifo ./daemon.in
    #use sh for redirecting input
    # open daemon.in by redirecting stream 3 (unused) to it and exec java using stream 3
    # ( ; seems to have special meaning. Enclosing the whole sh script in '' doesn't matter either... )
    ExecStart=/bin/sh -c 'exec /usr/bin/java -server -Xmx1024M -Xms408M -jar ./spigot-1.11.2.jar 3<>./daemon.in -<&3'
    KillMode=none
    #took me hours to figure out the double escape. \r works so I don't even want to try \n .
    ExecStop=/bin/sh -c 'echo stop$(printf \\\\r) > ./daemon.in'
    ExecStopPost=/bin/rm ./daemon.in

    StandardOutput=journal
    User=minecraft
    Group=minecraft

    [Install]
    WantedBy=multi-user.target
    It should be possible to write commands to ./daemon.in - just use the right permissions and don't forget the newline. Output can be fetched using "journalctl -xe".


    If you really want systemd+screen:
    Code (Text):
    [Unit]
    Description=Minecraft SpigotMC Server screened
    After=network.target

    [Service]
    WorkingDirectory=/opt/minecraft-server

    Type=oneshot
    ExecStart=/usr/bin/screen -dmS "spigotMC" /usr/bin/java -server -Xmx1024M -Xms408M -jar "./spigot-1.11.2.jar"
    ExecStop=/usr/bin/screen -S "spigotMC" -p 0 -X stuff "stop$(printf \\\\r)"
    RemainAfterExit=true

    StandardOutput=journal
    User=minecraft
    Group=minecraft

    [Install]
    WantedBy=multi-user.target
    Posted here because a certain search engine finds this thread and it is an alternative to the previously mentioned init+screen approach.
     
    • Like Like x 1
  11. mathhulk

    mathhulk Retired Moderator
    Retired

    Going to lock this instead of also deleting the previous reply as it could provide use to someone. However, please do not bump or post on threads of this age @pucgenie.
     
Thread Status:
Not open for further replies.