From 1938e91cb1049e893d4487207203055b8064b4ba Mon Sep 17 00:00:00 2001 From: Nathaniel Cook Date: Mon, 17 Apr 2017 19:56:30 -0600 Subject: [PATCH] add save command --- src/minecraftctl.sh | 22 ++++++++++++++++------ src/minecraftd-save@.service | 6 ++++++ src/minecraftd-save@.timer | 11 +++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/minecraftd-save@.service create mode 100644 src/minecraftd-save@.timer diff --git a/src/minecraftctl.sh b/src/minecraftctl.sh index 819fec8..08c2f1d 100755 --- a/src/minecraftctl.sh +++ b/src/minecraftctl.sh @@ -38,7 +38,7 @@ LEVEL=${LEVEL-world} TIMEOUT=${TIMEOUT-0} usage() { - echo "Usage: $0 [start|stop|restart|status|backup] " + echo "Usage: $0 [start|stop|restart|status|save|backup] " echo "" echo "Name is a name for the container and the data dir" exit 1 @@ -66,7 +66,7 @@ start() { exit 0 fi stop_container - + vol_mount="--volume=$DATA_DIR/$name:/data" if $EPHEMERAL then @@ -109,9 +109,9 @@ start() { -e "UID=$MINECRAFT_UID" \ -e "GID=$MINECRAFT_GID" \ itzg/minecraft-server - + echo "Started minecraft container $name" - + } # Send a command to the game server @@ -128,11 +128,18 @@ game_command() { wait } +# Do a world save +save() { + game_command "save-all flush" "Saved the world" + game_command "say Saved the world" +} + + # Do a world backup backup() { filename="$name-$(date +%Y_%m_%d_%H.%M.%S).tar.gz" - game_command "say Starting backup..." + game_command "say Starting backup..." # Make sure we always turn saves back on set +e ret=0 @@ -162,7 +169,7 @@ stop() { game_command "save-all" for i in {10..1} do - game_command "say Server shutting down in ${i}s..." + game_command "say Server shutting down in ${i}s..." sleep 1 done game_command "say Shutting down..." @@ -217,6 +224,9 @@ restart) backup) backup ;; +save) + save + ;; *) usage ;; diff --git a/src/minecraftd-save@.service b/src/minecraftd-save@.service new file mode 100644 index 0000000..bdf75f2 --- /dev/null +++ b/src/minecraftd-save@.service @@ -0,0 +1,6 @@ +[Unit] +Description=Save %I Minceraft server + +[Service] +Type=oneshot +ExecStart=/usr/bin/minecraftctl save %i diff --git a/src/minecraftd-save@.timer b/src/minecraftd-save@.timer new file mode 100644 index 0000000..8928888 --- /dev/null +++ b/src/minecraftd-save@.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Daily save of Minecraft server %i + +[Timer] +OnCalendar=daily +Persistent=true + + +[Install] +WantedBy=multi-user.target +