Made minecraft role support vanilla and paper forks.
--- a/papermc/defaults/main.yaml Fri Jul 03 09:38:16 2020 -0500
+++ b/papermc/defaults/main.yaml Fri Jul 03 12:00:27 2020 -0500
@@ -1,10 +1,12 @@
---
-papermc_user: "papermc"
-papermc_version: "1.16.1"
-papermc_build: "34"
-papermc_url: "https://papermc.io/api/v1/paper/{{papermc_version}}/{{papermc_build}}/download"
-papermc_dir: "/opt/papermc"
-papermc_motd: "A Minecraft Server"
-papermc_mem: "2G"
-papermc_seed: ""
+minecraft_user: "minecraft"
+minecraft_fork: "vanilla" # paper
+minecraft_parent_dir: "/opt"
+minecraft_motd: "A Minecraft Server"
+minecraft_mem: "2G"
+minecraft_seed: ""
+
+minecraft_paper_version: "1.16.1"
+minecraft_paper_build: "34"
+minecraft_vanilla_hash: "a412fd69db1f81db3f511c1463fd304675244077"
--- a/papermc/handlers/main.yaml Fri Jul 03 09:38:16 2020 -0500
+++ b/papermc/handlers/main.yaml Fri Jul 03 12:00:27 2020 -0500
@@ -1,5 +1,5 @@
---
-- name: restart papermc
+- name: restart minecraft
become: yes
- systemd: name="papermc.service" state="restarted" daemon_reload="yes"
+ systemd: name="minecraft.service" state="restarted" daemon_reload="yes"
--- a/papermc/tasks/main.yaml Fri Jul 03 09:38:16 2020 -0500
+++ b/papermc/tasks/main.yaml Fri Jul 03 12:00:27 2020 -0500
@@ -1,59 +1,78 @@
---
-- name: add papermc user
+- name: add minecraft user
become: yes
- user: name="{{papermc_user}}" home="{{papermc_dir}}"
+ user: name="{{minecraft_user}}" home="{{minecraft_dir}}"
- name: install jre
become: yes
apt: name="default-jre-headless"
-- name: download papermc
+- 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:
+ path: "{{minecraft_dir}}"
+ owner: "{{minecraft_user}}"
+ group: "{{minecraft_user}}"
+ mode: "0755"
+ state: "directory"
+
+- name: download minecraft
become: yes
get_url:
- url: "{{papermc_url}}"
- dest: "{{papermc_dir}}/server.jar"
+ url: "{{minecraft_url}}"
+ dest: "{{minecraft_dir}}/server.jar"
mode: "0755"
- notify: restart papermc
+ notify: restart minecraft
-- name: configure eula and ops
+- name: configure minecraft eula and ops
become: yes
copy:
src: "{{item}}"
- dest: "{{papermc_dir}}/{{item}}"
- owner: "{{papermc_user}}"
- group: "{{papermc_user}}"
+ dest: "{{minecraft_dir}}/{{item}}"
+ owner: "{{minecraft_user}}"
+ group: "{{minecraft_user}}"
loop:
- "eula.txt"
- "ops.json"
- notify: restart papermc
+ notify: restart minecraft
- name: create server.properties
become: yes
file:
- path: "{{papermc_dir}}/server.properties"
+ path: "{{minecraft_dir}}/server.properties"
state: "touch"
- owner: "{{papermc_user}}"
- group: "{{papermc_user}}"
+ access_time: "preserve"
+ modification_time: "preserve"
+ owner: "{{minecraft_user}}"
+ group: "{{minecraft_user}}"
- name: configure server.properties
become: yes
lineinfile:
- path: "{{papermc_dir}}/server.properties"
+ path: "{{minecraft_dir}}/server.properties"
regexp: "^{{item.key}}="
line: "{{item.key}}={{item.value}}"
- notify: restart papermc
+ notify: restart minecraft
loop:
- - {key: "motd", value: "{{papermc_motd}}"}
- - {key: "level-seed", value: "{{papermc_seed}}"}
+ - {key: "motd", value: "{{minecraft_motd}}"}
+ - {key: "level-seed", value: "{{minecraft_seed}}"}
- name: install systemd service
become: yes
template:
- src: "papermc.service.j2"
- dest: "/lib/systemd/system/papermc.service"
- notify: restart papermc
+ src: "minecraft.service.j2"
+ dest: "/lib/systemd/system/minecraft.service"
+ notify: restart minecraft
- name: ensure service is started
become: yes
- systemd: name="papermc.service" enabled="yes" state="started"
+ systemd: name="minecraft.service" enabled="yes" state="started"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/papermc/templates/minecraft.service.j2 Fri Jul 03 12:00:27 2020 -0500
@@ -0,0 +1,22 @@
+[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
--- a/papermc/templates/papermc.service.j2 Fri Jul 03 09:38:16 2020 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-[Unit]
-Description=PaperMC Server
-Documentation=https://paper.readthedocs.io/en/latest/server/getting-started.html
-
-Wants=network.target
-After=network.target
-
-[Service]
-User={{papermc_user}}
-Group={{papermc_user}}
-WorkingDirectory={{papermc_dir}}
-Restart=on-failure
-RestartSec=20 5
-# ExecStart=/usr/bin/java -Xms{{papermc_mem}} -Xmx{{papermc_mem}} -jar server.jar
-# Optimizations from https://aikar.co/2018/07/02/tuning-the-jvm-g1gc-garbage-collector-flags-for-minecraft/
-ExecStart=/usr/bin/java -Xms{{papermc_mem}} -Xmx{{papermc_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/papermc/vars/main.yaml Fri Jul 03 12:00:27 2020 -0500
@@ -0,0 +1,5 @@
+---
+
+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"