Skip to content

Commit

Permalink
add save command
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed Apr 18, 2017
1 parent 50f02f7 commit 1938e91
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/minecraftctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ LEVEL=${LEVEL-world}
TIMEOUT=${TIMEOUT-0}

usage() {
echo "Usage: $0 [start|stop|restart|status|backup] <name>"
echo "Usage: $0 [start|stop|restart|status|save|backup] <name>"
echo ""
echo "Name is a name for the container and the data dir"
exit 1
Expand Down Expand Up @@ -66,7 +66,7 @@ start() {
exit 0
fi
stop_container

vol_mount="--volume=$DATA_DIR/$name:/data"
if $EPHEMERAL
then
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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..."
Expand Down Expand Up @@ -217,6 +224,9 @@ restart)
backup)
backup
;;
save)
save
;;
*)
usage
;;
Expand Down
6 changes: 6 additions & 0 deletions src/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Unit]
Description=Save %I Minceraft server

[Service]
Type=oneshot
ExecStart=/usr/bin/minecraftctl save %i
11 changes: 11 additions & 0 deletions src/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Daily save of Minecraft server %i

[Timer]
OnCalendar=daily
Persistent=true


[Install]
WantedBy=multi-user.target

0 comments on commit 1938e91

Please sign in to comment.