lennartalff.net/content/posts/terraria-server.md

1.8 KiB

title date categories tags
Terraria Server 2022-04-10
Software
software
server

Get Your Stuff Together

Download the dedicated server from the Terraria Wiki. All information to start the server are provided there as well. The relevant steps here are to create a serverconfig.txt and we should not forget to forward the port used by Terraria. By default this is 7777.

Configure the systemd Daemon

These steps are heavily inspired by the linode guide.

Create the file /usr/local/bin/terrariad


#!/usr/bin/env bash

SERVER_CMD_ARG="`printf \"$*\r\"`"
ATTACH_CMD_ARG="-r terraria"
SEND_CMD_ARG="-S terraria -X stuff $SERVER_CMD_ARG"

if [ "$1" = "attach" ]
then
    CMD_ARG="$ATTACH_CMD_ARG"
else
    CMD_ARG="$SEND_CMD_ARG"
fi

screen $CMD_ARG

We can attach to a running Terraria server via terrariad attach to interact with the server's command line. Or we can directly send server commands like exit to save the currently running Terraria world and stop the server via terrariad exit.

Create the service file /etc/systemd/system/terraria.service and replace the paths and the username so they fit our setup.


[Unit]
Description=server daemon for terraria

[Service]
Type=forking
User=root
KillMode=none
ExecStart=/usr/bin/screen -dmS terraria /bin/bash -c "/PATH/TO/THE/TerrariaServer.bin.x86_64 -config /PATH/TO/THE/SERVER/CONFIG/FILE/serverconfig.txt"
ExecStop=/usr/local/bin/terrariad exit
User=THE_USER_RUNNING_THE_SERVER
Group=THE_USER_RUNNING_THE_SERVER

[Install]
WantedBy=multi-user.target

That is almost it! Enable and start the service


sudo systemctl enable --now terraria.service