Updated minecraft to be multi-world and minimized world size.
authorLuke Hoersten <luke@hoersten.org>
Sun, 18 Jul 2021 20:17:16 -0500
changeset 164 ae19501f5251
parent 163 40b78af86337
child 165 00e0af8e76a4
Updated minecraft to be multi-world and minimized world size.
minecraft/aws-s3-backup/files/minecraft-s3-backup-lifecycle.json
minecraft/aws-s3-backup/files/minecraft-s3-backup.sh
minecraft/aws-s3-backup/handlers/main.yaml
minecraft/aws-s3-backup/tasks/main.yaml
minecraft/aws-s3-backup/templates/[email protected]
minecraft/server/defaults/main.yaml
minecraft/server/handlers/main.yaml
minecraft/server/tasks/main.yaml
minecraft/server/templates/minecraft.service.j2
minecraft/server/templates/[email protected]
minecraft/server/vars/main.yaml
--- a/minecraft/aws-s3-backup/files/minecraft-s3-backup-lifecycle.json	Sun Jul 18 17:43:46 2021 -0500
+++ b/minecraft/aws-s3-backup/files/minecraft-s3-backup-lifecycle.json	Sun Jul 18 20:17:16 2021 -0500
@@ -5,7 +5,7 @@
 				"Filter": {},
 				"Status": "Enabled",
 				"NoncurrentVersionExpiration": {
-					 "NoncurrentDays": 5
+					 "NoncurrentDays": 30
 				}
 		  }
 	 ]
--- a/minecraft/aws-s3-backup/files/minecraft-s3-backup.sh	Sun Jul 18 17:43:46 2021 -0500
+++ b/minecraft/aws-s3-backup/files/minecraft-s3-backup.sh	Sun Jul 18 20:17:16 2021 -0500
@@ -1,10 +1,12 @@
 #!/bin/bash
 
-BUCKET=$1
+BACKUP_WORLD_NAME=$1
 BACKUP_DIR=$2
-BACKUP_TAR="/tmp/$BUCKET.tgz"
+BUCKET=$3
+BACKUP_TAR_DIR=$4
+BACKUP_TAR="${BACKUP_TAR_DIR}/${BUCKET}.tgz"
 
-tar -zc -f $BACKUP_TAR $BACKUP_DIR
+tar -zc -f $BACKUP_TAR -C $BACKUP_DIR $BACKUP_WORLD_NAME {$BACKUP_WORLD_NAME}_nether ${BACKUP_WORLD_NAME}_the_end
 aws s3 mb "s3://$BUCKET/"
 aws s3api put-bucket-versioning --bucket "$BUCKET" --versioning-configuration Status=Enabled
 aws s3api put-bucket-lifecycle-configuration --bucket "$BUCKET" --lifecycle-configuration "file:///usr/local/share/minecraft-s3-backup-lifecycle.json"
--- a/minecraft/aws-s3-backup/handlers/main.yaml	Sun Jul 18 17:43:46 2021 -0500
+++ b/minecraft/aws-s3-backup/handlers/main.yaml	Sun Jul 18 20:17:16 2021 -0500
@@ -1,5 +1,5 @@
 ---
 
 - name: reload s3 backup service
-  systemd: name="minecraft-s3-backup@{{minecraft_s3_backup_bucket}}.service" enabled="yes" daemon_reload="yes"
+  systemd: name="minecraft-s3-backup@{{minecraft_s3_backup_world_name}}.service" enabled="yes" daemon_reload="yes"
   become: yes
--- a/minecraft/aws-s3-backup/tasks/main.yaml	Sun Jul 18 17:43:46 2021 -0500
+++ b/minecraft/aws-s3-backup/tasks/main.yaml	Sun Jul 18 20:17:16 2021 -0500
@@ -14,13 +14,20 @@
     dest: "/usr/local/share/minecraft-s3-backup-lifecycle.json"
     mode: "0755"
 
