[GUIDE] Terraria server on PR2100/PR4100

A friend asked if I could host a Terraria server for him.
Here’s how to do it based on the official instructions
Warning: modifications to your NAS are at your own risk. WD does not support these procedures.

SSH into your NAS.
Setup a working directory.
I’d recommend to create a Terraria share via the WD web UI so it’s easier to add worlds.

cd /shares/Terraria

Get the server binary.
Browse to the official website, scroll down and copy the link of ‘dedicated server’ at the bottom.
Download the server binary like this

curl -L -o terraria.zip https://terraria.org/system/dedicated_servers/archives/000/000/032/original/terraria-server-1353.zip?1515098333

or simply download it via your browser and copy it to your Terraria share.

Unpack.

unzip terraria.zip
ls -l

Select the linux server, keep an example config and clean up the rest.

v=1353
mv $v/Linux server
cat $v/Windows/serverconfig.txt > example_config.txt
sed -i "s@#worldpath=.*@worldpath=/shares/Terraria/Worlds/@" example_config.txt
sed -i "s@#world=.*@world=/shares/Terraria/Worlds/Terraria.wld@" example_config.txt
rm -rf $v

Make the binaries executable

chmod +x server/TerrariaServer*

Prepare a persistent Worlds directory.
It defaults to /home/root/.local/share/Terraria which gets wiped on NAS reboot (unless you have my Entware package installed).

mkdir Worlds

Prepare a config file. More options available here.

cat << EOF > config.txt
maxplayers=8
port=7777
world=/shares/Terraria/Worlds/Terraria.wld
# the name should match the full path above
worldname=Terraria
worldpath=/shares/Terraria/Worlds/
autocreate=1
motd=Digging the My Cloud!
password=thisisnotastrongpassword
secure=1
upnp=1
EOF

Now start the server with the x64 option and the full path to the config file

/shares/Terraria/server/TerrariaServer -x64 -config /shares/Terraria/config.txt

You should be able to connect to it.

You probably don’t want to keep your SSH session open all the time.
Save the world and exit the server with.

exit

Get screen (e.g. via the Entware package).

/opt/bin/opkg install screen
/opt/bin/screen
/shares/Terraria/server/TerrariaServer -x64 -config /shares/Terraria/config.txt

Press CTRL-A and D to detach from the screen session.
Press CTRL-A and R to attach to the session again.

To start the server on boot, add this somewhere to init.sh

screen -S terr -d -m ./server/TerrariaServer -x64 -config /shares/Terraria/config.txt

And to ensure a clean shutdown, add this funky command to clean.sh

screen -S terr -p 0 -X stuff $'exit\n'

You may need to forward port 7777 in your router to connect from outside your home network if upnp doesn’t work.

Enjoy!

The next level of awesomeness is Terraria + TShock. This can be done with docker and https://github.com/ryansheehan/terraria