Terraria server crashes when I run it as a service

Solution 1:

The problem is that

Terraria server seems to need a thread which manage input and output stream of command and server log as you saw when you start server. But when I start it in docker, it remove the input output and cause NullReferenceException (System.Object threadContext).

The solution suggested there is to use screen--which works! However, you lose all the logging to the systemd journal. So instead, you can use unbuffer, which makes a TTY but also redirects the output to stdout. Use it like this:

ExecStart=/usr/bin/unbuffer /opt/terraria/1412/TerrariaServer.bin.x86_64 -config /var/lib/terraria/config