Linux Server crash with System.NullReferenceException

MoMelyz

Terrarian
Hello, I'm trying to run a terraria server on a docker with CentOS7 images.

I've set everything up and run it on my server and it can run just fine. But when I tried to run the same configuration in docker, server crash when it finish loading world map with this message.

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
at Terraria.Main.startDedInputCallBack (System.Object threadContext) [0x00000] in <filename unknown>:0

Anyone has any idea what causes this?
 
OK, I've found my solution. And in case anyone that have the same problem as me and found this Post, here is how i do.

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). So I need a background screen which can still attach to it and have a command line.

I've try tmux in docker but it failed too. But after googling for sometime. I found this post which use systemd service.

So here it is.

1. install screen using apt-get install or yum install

2. create a service file /etc/systemd/system/terraria.service
Code:
[Unit]

Description=server daemon for terraria

[Service]
Type=forking
User=terraria
KillMode=none
ExecStart=/usr/bin/screen -dmS terraria /bin/bash -c "/opt/terraria/TerrariaServer.bin.x86_64 -config /srv/terraria/config.txt"
ExecStop=/usr/local/bin/terrariad exit

[Install]
WantedBy=multi-user.target
Dont' forget to change the path to server file and config to match yours.

3. run command "systemctl start terraria" to start service and "systemctl enable terraria" to enable it to run each time server started.


For more detail. Please follow the original post that I found https://www.linode.com/docs/applications/game-servers/host-a-terraria-server-on-your-linode.
 
Thanks for sharing your solution MoMelyz, I ran into the same issue running Terraria in a Docker container, and your post helped me come up with a fix. I think your solution is a bit overkill though, to provide stdout/TTY to the container all you need to do is add the -it flags to your docker run command. No need to mess with screen and systemctl!
 
Back
Top Bottom