Minecraft modpacks.ch server management

This commit is contained in:
Kris Lamoureux 2021-06-16 22:49:01 -04:00
parent 6a73e4120e
commit f44ac239d9
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925
9 changed files with 166 additions and 65 deletions

View File

@ -6,4 +6,11 @@ manage_network: false
# Agree to EULA to start service in Vagrant
# i.e. sed -i 's/^#minecraft_eula/minecraft_eula/' ./dev/host_vars/minecraft.yml
#minecraft_eula: true
minecraft_sha1: 1b557e7b033b583cd9f66746b7a9ab1ec1673ced # 1.16.5
minecraft_onboot: vanilla
minecraft:
- name: vanilla # 1.16.5 (https://mcversions.net/download/1.16.5)
sha1: 1b557e7b033b583cd9f66746b7a9ab1ec1673ced
- name: revelation # 3.4.0 (https://api.modpacks.ch/public/modpack/35/174)
modpack: 35/174
java: 8

View File

@ -1,6 +1,8 @@
minecraft_eula: false
minecraft_home: "/opt/minecraft"
minecraft_url: "https://launcher.mojang.com/v1/objects/{{ minecraft_sha1 }}/server.jar"
minecraft_java: 11
minecraft_modpack_url: "https://api.modpacks.ch/public/modpack/{{ item.modpack }}/server/linux"
minecraft_url: "https://launcher.mojang.com/v1/objects/{{ item.sha1 }}/server.jar"
minecraft_user: minecraft
minecraft_xms: 1G
minecraft_xmx: "{{ minecraft_xms }}"

View File

@ -0,0 +1,47 @@
- name: Install GPG
apt:
name: gpg
state: present
when: item.java is defined and item.java == 8
loop: "{{ minecraft }}"
- name: Add AdoptOpenJDK's signing key
apt_key:
id: 8ED17AF5D7E675EB3EE3BCE98AC3B29174885C03
url: https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public
when: item.java is defined and item.java == 8
loop: "{{ minecraft }}"
- name: Install AdoptOpenJDK repository
apt_repository:
repo: deb https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ buster main
mode: 0644
state: present
when: item.java is defined and item.java == 8
loop: "{{ minecraft }}"
- name: Install Java 8
apt:
name: adoptopenjdk-8-hotspot
state: present
when: item.java is defined and item.java == 8
loop: "{{ minecraft }}"
- name: Install Java 11
apt:
name: openjdk-11-jre
state: present
when: item.java is not defined or item.java == 11
loop: "{{ minecraft }}"
- name: Activate Java 8
alternatives:
name: java
path: /usr/lib/jvm/adoptopenjdk-8-hotspot-amd64/jre/bin/java
when: minecraft_java == 8
- name: Activate Java 11
alternatives:
name: java
path: /usr/lib/jvm/java-11-openjdk-amd64/bin/java
when: minecraft_java == 11

View File

@ -1,55 +1,14 @@
- name: Install Screen
apt:
name: screen
state: present
- name: Install Java
apt:
name: default-jre
state: present
- name: Create Minecraft user
user:
name: "{{ minecraft_user }}"
state: present
shell: /bin/bash
- name: Create Minecraft directory
file:
path: "{{ minecraft_home }}"
state: directory
owner: "{{ minecraft_user }}"
group: "{{ minecraft_user }}"
- name: Download Minecraft
get_url:
url: "{{ minecraft_url }}"
dest: "{{ minecraft_home }}/minecraft_server.jar"
checksum: "sha1:{{ minecraft_sha1 }}"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_user }}"
mode: 0700
- name: Deploy Minecraft systemd service
template:
src: minecraft.service.j2
dest: "/etc/systemd/system/minecraft.service"
register: minecraft_systemd
- name: Answer to Mojang's EULA
template:
src: eula.txt.j2
dest: "{{ minecraft_home }}/eula.txt"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_user }}"
- name: Reload systemd manager configuration
systemd:
daemon_reload: true
when: minecraft_systemd.changed
- name: Start Service
service:
name: minecraft
state: started
- import_tasks: system.yml
when: minecraft_eula
- import_tasks: java.yml
when: minecraft_eula
- import_tasks: vanilla.yml
when: minecraft_eula
- import_tasks: modpacks.yml
when: minecraft_eula
- import_tasks: service.yml
when: minecraft_eula

View File