+- name: create minecraft tar dir
+  become: yes
+  file:
+    path: "{{minecraft_s3_backup_tar_dir}}"
+    mode: "0755"
+    state: "directory"
+
 - name: configure minecraft s3 backup systemd service
   become: yes
   template:
     src: "[email protected]"
-    dest: "/lib/systemd/system/minecraft-s3-backup@{{minecraft_s3_backup_bucket}}.service"
+    dest: "/lib/systemd/system/minecraft-s3-backup@{{minecraft_s3_backup_world_name}}.service"
   notify: reload s3 backup service
 
 - name: ensure minecraft s3 backup service is started
   become: yes
-  systemd: name="minecraft-s3-backup@{{minecraft_s3_backup_bucket}}.service" enabled="yes"
+  systemd: name="minecraft-s3-backup@{{minecraft_s3_backup_world_name}}.service" enabled="yes"
--- a/minecraft/aws-s3-backup/templates/[email protected]	Sun Jul 18 17:43:46 2021 -0500
+++ b/minecraft/aws-s3-backup/templates/[email protected]	Sun Jul 18 20:17:16 2021 -0500
@@ -3,7 +3,7 @@
 
 [Service]
 Type=oneshot
-ExecStart=/usr/local/bin/minecraft-s3-backup.sh %i "{{minecraft_s3_backup_dir}}"
+ExecStart=/usr/local/bin/minecraft-s3-backup.sh %i "{{minecraft_s3_backup_dir}}" "{{minecraft_s3_backup_bucket}}" "{{minecraft_s3_backup_tar_dir}}"
 
 [Install]
 WantedBy=aws-s3-backup.target
--- a/minecraft/server/defaults/main.yaml	Sun Jul 18 17:43:46 2021 -0500
+++ b/minecraft/server/defaults/main.yaml	Sun Jul 18 20:17:16 2021 -0500
@@ -1,7 +1,6 @@
 ---
 
 minecraft_user: "minecraft"
-minecraft_fork: "vanilla" # paper
 minecraft_parent_dir: "/opt"
 minecraft_motd: "A Minecraft Server"
 minecraft_mem: "2G"
@@ -9,14 +8,13 @@
 minecraft_difficulty: "hard"
 minecraft_whitelist: "true"
 minecraft_view_distance: "10"
-
-minecraft_vanilla_hash: "0a269b5f2c5b93b1712d0f5dc43b6182b9ab254e"
+minecraft_world_name: "world"
 
 # https://papermc.io
 minecraft_paper_version: "1.17.1"
 minecraft_paper_build: "98"
 
-minecreat_paper_plugins_enabled:
+minecreat_plugins_enabled:
   - "dynmap"
   - "geyser"
 
--- a/minecraft/server/handlers/main.yaml	Sun Jul 18 17:43:46 2021 -0500
+++ b/minecraft/server/handlers/main.yaml	Sun Jul 18 20:17:16 2021 -0500
@@ -2,4 +2,4 @@
 
 - name: restart minecraft
   become: yes
-  systemd: name="minecraft.service" state="restarted" daemon_reload="yes"
+  systemd: name="minecraft@{{minecraft_world_name}}.service" state="restarted" daemon_reload="yes"
--- a/minecraft/server/tasks/main.yaml	Sun Jul 18 17:43:46 2021 -0500
+++ b/minecraft/server/tasks/main.yaml	Sun Jul 18 20:17:16 2021 -0500
@@ -2,19 +2,11 @@
 
 - name: add minecraft user
   become: yes
-  user: name="{{minecraft_user}}" home="{{minecraft_dir}}"
+  user: name="{{minecraft_user}}" home="{{minecraft_parent_dir}}/minecraft"
 
 - name: install adoptopenjdk
   include_tasks: adoptopenjdk.yaml
 
-- name: set minecraft fork
-  set_fact: minecraft_url="{{minecraft_vanilla_url}}"
-  when: minecraft_fork == "vanilla"
-
-- name: set minecraft fork
-  set_fact: minecraft_url="{{minecraft_paper_url}}"
-  when: minecraft_fork == "paper"
-
 - name: create minecraft dir
   become: yes
   file:
