Add teamspeak-fallback service

This commit is contained in:
Tobias Reisinger 2023-12-16 05:06:10 +01:00
parent c95be92f46
commit 03f83ef7fd
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
6 changed files with 94 additions and 0 deletions

View file

@ -44,6 +44,8 @@
tags: [synapse, matrix, communication]
- role: tandoor
tags: [tandoor, recipes]
- role: teamspeak_fallback
tags: [teamspeak-fallback, communication]
- role: telegraf
tags: [telegraf, monitoring]
- role: tinytinyrss

View file

@ -0,0 +1,19 @@
services:
teamspeak:
image: teamspeak
restart: always
ports:
- 9987:9987/udp
- 10011:10011
- 30033:30033
environment:
TS3SERVER_DB_PLUGIN: ts3db_sqlite3
TS3SERVER_DB_SQLCREATEPATH: create_sqlite
TS3SERVER_LICENSE: accept
volumes:
- data:/var/ts3server/
volumes:
data:
external: true
name: teamspeak-fallback-data

View file

@ -0,0 +1,36 @@
---
- name: Set common facts
ansible.builtin.import_tasks: tasks/set-default-facts.yml
- name: Deploy {{ svc.name }}
vars:
svc: "{{ teamspeak_fallback_svc }}"
block:
- name: Import tasks to create service directory
ansible.builtin.import_tasks: tasks/steps/create-service-directory.yml
- name: Copy the docker-compose file
ansible.builtin.copy:
src: docker-compose.yml
dest: "{{ (service_path, 'docker-compose.yml') | path_join }}"
mode: "0644"
- name: Template the conditional-start script
ansible.builtin.template:
src: conditional-start.sh.j2
dest: "{{ (service_path, 'conditional-start.sh') | path_join }}"
mode: "0755"
- name: Copy the system service
ansible.builtin.template:
src: teamspeak-fallback.service.j2
dest: /etc/systemd/system/teamspeak-fallback.service
mode: "0644"
become: true
- name: Enable the system service
ansible.builtin.systemd_service:
name: teamspeak-fallback.service
state: started
enabled: true
daemon_reload: true
become: true

View file

@ -0,0 +1,18 @@
#!/usr/bin/env sh
while true
do
if nc -z "{{ teamspeak_fallback_check_server }}" "{{ teamspeak_fallback_check_port }}"
then
if docker compose ps --services | grep teamspeak >/dev/null; then
echo "Stopping Server"
docker compose down
fi
else
if ! docker compose ps --services | grep teamspeak >/dev/null; then
echo "Starting Server"
docker compose up -d --pull=always
fi
fi
sleep 5
done

View file

@ -0,0 +1,13 @@
[Service]
[Unit]
Description=Teamspeak Fallback Starter
After=network.target
[Service]
Type=simple
ExecStart={{ service_path }}/conditional-start.sh
WorkingDirectory={{ service_path }}
Restart=on-failure
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,6 @@
---
teamspeak_fallback_check_server: ts.sneiso.eu
teamspeak_fallback_check_port: 30033
teamspeak_fallback_svc:
name: teamspeak-fallback