Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraria TModLoader Server Stack #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/.env
4 changes: 4 additions & 0 deletions terraria-tmod/.env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
WEBHOOK_URL=https://discord.com/api/webhooks/123456789012345678/addyourownvalidwebhook-thisonewillnotwork
SFTP_USERS=root:pass # required by image but not used
SFTP_PASS=<FILL IN YOUR OWN> # Invalid default value, used by sftp.d script to set root pass (terraria image runs as root)
DISCORD_USER=terraria.yourhostname.xyz
2 changes: 2 additions & 0 deletions terraria-tmod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config.txt
data
31 changes: 31 additions & 0 deletions terraria-tmod/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM frolvlad/alpine-glibc:alpine-3.10 as build

ARG TMOD_VERSION=0.11.8.5
ARG TERRARIA_VERSION=1353

RUN apk update &&\
apk add --no-cache --virtual build curl unzip &&\
apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing mono

WORKDIR /tmod

RUN cp /usr/lib/libMonoPosixHelper.so .

# Server URL changed or down?
#RUN curl -SLO "http://terraria.org/server/terraria-server-${TERRARIA_VERSION}.zip" &&\
# unzip terraria-server-*.zip &&\
# rm terraria-server-*.zip &&\
# cp --verbose -a "${TERRARIA_VERSION}/Linux/." . &&\
# rm -rf "${TERRARIA_VERSION}" &&\
# rm TerrariaServer.bin.x86 TerrariaServer.exe


RUN curl -SL "https://github.com/tModLoader/tModLoader/releases/download/v${TMOD_VERSION}/tModLoader.Linux.v${TMOD_VERSION}.tar.gz" | tar -xvz &&\
rm -r lib tModLoader.bin.x86 tModLoaderServer.bin.x86 &&\
chmod u+x tModLoaderServer*

FROM rfvgyhn/tmodloader:latest

WORKDIR /terraria-server
COPY --from=build /tmod ./

18 changes: 18 additions & 0 deletions terraria-tmod/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Terraria tMod docker-compose

Terraria tModLoader server. Used for Calamity Mod in my case.

Image used: https://github.com/Rfvgyhn/tmodloader-docker (Stale, building updated PR fork for latest)

## Optional notify container for non 24/7 servers

Notify container for discord, dead simple webhook message poster to notify if server is up/down. Include a MSG with your hours.

Edit your crontab (`crontab -e`) with hours you what your server to maintain. Slightly odd to not just do 24/7 but I believe it encourage more group play if you set server hours.

``` crontab
PATH=/usr/local/bin:/usr/bin:/bin
45 20 * * 2-5 /home/a/game-server-stacks/terraria-tmod/online.sh
0 0 * * 3-6 /home/a/game-server-stacks/terraria-tmod/offline.sh
```

42 changes: 42 additions & 0 deletions terraria-tmod/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '3'

services:
# --- Main TMOD Server, be sure to read parent image README for details/features/usage
tmod:
#image: 'rfvgyhn/tmodloader:latest'
# Building latest tmod version from PR fork/custom Dockerfile tweaks
build:
context: .
container_name: 'tmod'
ports:
- 7777:7777
volumes:
- /etc/localtime:/etc/localtime:ro
- ./data:/terraria
- ./config.txt:/terraria-server/config.txt
environment:
- TMOD_SHUTDOWN_MSG="See ya!"
# --- SFTP for manually managing mods/resources
sftp:
image: atmoz/sftp
volumes:
- ./data:/root/data
- ./config.txt:/root/config.txt
- /etc/ssh/
- ./enable-root-ssh:/etc/sftp.d/enable-root-ssh
ports:
- 2277:22
environment:
- SFTP_USERS # .env but not used
- SFTP_PASS # .env used to setup root in enable-root-ssh
# --- Custom notification scripts to let discord friends know when servers up or down
discord-notify:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disable auto-starting and sending 'test message' or modify script to just not send anything if MSG is null as a workaround to avoid using bleeding edge profile/docker-compose 2 beta features: https://stackoverflow.com/a/65957695/895792

image: curlimages/curl
environment:
- WEBHOOK_URL
- DISCORD_USER
- MSG=Test Message
volumes:
- ./notify.sh:/usr/local/bin/notify.sh
entrypoint: /usr/local/bin/notify.sh
# ---
2 changes: 2 additions & 0 deletions terraria-tmod/enable-root-ssh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sed -i 's|PermitRootLogin no|PermitRootLogin yes|g' /etc/ssh/sshd_config
echo -e "${SFTP_PASS}\n${SFTP_PASS}" | passwd root
12 changes: 12 additions & 0 deletions terraria-tmod/notify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh
set -ex
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove -x debug


env

echo '{
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test if MSG is null and don't try to send to make container noop by default.

"username": "' ${DISCORD_USER} '",
"content": "' ${MSG} '"
}' | curl \
-H "Content-Type: application/json" \
-d@- \
"${WEBHOOK_URL}"
7 changes: 7 additions & 0 deletions terraria-tmod/offline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -ex
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove -x debug

pushd "$(dirname $0)" # enables crontab to use this file
if [ -n "$(docker ps -q --filter name=tmod)" ] || [ -n "$FORCE" ] ; then
docker-compose stop tmod
docker-compose run --rm -e MSG="[Offline] Shutdown!" discord-notify
fi
7 changes: 7 additions & 0 deletions terraria-tmod/online.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -ex
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove -x debug

pushd "$(dirname $0)" # enables crontab to use this file
if [ -z "$(docker ps -q --filter name=tmod)" ] || [ -n "$FORCE" ] ; then
docker-compose up -d tmod
docker-compose run --rm -e MSG="[Online] Calamity Mod Server started, connect using TModLoader. Hours: 9PM-Mid Tue-Fri" discord-notify
fi