@@ -72,8 +64,7 @@
 
 - name: install plugins
   include_tasks: "{{item}}.yaml"
-  loop: "{{minecreat_paper_plugins_enabled}}"
-  when: minecraft_fork == "paper"
+  loop: "{{minecreat_plugins_enabled}}"
 
 - name: create server.properties
   become: yes
@@ -94,6 +85,7 @@
   notify: restart minecraft
   loop:
     - {key: "motd", value: "{{minecraft_motd}}"}
+    - {key: "level-name", value: "{{minecraft_world_name}}"}
     - {key: "level-seed", value: "{{minecraft_seed}}"}
     - {key: "difficulty", value: "{{minecraft_difficulty}}"}
     - {key: "white-list", value: "{{minecraft_whitelist}}"}
@@ -104,10 +96,10 @@
 - name: install systemd service
   become: yes
   template:
-    src: "minecraft.service.j2"
-    dest: "/lib/systemd/system/minecraft.service"
+    src: "[email protected]"
+    dest: "/lib/systemd/system/[email protected]"
   notify: restart minecraft
 
 - name: ensure service is started
   become: yes
-  systemd: name="minecraft.service" enabled="yes" state="started"
+  systemd: name="minecraft@{{minecraft_world_name}}.service" enabled="yes" state="started"
--- a/minecraft/server/templates/minecraft.service.j2	Sun Jul 18 17:43:46 2021 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-[Unit]
-Description=Minecraft Server
-Documentation=https://minecraft.gamepedia.com/Tutorials/Setting_up_a_server
-
-Wants=network.target
-After=network.target
-
-[Service]
-User={{minecraft_user}}
-Group={{minecraft_user}}
-WorkingDirectory={{minecraft_dir}}
-Restart=on-failure
-RestartSec=20 5
-ExecStart=/usr/bin/java -Xms{{minecraft_mem}} -Xmx{{minecraft_mem}} -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar server.jar nogui
-
-PrivateTmp=true
-ProtectSystem=full
-NoNewPrivileges=true
-PrivateDevices=true
-
-[Install]
-WantedBy=multi-user.target
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/minecraft/server/templates/[email protected]	Sun Jul 18 20:17:16 2021 -0500
@@ -0,0 +1,20 @@
+[Unit]
+Description=Minecraft Server %I
+Documentation=https://minecraft.gamepedia.com/Tutorials/Setting_up_a_server
+After=network.target
+
+[Service]
+User={{minecraft_user}}
+Group={{minecraft_user}}
+WorkingDirectory={{minecraft_parent_dir}}/minecraft/%i
+Restart=on-failure
+RestartSec=20 5
+ExecStart=/usr/bin/java -Xms{{minecraft_mem}} -Xmx{{minecraft_mem}} -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar server.jar nogui
+
+PrivateTmp=true
+ProtectSystem=full
+NoNewPrivileges=true
+PrivateDevices=true
+
+[Install]
+WantedBy=multi-user.target
--- a/minecraft/server/vars/main.yaml	Sun Jul 18 17:43:46 2021 -0500
+++ b/minecraft/server/vars/main.yaml	Sun Jul 18 20:17:16 2021 -0500
@@ -1,8 +1,7 @@
 ---
 
-minecraft_dir: "{{minecraft_parent_dir}}/minecraft/{{minecraft_fork}}"
-minecraft_paper_url: "https://papermc.io/api/v1/paper/{{minecraft_paper_version}}/{{minecraft_paper_build}}/download"
-minecraft_vanilla_url: "https://launcher.mojang.com/v1/objects/{{minecraft_vanilla_hash}}/server.jar"
+minecraft_dir: "{{minecraft_parent_dir}}/minecraft/{{minecraft_world_name}}"
+minecraft_url: "https://papermc.io/api/v1/paper/{{minecraft_paper_version}}/{{minecraft_paper_build}}/download"
 
 # paper is a spigot derivative
 minecraft_dynmap_url: "http://dynmap.us/builds/dynmap/Dynmap-{{minecraft_dynmap_version}}-spigot.jar"