I use screen
to run a Minecraft server, and I restart it every day. This is my start code:
screen -mdS mcserver
screen -S mcserver -p 0 -X stuff "java -Xmx4G -jar server.jar^M"
This is my stop code:
screen -S mcserver -p 0 -X stuff "stop^M"
sleep 10
screen -XS mcserver quit
Sending the command stop
makes the Minecraft server save the world, which can take a few seconds. Is there a way to make the program wait until java
(The Minecraft server) isn't running and then kill screen
? If I kill screen
before I send stop
to Minecraft, the world can have a few glitches. (Player items desync from the world blocks, people lose items, and accidentally duplicate stuff)
seems scriptable to me. You could try doing something simply like this
This basically loops until server.jar is not found in the process list, then it breaks out of the loop. Since the loop is broken, it should be safe to shutdown the screen session