@ -0,0 +1,33 @@
- name: Download Minecraft modpack installer
get_url:
url: "{{ minecraft_modpack_url }}"
dest: "{{ minecraft_home }}/{{ item.name }}/serverinstall_{{ item.modpack | replace ('/', '_') }}"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_user }}"
mode: 0700
loop: "{{ minecraft }}"
when: item.modpack is defined and item.sha1 is not defined
- name: Run Minecraft modpack installer
command: "sudo -u {{ minecraft_user }} ./serverinstall_{{ item.modpack | replace ('/', '_') }} --auto"
args:
creates: "{{ minecraft_home }}/{{ item.name }}/mods"
chdir: "{{ minecraft_home }}/{{ item.name }}"
loop: "{{ minecraft }}"
when: item.modpack is defined and item.sha1 is not defined
- name: Find Minecraft Forge
find:
paths: "{{ minecraft_home }}/{{ item.name }}"
patterns: "forge*.jar"
register: minecraft_forge
loop: "{{ minecraft }}"
when: item.modpack is defined and item.sha1 is not defined
- name: Link to Minecraft Forge
file:
src: "{{ item.files[0].path }}"
dest: "{{ minecraft_home }}/{{ item.item.name }}/minecraft_server.jar"
state: link
loop: "{{ minecraft_forge.results }}"
when: minecraft_forge is defined and item.files[0].path is defined

View File

@ -0,0 +1,17 @@
- name: Deploy Minecraft systemd service
template:
src: minecraft.service.j2
dest: "/etc/systemd/system/minecraft@.service"
register: minecraft_systemd
- name: Reload systemd manager configuration
systemd:
daemon_reload: true
when: minecraft_systemd.changed
- name: Start Service
service:
name: "minecraft@{{ minecraft_onboot }}"
state: started
enabled: true
when: minecraft_eula and minecraft_onboot is defined

View File

@ -0,0 +1,26 @@
- name: Install Screen
apt:
name: screen
state: present
- name: Create Minecraft user
user:
name: "{{ minecraft_user }}"
state: present
shell: /bin/bash
- name: Create Minecraft directory
file:
path: "{{ minecraft_home }}/{{ item.name }}"
state: directory
owner: "{{ minecraft_user }}"
group: "{{ minecraft_user }}"
loop: "{{ minecraft }}"
- name: Answer to Mojang's EULA
template:
src: eula.txt.j2
dest: "{{ minecraft_home }}/{{ item.name }}/eula.txt"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_user }}"
loop: "{{ minecraft }}"

View File

@ -0,0 +1,10 @@
- name: Download Minecraft
get_url:
url: "{{ minecraft_url }}"
dest: "{{ minecraft_home }}/{{ item.name }}/minecraft_server.jar"
checksum: "sha1:{{ item.sha1 }}"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_user }}"
mode: 0700
loop: "{{ minecraft }}"
when: item.sha1 is defined

View File

@ -1,26 +1,26 @@
[Unit]
Description=Minecraft Server
Description=Minecraft Server: %i
After=network.target
[Service]
Type=simple
WorkingDirectory={{ minecraft_home }}
WorkingDirectory={{ minecraft_home }}/%i
User={{ minecraft_user }}
Group={{ minecraft_user }}
Restart=always
ExecStart=/usr/bin/screen -DmS minecraft \
ExecStart=/usr/bin/screen -DmS minecraft-%i \
/usr/bin/java -Xms{{ minecraft_xms }} -Xmx{{ minecraft_xmx }} -jar minecraft_server.jar nogui
ExecReload=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "reload"\\015'
ExecStop=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "say SERVER SHUTDOWN IN 30 SECONDS"\015'
ExecReload=/usr/bin/screen -p 0 -S minecraft-%i -X eval 'stuff "reload"\\015'
ExecStop=/usr/bin/screen -p 0 -S minecraft-%i -X eval 'stuff "say SERVER SHUTDOWN IN 30 SECONDS"\015'
ExecStop=/bin/sleep 15
ExecStop=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "say SERVER SHUTDOWN IN 15 SECONDS"\015'
ExecStop=/usr/bin/screen -p 0 -S minecraft-%i -X eval 'stuff "say SERVER SHUTDOWN IN 15 SECONDS"\015'
ExecStop=/bin/sleep 10
ExecStop=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "say SERVER SHUTDOWN IN 5 SECONDS"\015'
ExecStop=/usr/bin/screen -p 0 -S minecraft-%i -X eval 'stuff "say SERVER SHUTDOWN IN 5 SECONDS"\015'
ExecStop=/bin/sleep 5
ExecStop=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "save-all"\015'
ExecStop=/usr/bin/screen -p 0 -S minecraft-%i -X eval 'stuff "save-all"\015'
ExecStop=/bin/sleep 1
ExecStop=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "stop"\015'
ExecStop=/usr/bin/screen -p 0 -S minecraft-%i -X eval 'stuff "stop"\015'
ExecStop=/bin/sleep 3
[Install]