Add a hopefully functional implementation
Time to test
This commit is contained in:
parent
c3ca975e85
commit
0715707452
@ -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,13 @@ 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
|
||||
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
9
handlers/main.yml
Normal 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
|
@ -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
|
||||
|
16
templates/install-server.sh
Normal file
16
templates/install-server.sh
Normal 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 {} +
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user