TransWikia.com

Terraria server crashes when I run it as a service

Arqade Asked by user60561 on July 25, 2021

I’m running Terraria as a systemd service, with a service file like the following:

[Unit]
Description=server daemon for terraria

[Service]
User=terraria
Type=exec
RestartSec=10s
ExecStart=/opt/terraria/1412/TerrariaServer.bin.x86_64 -config /var/lib/terraria/config
ExecStop=/opt/terraria/bin/terrariad exit
ExecStop=/usr/bin/sh -c 'while kill -0 $MAINPID 2>/dev/null; do sleep 1; done'
TimeoutStopSec=10

[Install]
WantedBy=multi-user.target

Unfortunately, 5 minutes after starting the server, it crashes with this error:

Apr 15 18:13:40: [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
Apr 15 18:13:40: ================
Apr 15 18:13:40:   at System.Threading.ThreadHelper.ThreadStart () [0x00008] in <d1664be62cd44600bbd25f7afa292479>:0
Apr 15 18:13:40:   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallba>
Apr 15 18:13:40:   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallba>
Apr 15 18:13:40:   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.Conte>
Apr 15 18:13:40:   at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00014] in <d1664be62cd44600bbd25f7afa292479>:0
Apr 15 18:13:40:   at Terraria.Main.startDedInputCallBack () [0x00017] in <c62dec19bbe944969ce327cab98fe21b>:0
Apr 15 18:13:40: Exception: System.NullReferenceException: Object reference not set to an instance of an object
Apr 15 18:13:40: Culture: en-US
Apr 15 18:13:40: Thread: 6 [Server Input Thread]
Apr 15 18:13:40: 4/15/2021 6:13:40 PM: Unhandled Exception
Apr 15 18:13:40: : ================
Apr 15 18:13:40: Backing up world file
Apr 15 18:13:40: Validating world save: 87%
<snip>
Apr 15 18:08:45: : Server started
Apr 15 18:08:45: Type 'help' for a list of commands.

How do I avoid this crash?

One Answer

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

Answered by user60561 on July 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP