Installing TShock Terraria Server on Debian Wheezy

Posted on .

The following is how I installed TShock Terraria Server on a clean Debian Wheezy machine. The same method has been tested working on Ubuntu 12.04 LTS (Precise).

One important difference to other howtos is it does not install mono-complete and the plethora of dependencies that requires (including x11-common). This only installs the required libraries to run, nothing more.

Run these commands individually, this is not to be copy pasted into your shell in full.

Update: A few users are complaining of missing packages, however I have re-run the instructions in a fresh Wheezy guest and found no issues (see transcript of installation here).

Update2: I have successfully tested the following instructions using Ubuntu 12.04 LTS Precise (transcript here)

Update3: Tested working with TShock 4.2

Make sure you are using Debian 7 Wheezy or Ubuntu 12.04 LTS Precise.

Debian init-script

The following init-script can:

  • Connect to the screen console with ./terraria-server connect
  • Exits the server cleanly by issuing the “exit” or “exit-nosave” command to the server console
  • Fits perfectly if installation was made by the above howto

Download
  terraria-init.sh (2.6 KiB, 4,974 hits)

32 thoughts on “Installing TShock Terraria Server on Debian Wheezy

  1. Jeff

    This didn’t work for me. apt-get didnt find some of the packages mentioned in the first step.

    libmono-system-runtime-serialization4.0-cil
    mono-runtime

    Reply
  2. Jordan

    This also had issues for me. A lot of packages weren’t found. However mono was. But when I run the server for the first time I get an error:

    mono TerrariaServer.exe -ip 0.0.0.0 -port 7777 -maxplayer 32
    WARNING: The runtime version supported by this application is unavailable.
    Using default runtime: v1.1.4322

    ** (TerrariaServer.exe:29277): WARNING **: The class System.Func`2 could not be loaded, used in mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

    Unhandled Exception: System.TypeLoadException: Could not load type ‘Terraria.ProgramServer’ from assembly ‘TerrariaServer, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’.

    Reply
  3. Zenda

    Hello, my problem is that when I rebooted linux and I want to turn on, turn off or restart the TShock server it writes: Starting TShock Terraria Server terraria_server [fail]. Do you know what can be?
    Thanks for the reply
    (Sorry for Google translate ;))

    Reply
  4. brad

    Seems to work ok on ubuntu 12.0.4 LTS but line 27 of the transcript says to “# (note down auth code for admin access, and exit-nosave)”.

    I did not see Auth code

    Reply
  5. Toni

    On Ubuntu Server 13.10 use insserv commant say’s “not Found”.
    Can be fixed with
    “sudo ln -s /usr/lib/insserv/insserv /sbin/insserv”

    PS: Tested OK with Tshock v4.21103

    Reply
  6. Cr4zY

    The init-script doesn’t seem to work. If I start terraria manually with mono, the server works fine and I can connect. If I use your script though, I can’t get into the game. “invoke-rc.d terraria-server connect” just shows:
    Terraria Server v1.2.1.2

    Saving world. Momentary lag might result from this.
    Saving world data: 1%

    The status is stuck at 1%. Am I doing something wrong?

    Reply
    1. stalks Post author

      How are you running it manually?
      Try running the following:

      su terraria -c "cd ~terraria/bin/; screen -mS terraria_server $(which mono) /home/terraria/bin/TerrariaServer.exe -port 7777 -world /home/terraria/bin/Terraria/Worlds/test.wld;"

      This will run the almost identical command as the init-script but will keep you inside the screen.

      If you get an error such as “Unable to read from /dev/pts/0”, then give that file o+rw permissions, ie. chmod o+rw /dev/pts/0

      PS. I came accross a possibly unrelated bug where it would create ServerLog.txt in the wrong directory, so adjusted the init-script to change directory prior to launch. I also added more variables to make it a little easier to setup. Re-download the init-script to find the changes, do a diff to see what I changed.

      Reply
  7. Johan

    Just set up a TShock server on Ubuntu 12.04 and started thinking of writing some startup-scripts. The init.d script I found here saved a lot of works. Big thanks to the author!

    @Cr4zY: Same thing happened to me when I started the server with the startup-script pointing to a non-existant world. Check the “WORLDFILE” variable in the script and make sure it points to an existing world.

    Reply
  8. Johan

    On Ubuntu 12.04 I had some problems with the server not shutting down properly. Tracked it down to screen not recognizing the newline character when sending the EXIT_COMMAND to the detached screen in terraria-init.sh line 79.

    Changing line 79 from:
    su “${USERID}” -c ‘screen -dr ‘${NAME}’ -X stuff “‘${EXIT_COMMAND}’15″‘
    to
    su “${USERID}” -c ‘screen -dr ‘${NAME}’ -X stuff “‘${EXIT_COMMAND}’$(printf \\r)”

    solved this problem for me.

    BR, Johan

    Reply
    1. stalks Post author

      I tested your change on my Debian machine and it works so I have updated the init script here to use that.

      Thanks πŸ™‚

      Reply
  9. Alex

    Well, I am using Ubuntu 12.04 and updated your script recently.
    I receive the error when I attempt to shut down the server:
    Warning: unknown mime-type for “\r” — using “application/octet-stream”
    Error: no such file “\r”

    It is associated to line 79, with the previous fix that Johan made.

    If you could let me know what I can do to solve it, please reply. I’ll keep this on refresh tab. πŸ™‚

    Thanks in advance

    Reply
    1. stalks Post author

      Doh! It was meant to be “printf” not “print”.

      I have adjusted it, sorry.

      I was testing the changes to my own server and then editing the online file separately and made a typo πŸ™

      Reply
  10. Shibi

    Hello,

    really nice Guide! Got it working really fast,

    Im Using an Raspberry Pi (700mhz, 500mb ram, ARM) with “A Debian wheezy port, optimised for the Raspberry Pi” from http://www.raspberrypi.org/downloads

    at first everything runs smoothly but after random intervals the Server just goes offline without any information inside the log. (no errors)

    Im Using Putty to observe the “screen”.
    Just at the momment when the Server Crashes Putty shows:
    “[screen is terminating]
    root@raspberrypi:~#”

    if i use invoke-rc.d terraria-server connect it says “screen not running)
    if i use invoke-rc.d terraria-server start
    it shows: [FAIL] Starting TShock Terraria Server: terraria_server failed!
    invoke-rc.d: initscript terraria-server, action “start” failed.-
    if i use “invoke-rc.d terraria-server connect” now it connects and it is allready Loading world data.
    I can play again but after some time random crashes ocur.

    I have not worked much with linux yet. But i can imagine that the ram is overflowing? or do you have any other idea what is causing the crash.

    Greetings Shibi

    Reply
    1. stalks Post author

      When linux runs out of RAM it runs the OOM-KILLER, which will begin to destroy processes in order to free up RAM. The easiest way to find out if Terraria will killed due to OOM-KILLER, is to run the command “dmesg”. The kernel writes messages to a wall regularly, errors, driver info etc, all go on this wall, and running dmesg allows you to see the messages since boot.

      Reply
      1. stalks Post author

        Also, Terraria is written in .NET and so uses the equivalient mono library on Linux. Unfortunately mono is well known for requiring a disproportionate amount of RAM compared to .NET. πŸ™ Since writing this guide I have retired the Linux VM used to run Terraria and instead run a Windows VM just for this purpose. Memory requirements for Terraria went from 1.5GB to 750MB and I have an always-on Remote Desktop as well πŸ™‚

        Reply
  11. Lukas Jansen

    Hello,
    Thank you so much for the post.
    Could I maybe use your init script in my Blog? I would give full credit and add also a Link to your Blog. Love the way it is handling the screen session and you can use it for every gameserver.

    Reply
  12. Kashim119

    Hi There i have a problem my server runs there is no problem with that but if someone connectΒ΄s they cant load the map file completely ! it stucks on 26% what can i do ?

    Reply
  13. Anonymous

    What does this mean??

    Settling liquids: 99%
    Starting server…
    System.Net.Sockets.SocketException: Address already in use
    at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00000] in :0
    at System.Net.Sockets.TcpListener.Start (Int32 backlog) [0x00000] in :0
    at System.Net.Sockets.TcpListener.Start () [0x00000] in :0
    at Terraria.Netplay.ServerLoop (System.Object threadContext) [0x00000] in :0

    Reply
  14. Anthony

    Been ages since I used linux, I’m getting this:

    /etc/init.d/terraria-server: line 46: [: too many arguments

    guessing a space or new line is getting in there somehow, but I’m using the default with no changes. I modified everything to adhere to the default script.

    Reply
      1. Anthony

        if [[ -e /var/run/screen/S-${USERID}/*.${NAME} ]]; then return 0; fi

        Double [[ works.

        When I try to connect to the service I get (screen not running).

        Reply
      2. Anthony

        if [[ -e /var/run/screen/S-${USERID}/*.${NAME} ]]; then return 0; fi

        Double [[ doesn’t fail, but when I try to connect to the service I get:

        (screen not running)

        So it’s probably causing another issue.

        Reply
  15. Lin

    this fails when i try to run the server because it is “already running” but when i try to stop it it fails also.

    root@raspberrypi:~# invoke-rc.d terraria-server start
    [FAIL] Starting TShock Terraria Server: terraria_server (already running) failed!

    root@raspberrypi:~# invoke-rc.d terraria-server stop
    [FAIL] Stopping TShock Terraria Server: terraria_server failed!
    invoke-rc.d: initscript terraria-server, action “stop” failed.

    also how can i edit the init file from ssh?

    Reply

Leave a Reply

You may leave the Name and Email fields blank to post anonymously.