Merge branch '20-start-up-a-quick-teamspeak-server' into 'master'

Resolve "Start up a quick teamspeak server on docker"

Closes #20

See merge request icaotix/linux-tools!19
This commit is contained in:
Marcel Schwarz 2020-03-21 21:53:31 +00:00
commit 9daccaee06
5 changed files with 52 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
__pycache__ __pycache__
.vscode .vscode
devenv devenv
your_system_information.txt

View File

@ -5,13 +5,15 @@ from modules.install.ToolsInstaller import ToolsInstaller
from modules.swap.SwapModule import SwapModule from modules.swap.SwapModule import SwapModule
from modules.systemupdate.Systemupdate import Systemupdate from modules.systemupdate.Systemupdate import Systemupdate
from modules.vim.VimModule import VimModule from modules.vim.VimModule import VimModule
from modules.teamspeak.Teamspeak import Teamspeak
modules = { modules = {
"helloworld": HelloWorld().run, "helloworld": HelloWorld().run,
"install": ToolsInstaller, "install": ToolsInstaller,
"swap": SwapModule().run, "swap": SwapModule().run,
"update": Systemupdate().run, "update": Systemupdate().run,
"vim": VimModule().run "vim": VimModule().run,
"teamspeak": Teamspeak
} }
fire.Fire(modules) fire.Fire(modules)

3
modules/teamspeak/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
ts3_data
*.tar
*.gz

View File

@ -0,0 +1,32 @@
import subprocess
from os import path
import time
import re
class Teamspeak:
"""Manage a Docker backed Teamspeak server"""
def start(self):
"""Starts a Teamspeak Server with docker-compose"""
show_creds = False if path.exists(path.join(path.dirname(__file__), "ts3_data")) else True
subprocess.run("docker-compose up -d", shell=True, cwd=path.dirname(__file__))
if show_creds:
logs = subprocess.check_output("docker-compose logs", shell=True, cwd=path.dirname(__file__)).decode("UTF-8")
while re.search(r"token", logs) is None:
time.sleep(2)
logs = subprocess.check_output("docker-compose logs", shell=True, cwd=path.dirname(__file__)).decode("UTF-8")
print("Server Query Admin Account: " + re.search(r"loginname=.*", logs).group(0))
print("Server Admin Token: " + re.search(r"token=(.*)", logs).group(1))
def stop(self):
"""Stops the Teamspeak Server with docker-compose"""
subprocess.run("docker-compose down -v", shell=True, cwd=path.dirname(__file__))
def pack_data(self, name="ts3_data.tar.gz"):
"""Pack all user data of the server started with this script as tar file"""
subprocess.run(f"tar -zcvf {name} ts3_data", shell=True, cwd=path.dirname(__file__))
def show_logs(self):
"""show the logs of the running Teamspeak server"""
subprocess.run("docker-compose logs", shell=True, cwd=path.dirname(__file__))

View File

@ -0,0 +1,13 @@
version: '3.7'
services:
teamspeak:
image: teamspeak
restart: always
ports:
- 9987:9987/udp
- 10011:10011
- 30033:30033
volumes:
- ./ts3_data:/var/ts3server
environment:
TS3SERVER_LICENSE: accept