Deploy a new tmodloader serber
This commit is contained in:
parent
42f8c8aa35
commit
75424d6d82
@ -36,6 +36,11 @@
|
|||||||
mcviewdist: 14
|
mcviewdist: 14
|
||||||
mcleveltype: "default"
|
mcleveltype: "default"
|
||||||
tags: [ gameserver, minecraft, me5 ]
|
tags: [ gameserver, minecraft, me5 ]
|
||||||
|
- role: tmodloader
|
||||||
|
vars:
|
||||||
|
terraria_name: "calamity"
|
||||||
|
terraria_password: "dicks"
|
||||||
|
tags: [ gameserver, terraria, calamity ]
|
||||||
tasks:
|
tasks:
|
||||||
- name: Assure Minecraft CNAME record
|
- name: Assure Minecraft CNAME record
|
||||||
route53:
|
route53:
|
||||||
@ -47,7 +52,7 @@
|
|||||||
ttl: 3600
|
ttl: 3600
|
||||||
value: [ "{{ inventory_hostname }}." ]
|
value: [ "{{ inventory_hostname }}." ]
|
||||||
become: yes
|
become: yes
|
||||||
tags: [ dns ]
|
tags: [ dns, minecraft, me5 ]
|
||||||
- name: Assure Minecraft SRV record
|
- name: Assure Minecraft SRV record
|
||||||
route53:
|
route53:
|
||||||
state: present
|
state: present
|
||||||
@ -58,7 +63,18 @@
|
|||||||
ttl: 3600
|
ttl: 3600
|
||||||
value: [ "1 10 25565 {{ inventory_hostname }}." ]
|
value: [ "1 10 25565 {{ inventory_hostname }}." ]
|
||||||
become: yes
|
become: yes
|
||||||
tags: [ dns ]
|
tags: [ dns, minecraft, me5 ]
|
||||||
|
- name: Assure Terraria record
|
||||||
|
route53:
|
||||||
|
state: present
|
||||||
|
overwrite: yes
|
||||||
|
zone: 9iron.club
|
||||||
|
type: CNAME
|
||||||
|
record: "calamity.9iron.club"
|
||||||
|
ttl: 3600
|
||||||
|
value: [ "{{ inventory_hostname }}." ]
|
||||||
|
become: yes
|
||||||
|
tags: [ dns, terraria, calamity ]
|
||||||
#- hosts: game1.9iron.club
|
#- hosts: game1.9iron.club
|
||||||
# roles:
|
# roles:
|
||||||
# - role: base-backups
|
# - role: base-backups
|
||||||
|
7
roles/tmodloader/defaults/main.yml
Normal file
7
roles/tmodloader/defaults/main.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
terraria_difficulty: 0
|
||||||
|
terraria_motd: "Please don't cut the purple trees!"
|
||||||
|
terraria_port: 7777
|
||||||
|
terraria_root: "/var/terraria"
|
||||||
|
terraria_worldname: "World"
|
||||||
|
terraria_worldsize: 3
|
||||||
|
terraria_tarball: "https://github.com/tModLoader/tModLoader/releases/download/v0.11.7.4/tModLoader.Linux.v0.11.7.4.tar.gz"
|
0
roles/tmodloader/meta/main.yml
Normal file
0
roles/tmodloader/meta/main.yml
Normal file
123
roles/tmodloader/tasks/main.yml
Normal file
123
roles/tmodloader/tasks/main.yml
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
#!/usr/bin/ansible-playbook
|
||||||
|
# vim:ft=ansible:
|
||||||
|
---
|
||||||
|
- name: Set up Terraria user
|
||||||
|
block:
|
||||||
|
- name: Install required packages
|
||||||
|
apt:
|
||||||
|
name:
|
||||||
|
- mono-complete
|
||||||
|
- name: Disable bundled services
|
||||||
|
systemd:
|
||||||
|
name: "{{ item }}"
|
||||||
|
enabled: no
|
||||||
|
state: stopped
|
||||||
|
loop:
|
||||||
|
- "mono-xsp4"
|
||||||
|
- name: Assure terraria admin group
|
||||||
|
group:
|
||||||
|
name: ter-admin
|
||||||
|
- name: Assure server user
|
||||||
|
user:
|
||||||
|
name: terraria
|
||||||
|
group: ter-admin
|
||||||
|
system: yes
|
||||||
|
home: "{{ terraria_root }}"
|
||||||
|
- name: Assure var directory
|
||||||
|
file:
|
||||||
|
path: "{{ terraria_root }}"
|
||||||
|
state: directory
|
||||||
|
owner: root
|
||||||
|
group: ter-admin
|
||||||
|
# Sticky, SetGID
|
||||||
|
mode: "3770"
|
||||||
|
- name: Assure systemd unit
|
||||||
|
template:
|
||||||
|
src: "tmodloader@.service"
|
||||||
|
dest: "/etc/systemd/system/tmodloader@.service"
|
||||||
|
- name: Reload available daemons
|
||||||
|
systemd:
|
||||||
|
daemon_reload: yes
|
||||||
|
become: yes
|
||||||
|
- name: Set up Terraria server
|
||||||
|
block:
|
||||||
|
- name: Create server directory
|
||||||
|
file:
|
||||||
|
path: "{{ terraria_root }}/{{ terraria_name }}"
|
||||||
|
state: directory
|
||||||
|
- name: Check for existing install
|
||||||
|
stat:
|
||||||
|
path: "{{ terraria_root }}/{{ terraria_name }}/tModLoaderServer"
|
||||||
|
register: stat_server_binary
|
||||||
|
- name: Unpack archive
|
||||||
|
block:
|
||||||
|
- name: Download tarball
|
||||||
|
get_url:
|
||||||
|
dest: "{{ terraria_root }}/{{ terraria_name }}/pack.tgz"
|
||||||
|
url: "{{ terraria_tarball }}"
|
||||||
|
- name: Unpack tarball
|
||||||
|
unarchive:
|
||||||
|
src: "{{ terraria_root }}/{{ terraria_name }}/pack.tgz"
|
||||||
|
remote_src: yes
|
||||||
|
dest: "{{ terraria_root }}/{{ terraria_name }}"
|
||||||
|
- name: Mark executable
|
||||||
|
file:
|
||||||
|
path: "{{ terraria_root }}/{{ terraria_name }}/tModLoaderServer.bin.x86_64"
|
||||||
|
mode: "0755"
|
||||||
|
- name: Clean up
|
||||||
|
file:
|
||||||
|
path: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
loop:
|
||||||
|
- "{{ terraria_root }}/{{ terraria_name }}/pack.tgz"
|
||||||
|
- name: Create worlds directory
|
||||||
|
file:
|
||||||
|
path: "{{ terraria_root }}/{{ terraria_name }}/worlds"
|
||||||
|
owner: terraria
|
||||||
|
group: ter-admin
|
||||||
|
state: directory
|
||||||
|
- name: Fix ownership
|
||||||
|
file:
|
||||||
|
path: "{{ terraria_root }}/{{ terraria_name }}"
|
||||||
|
recurse: yes
|
||||||
|
owner: terraria
|
||||||
|
group: ter-admin
|
||||||
|
when: not stat_server_binary.stat.exists
|
||||||
|
- name: Configure server
|
||||||
|
block:
|
||||||
|
- name: Template out server config
|
||||||
|
template:
|
||||||
|
src: config
|
||||||
|
dest: "{{ terraria_root }}/{{ terraria_name }}/config"
|
||||||
|
owner: terraria
|
||||||
|
group: ter-admin
|
||||||
|
become: yes
|
||||||
|
- name: Set up backups
|
||||||
|
block:
|
||||||
|
- name: Create backups directory
|
||||||
|
file:
|
||||||
|
state: directory
|
||||||
|
mode: "0700"
|
||||||
|
path: "{{ terraria_root }}/{{ terraria_name }}/backups"
|
||||||
|
owner: terraria
|
||||||
|
group: ter-admin
|
||||||
|
- name: Template out backup script
|
||||||
|
template:
|
||||||
|
src: "backup.sh"
|
||||||
|
dest: "{{ terraria_root }}/{{ terraria_name }}/backup.sh"
|
||||||
|
owner: terraria
|
||||||
|
group: ter-admin
|
||||||
|
mode: "0700"
|
||||||
|
- name: Set up backup cronjob
|
||||||
|
cron:
|
||||||
|
minute: "*/30"
|
||||||
|
name: "ansible-backup-terraria-{{ terraria_name }}"
|
||||||
|
job: "{{ terraria_root }}/{{ terraria_name }}/backup.sh >> {{ terraria_root }}/{{ terraria_name }}/backups.log 2>&1"
|
||||||
|
become: yes
|
||||||
|
- name: Enable service
|
||||||
|
systemd:
|
||||||
|
name: "tmodloader@{{ terraria_name }}"
|
||||||
|
daemon_reload: yes
|
||||||
|
enabled: yes
|
||||||
|
state: started
|
||||||
|
become: yes
|
50
roles/tmodloader/templates/backup.sh
Normal file
50
roles/tmodloader/templates/backup.sh
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
#
|
||||||
|
# terraria.sh
|
||||||
|
# Backup script for Gitea. Meant to be sourced by our main backup script
|
||||||
|
# Copyright (C) 2020 Vintage Salt <rehashedsalt@cock.li>
|
||||||
|
#
|
||||||
|
# Distributed under terms of the MIT license.
|
||||||
|
#
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
export TERRARIADIR="{{ terraria_root }}/{{ terraria_name }}"
|
||||||
|
export OUTDIR="$TERRARIADIR/backups"
|
||||||
|
retention=144 # 30-minute intervals, 3 days
|
||||||
|
|
||||||
|
# Helper functions
|
||||||
|
log() {
|
||||||
|
[ -z "$1" ] && return 1
|
||||||
|
printf "$(date -Iseconds): $1\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Sanity checks
|
||||||
|
if ! [ -d "$OUTDIR" ]; then
|
||||||
|
if ! mkdir "$OUTDIR"; then
|
||||||
|
log "Unable to find or create output directory: $OUTDIR"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
# Enforce permissions on our output directory since the terraria user will need them
|
||||||
|
chown terraria.ter-admin "$OUTDIR"
|
||||||
|
chmod 770 "$OUTDIR"
|
||||||
|
|
||||||
|
# Purge oldest backup if we need to
|
||||||
|
currentbackupcount="$(ls -1 "$OUTDIR" | wc -l)"
|
||||||
|
if (( currentbackupcount >= retention )); then
|
||||||
|
lastbackup="$(find "$OUTDIR" -name \*.wld 2>/dev/null | sort | head -n 1)"
|
||||||
|
if [ -f "$lastbackup" ]; then
|
||||||
|
log "Removing old backup: $lastbackup"
|
||||||
|
rm "$lastbackup"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
# WE MAKE BACKUP NOW SERGEI
|
||||||
|
if cd "$OUTDIR"; then
|
||||||
|
log "Initiating terraria dump"
|
||||||
|
su terraria -c "cp \"$TERRARIADIR/worlds/world.wld\" \"$OUTDIR/world-$(date -Iseconds).wld\""
|
||||||
|
else
|
||||||
|
log "Could not change directory: $OUTDIR"
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
|
|
13
roles/tmodloader/templates/config
Normal file
13
roles/tmodloader/templates/config
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# This configuration file is deployed via Ansible
|
||||||
|
# Changes made here will be overwritten!
|
||||||
|
maxplayers=8
|
||||||
|
world={{ terraria_root }}/{{ terraria_name }}/worlds/world.wld
|
||||||
|
port={{ terraria_port }}
|
||||||
|
password={{ terraria_password }}
|
||||||
|
motd={{ terraria_worldname }} {{ terraria_motd }}
|
||||||
|
worldpath={{ terraria_root }}/{{ terraria_name }}/worlds
|
||||||
|
autocreate={{ terraria_worldsize }}
|
||||||
|
difficulty={{ terraria_difficulty }}
|
||||||
|
worldname=world
|
||||||
|
banlist=banlist.txt
|
||||||
|
secure=0
|
33
roles/tmodloader/templates/tmodloader@.service
Normal file
33
roles/tmodloader/templates/tmodloader@.service
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#
|
||||||
|
# Licensed under the terms of the MIT license
|
||||||
|
# vim:ft=dosini:
|
||||||
|
#
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=tModLoader Server %i
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=terraria
|
||||||
|
Group=ter-admin
|
||||||
|
WorkingDirectory={{ terraria_root }}/%i
|
||||||
|
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 ./tModLoaderServer.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 "exit"\\015'
|
||||||
|
ExecStop=/bin/sleep 5
|
||||||
|
|
||||||
|
Restart=always
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
Reference in New Issue
Block a user