Skip to content

Instantly share code, notes, and snippets.

@mirsella
Last active July 17, 2025 10:20
Show Gist options
  • Select an option

  • Save mirsella/741848f8ee7c1389ad6f1727a84b94ac to your computer and use it in GitHub Desktop.

Select an option

Save mirsella/741848f8ee7c1389ad6f1727a84b94ac to your computer and use it in GitHub Desktop.
[Unit]
Description=Server daemon for Terraria
After=network.target
[Service]
WorkingDirectory=/storage/terrariaserver/
User=mirsella
Type=forking
# Default KillMode is 'control-group', which is typically desired.
# It allows systemd to send SIGTERM to the entire process group
# (including the 'screen' process) after ExecStop finishes or times out.
# Removed 'KillMode=none' as it complicates graceful shutdowns.
ExecStart=/usr/bin/screen -dmS terraria ./TerrariaServer.bin.x86_64 -config serverconfig.txt
# Send 'exit' command to the Terraria server within the screen session.
# The `\r` (carriage return) simulates pressing Enter after typing 'exit'.
ExecStop=/usr/bin/screen -S terraria -X stuff $'exit\r'
# Allow time for the Terraria server to save and shut down gracefully
# after the 'exit' command is sent, before systemd attempts to kill 'screen'.
TimeoutStopSec=30
# Commands in ExecStopPost run *after* the main service process has stopped.
# This is the appropriate place for post-shutdown tasks like backups.
ExecStopPost=/usr/bin/cp -r /storage/terrariaworlds /home/mirsella/downloads
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment