TeamSpeak 3 Server with MySQL Database - audio/teamspeak3-server

This article will detail the installation and configuration of TeamSpeak 3 Server from ports - audio/teamspeak3-server

TeamSpeak 3 Server will connect to a MySQL Server for its database and works with MySQL 5.5 or higher.

 

Install Teamspeak 3 Server

cd /usr/ports/audio/teamspeak3-server

make config

The configuration dialog has an option to enable MySQL database support.
It is not required to enable this as It will only add MySQL server as a required installation and runtime dependency of teamspeak3-server on the local system. The database plugins the teamspeak3-server needs to connect to a MySQL database server are always installed in /usr/local/lib/teamspeak/server/ irrespective of this setting. Enable the option only if you intend to install MySQL server, or if it is already installed on the local system. If enabled, ensure your desired MySQL server version is specified in /etc/make.conf prior to installing teamspeak3-server.

DEFAULT_VERSIONS+= php=7.4 python=3.9 python3=3.9 perl5=5.32 ssl=openssl mysql=8.0

make install clean

<Accept> terms of license.

To prevent build failures in Poudriere and Synth also add the following to /etc/make.conf as well as the port management's respective make.conf:

DISABLE_LICENSES= yes

There is no pre-built package for teamspeak3-server due to the requirement to accept the license.

 

Configure Teamspeak 3 Server

Create a new server ini file /usr/local/etc/teamspeak/ts3server.ini with the following configuration:

dbplugin=ts3db_mariadb
dbpluginparameter=mysql.ini
logappend=1
dbsqlcreatepath=create_mariadb/

NOTE: As per Teamspeak documentation, the ts3db_mariadb plugin is used to connect to MySQL as well as MariaDB database servers. Also note that the actual plugin filename(s) begin with lib but this is deliberately omitted when specifying dbplugin=

dbsqlcreatepath=create_mariadb/ is only needed when starting the server instance for the first time and can be removed from configuration anytime thereafter.

Many other command line configuration options exist, such as changing the voice, query, or file transfer ports. Refer to /usr/local/share/doc/teamspeak3-server/server_quickstart.txt for the complete list including default values for each. Only command line options that need to be altered from the defaults need be specified in ts3server.ini.

 

Create a new database for the TeamSpeak 3 server on your MySQL server.
Create a new MySQL user account with a mysql_native_password and grant it full rights to the Teamspeak 3 server database.

 

Create the configuration file for the MySQL server connection /var/db/teamspeak/mysql.ini  the filename is specified with dbpluginparameter= in ts3server.ini. Specify the MySQL username, password, and database name that was used when creating the TeamSpeak database. Use single quotes around the password to ensure that special characters are used correctly.

[config]
host=localhost
port=3306
username=teamspeak
password='password'
database=ts3server

If the Teamspeak server daemon will be running on the same system as the MySQL server then you can optionally take advantage of MySQL sockets by replacing port=3306 with socket=/tmp/mysql.sock

NOTE: When using sockets host= must be localhost for sockets to work.

 

To enable the teamspeak server add the following to /etc/rc.conf

teamspeak_enable="YES"

Other optional rc.conf configuration variables are available with their default values shown:

teamspeak_pidfile="/var/db/teamspeak/teamspeak_server.pid"
teamspeak_db_dir="/var/db/teamspeak"
teamspeak_log_dir="/var/log/teamspeak"

Start the Teamspeak Server service:

service teamspeak start

 

Gain Administrative Control

A synopsis of server_quickstart.txt - Section 8. Gaining Administrator Access

View the contents of the /var/log/teamspeak/ts3server_1.log file to obtain the ServerAdmin token used to gain administrative control of the Teamspeak server:

ServerAdmin token created, please use the line below
token=ppEa0Wp6hopKBzKhH5RiUtb5Ggve5aI8J7ifu+/P

To gain global administration permissions for ServerQuery access, the first time the server instance
is started a ServerQuery password is printed to the console output:

Server Query Admin Acccount created
loginname= “serveradmin”, password= “BAIPwM8X”

If for any reason this was not displayed then the password can be set by temporarily adding the following command line parameter to ts3server.ini:

serveradmin_password='password'

 

Stopping and Restarting Teamspeak 3 Server

The examples in this section are entirely optional. The usual service teamspeak start|stop|restart commands work as intended.

When executing service teamspeak start the rc.d script /usr/local/etc/rc.d/teamspeak executes FreeBSD's builtin daemon(8) utility to start and daemonize the ts3server process. The modified teamspeak rc.d startup script (below) adds -r to the daemon startup command line. The -r option instructs the daemon process to supervise and automatically restart its child process after a one second delay if it is terminated. However now if we deliberately stop the TeamSpeak server with service teamspeak stop, the daemon process will dutifully launch ts3server again. The modified rc.d script adds a custom stop method that sends SIGTERM to the parent daemon process. When the daemon process receives a shutdown signal it forwards the SIGTERM to the child ts3server process to shut it down, removes both pid files, then terminates itself.

NOTE: The following rc.d script modifications are not required and intended only to accommodate the daemon(8) command-line option -r to supervise and restart the ts3server process as just described.

Edit /usr/local/etc/rc.d/teamspeak inserting items highlighted in bold

#!/bin/sh

# $FreeBSD: head/audio/teamspeak3-server/files/teamspeak.in 508976 2019-08-14 22:00:20Z ultima $
#
# PROVIDE: teamspeak
# REQUIRE: LOGIN 
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# teamspeak_enable (bool):   Set to NO by default.
#               Set it to YES to enable teamspeak server.
#

. /etc/rc.subr

name="teamspeak"
rcvar=teamspeak_enable

load_rc_config $name

: ${teamspeak_enable:="NO"}
: ${teamspeak_pidfile:="/var/db/teamspeak/teamspeak_server.pid"}
: ${teamspeak_db_dir:="/var/db/teamspeak"}
: ${teamspeak_log_dir:="/var/log/teamspeak"}
: ${teamspeak_daemon_pidfile:="/var/db/teamspeak/teamspeak_daemon.pid"}

stop_cmd="${name}_stop"
teamspeak_stop() {
	printf "Stopping ${name}.\n"
	kill `cat $teamspeak_daemon_pidfile`
	sleep 2
}

# Add flags var so it isn't called in daemon
flags=" "
procname=/usr/local/libexec/ts3server
command=/usr/sbin/daemon
command_args="-fp "$teamspeak_pidfile" -r -P $teamspeak_daemon_pidfile -u teamspeak /usr/local/libexec/ts3server dbsqlpath=/usr/local/share/teamspeak/server/sql/ inifile=/usr/local/etc/teamspeak/ts3server.ini licensepath=/usr/local/etc/teamspeak/ logpath="$teamspeak_log_dir" license_accepted=1"
teamspeak_chdir="$teamspeak_db_dir"
required_dirs="$teamspeak_db_dir $teamspeak_log_dir"

LD_LIBRARY_PATH=/usr/local/lib/teamspeak/server:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
export LANG=en_US.UTF-8

run_rc_command "$1"

NOTE: /usr/local/etc/rc.d/teamspeak is replaced every time the Teamspeak server port is updated. Therefore a saved backup of the modified file will need to be copied back after every update.

 

Logging and Log Rotation

By default the server creates new log files with each service (re)start. The created log file names include the exact date and time the service was started. The logappend=1 option specified in ts3server.ini suppresses this file name construct behavior and instead creates two log files named simply ts3server_0.log and ts3server_1.log and appends to these two log files perpetually. This makes it more suitable for newsyslog to rotate and save archive copies of the logs.

The following example configuration added to /etc/newsyslog.conf will rotate the logs on the first day of every month at midnight keeping 4 archive files.

/var/log/teamspeak/*.log teamspeak:wheel 600 4 * $M1D0 ZG /var/db/teamspeak/teamspeak_server.pid

The G flag allows us to specify a wildcard *.log to rotate and create archives for both of TeamSpeak server's log files.

NOTE: It is necessary to restart the ts3server process to continue logging properly after a log rotation. The process identified by teamspeak_server.pid will be sent a SIGHUP when newsyslog rotates the log files. The ts3server process will simply shutdown in response to a HUP signal which is not optimal. However if daemon(8) command line parameter -r is used as detailed in the previous section, then ts3server will be automatically restarted and logging will continue normally.

 

Adding a SRV Record to DNS

Adding a _ts3._udp. SRV resource record to the authoritative DNS zone of the TeamSpeak server, allows administrators to control the destination target IP address and port of clients connecting to a given FQDN. Clients configure their bookmarks with the FQDN only and no port. Administrative changes to destination IP address or port can be made without the need for clients to update their bookmarks.

The format is  _ts3._udp.name TTL IN SRV priority weight port target

_ts3._udp.example.org.    IN    SRV    0 5 9987 example.org.

NOTE: The target in the SRV record must point to a hostname that has an A and/or AAAA resource record. Pointing to a hostname that has a CNAME resource record is not a valid configuration.

 

Pertinent File/Folder Locations

Server configuration - /usr/local/etc/teamspeak/ts3server.ini

Database configuration - /var/db/teamspeak/mysql.ini

Logs - /var/log/teamspeak/

TeamSpeak icons, client avatars, and file transfer folders/files - /var/db/teamspeak/files/

Documentation /usr/local/share/doc/teamspeak3-server/ 

 

Server working directory - /var/db/teamspeak/

Database plugins (dbplugin=ts3db_mariadb) - /usr/local/lib/teamspeak/server/

SQL script files directory (dbsqlpath=) - /usr/local/share/teamspeak/server/sql/

TeamSpeak startup script - /usr/local/etc/rc.d/teamspeak