Compare commits

...

3 Commits

Author SHA1 Message Date
0041c0e82d Add README 2021-01-10 20:06:25 -06:00
b3c3007e5b Minor fixes 2021-01-10 19:55:26 -06:00
0715707452 Add a hopefully functional implementation
Time to test
2021-01-10 19:50:20 -06:00
6 changed files with 108 additions and 8 deletions

View File

@ -1,3 +1,43 @@
# ansible-role-terraria
A role to install a Terraria server.
## Supported Configuration
The role supporst the following distros:
* Anything Debian-like
The only real dependency is Mono. If you can get that installed some other way, the role will probably work on any distro.
## Basic Setup
Template out the role, ensuring it has root privileges. Consider setting the following vars:
```yaml
terraria_name: Name of the subdirectory of the server
terraria_version: The Terraria version string, sans periods (ex. 1412)
terraria_enabled: Boolean to determine the state of the server (defaults to yes)
```
More handy variables can be found in `defaults`.
You can manage server-config through the `terraria_config` dictionary:
```yaml
terraria_config:
max-players: 8
password: supersecret
```
Run the play and enjoy.
## Administration
The role will install servers as systemd units. A server named `default` will have the unit `terraria@default.service`. The server runs as its own user.
To access the server console, invoke `screen` as the `terraria` user. For example, to access the console of a server named `default`, use `sudo -u terraria screen -r default`.
## TODO
The biggest issue is that Redigit doesn't have a very... friendly server URL scheme. Often, if you want to download an updated server package, you'll have to manually change the `terraria_downloadurl`. Solutions to this problem are welcome.

View File

@ -1,6 +1,6 @@
# vim:ft=ansible:
terraria_name: default
terraria_version: blah
terraria_version: 1412
terraria_enabled: yes
terraria_restart_delay: 5
@ -11,7 +11,14 @@ terraria_packages:
terraria_packages_extra: []
# Server configuration
#terraria_downloadurl:
terraria_downloadurl: "https://terraria.org/system/dedicated_servers/archives/000/000/042/original/terraria-server-{{ terraria_version }}.zip"
terraria_config_default:
autocreate: 3
difficulty: 0
port: 7777
world: "{{ terraria_home }}/{{ terraria_name }}/worlds/world.wld"
worldpath: "{{ terraria_home }}/{{ terraria_name }}/worlds"
terraria_config: {}
# Service configuration
terraria_home: /opt/terraria

9
handlers/main.yml Normal file
View File

@ -0,0 +1,9 @@
#!/usr/bin/ansible-playbook
# vim:ft=ansible:
---
- name: "restart terraria {{ terraria_name }}"
systemd:
name: "terraria@{{ terraria_name }}"
state: restarted
become: yes
when: terraria_enabled

View File

@ -16,5 +16,36 @@
block:
- name: assure server directory
file: path={{ terraria_home }}/{{ terraria_name }} state=directory
- name: download server zip
get_url: url={{ terraria_downloadurl }} dest={{ terraria_home }}/{{ terraria_name }}/server.zip
register: download_server
- name: install server
block:
- name: assure server unzip directory
file: path={{ terraria_home }}/{{ terraria_name }}/server state=directory
- name: unpack zip
unarchive: src={{ terraria_home }}/{{ terraria_name }}/server.zip dest={{ terraria_home }}/{{ terraria_name }}/server remote_src=yes
- name: template out installer
template: src=install-server.sh dest={{ terraria_home }}/{{ terraria_name }}/install-server.sh
- name: run installer
command:
chdir: "{{ terraria_home }}/{{ terraria_name }}"
argv: [ "bash", "./install-server.sh" ]
notify: "restart terraria {{ terraria_name }}"
when: download_server is changed
- name: configure server settings
lineinfile:
dest: "{{ terraria_home }}/{{ terraria_name }}/config"
line: "{{ item.key }}={{ item.value }}"
regex: "^{{ item.key }}=.*"
create: yes
with_dict: "{{ terraria_config_default | combine(terraria_config) }}"
notify: "restart terraria {{ terraria_name }}"
become: yes
become_user: terraria
- name: enable service
systemd: name=terraria@{{ terraria_name }}.service enabled=yes state=started
when: terraria_enabled
- name: disable service
systemd: name=terraria@{{ terraria_name }}.service enabled=no state=stopped
when: not terraria_enabled

View File

@ -0,0 +1,16 @@
#! /bin/sh
# Find out where our server lives
# Ideally, this won't change at all over time. @redigit please keep these
# naming conventions
directory="server/{{ terraria_version }}/Linux"
echo "Syncing from $directory/"
# Now we rsync everything from that directory here, which should set us up
rsync -av "$directory"/ ./
# I'm not sure if it's just zip being zip or if it's Redigit not packing
# them properly, but I've found that the server executables tend to not have
# the right permissions
echo "Fixing permissions on server binaries"
find -maxdepth 1 -type f -iname "terrariaserver*" -exec chmod +x {} +

View File

@ -11,7 +11,7 @@ After=network.target
User=terraria
Group=terraria
WorkingDirectory={{ terraria_home }}/%i
EnvironmentFile={{ terraria_home }}/%i/env
#EnvironmentFile={{ terraria_home }}/%i/env
PrivateUsers=true
ProtectSystem=full
ProtectHome=true
@ -22,13 +22,10 @@ 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'
ExecStart=/bin/sh -c '/usr/bin/screen -DmS %i ./TerrariaServer.bin.x86_64 -config config'
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'
ExecStop=/usr/bin/screen -p 0 -S %i -X eval 'stuff "exit"\\015'
Restart=always