From c3ca975e8583365d459fcf5533842c36322c4ed8 Mon Sep 17 00:00:00 2001 From: Salt Date: Sat, 9 Jan 2021 22:35:20 -0600 Subject: [PATCH] Add a bunch of dysfunctional crap --- README.md | 3 +++ defaults/main.yml | 17 +++++++++++++++++ tasks/main.yml | 20 ++++++++++++++++++++ templates/terraria@.service | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/terraria@.service diff --git a/README.md b/README.md new file mode 100644 index 0000000..8bddd72 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# ansible-role-terraria + +A role to install a Terraria server. diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..30cbd9f --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,17 @@ +# vim:ft=ansible: +terraria_name: default +terraria_version: blah +terraria_enabled: yes +terraria_restart_delay: 5 + +# Packages +# Put any extra dependencies (for mods, etc.) in _extra +terraria_packages: + - mono-complete +terraria_packages_extra: [] + +# Server configuration +#terraria_downloadurl: + +# Service configuration +terraria_home: /opt/terraria diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..258a160 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,20 @@ +#!/usr/bin/env ansible-playbook +# vim:ft=ansible: +--- +- name: set up system + block: + - name: install required packages + apt: name="{{ terraria_packages + terraria_packages_extra }}" + - name: assure server user + user: name=terraria system=yes home={{ terraria_home }} + - name: assure operational directory + file: path={{ terraria_home }} state=directory owner=terraria group=terraria mode="3775" + - name: assure systemd unit + template: src=terraria@.service dest=/etc/systemd/system/terraria@.service + notify: "restart terraria {{ terraria_name }}" +- name: set up terraria + block: + - name: assure server directory + file: path={{ terraria_home }}/{{ terraria_name }} state=directory + become: yes + become_user: terraria diff --git a/templates/terraria@.service b/templates/terraria@.service new file mode 100644 index 0000000..7bf66dd --- /dev/null +++ b/templates/terraria@.service @@ -0,0 +1,36 @@ +# +# Licensed under the terms of the MIT license +# vim:ft=dosini: +# + +[Unit] +Description=Terraria Server %i +After=network.target + +[Service] +User=terraria +Group=terraria +WorkingDirectory={{ terraria_home }}/%i +EnvironmentFile={{ terraria_home }}/%i/env +PrivateUsers=true +ProtectSystem=full +ProtectHome=true +# Implies MountFlags=slave +ProtectKernelTunables=true +# Implies NoNewPrivileges=yes +ProtectKernelModules=true +# Implies MountAPIVFS=yes +ProtectControlGroups=true + +ExecStart=/bin/sh -c '/usr/bin/screen -DmS %i /usr/bin/java -Xms${JRE_XMS} -Xmx${JRE_XMX} -jar server.jar nogui' + +ExecReload=/usr/bin/screen -p 0 -S %i -X eval 'stuff "reload"\\015' + +ExecStop=/usr/bin/screen -p 0 -S %i -X eval 'stuff "say Server is going down: Service was stopped"\\015' +ExecStop=/usr/bin/screen -p 0 -S %i -X eval 'stuff "save-all"\\015' +ExecStop=/usr/bin/screen -p 0 -S %i -X eval 'stuff "stop"\\015' + +Restart=always + +[Install] +WantedBy=multi-user.target