diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5966c57 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/.env diff --git a/terraria-tmod/.env-example b/terraria-tmod/.env-example new file mode 100644 index 0000000..6284fd3 --- /dev/null +++ b/terraria-tmod/.env-example @@ -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= # Invalid default value, used by sftp.d script to set root pass (terraria image runs as root) +DISCORD_USER=terraria.yourhostname.xyz diff --git a/terraria-tmod/.gitignore b/terraria-tmod/.gitignore new file mode 100644 index 0000000..b29fb9f --- /dev/null +++ b/terraria-tmod/.gitignore @@ -0,0 +1,2 @@ +config.txt +data diff --git a/terraria-tmod/Dockerfile b/terraria-tmod/Dockerfile new file mode 100644 index 0000000..6cce850 --- /dev/null +++ b/terraria-tmod/Dockerfile @@ -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 ./ + diff --git a/terraria-tmod/README.md b/terraria-tmod/README.md new file mode 100644 index 0000000..508e7cd --- /dev/null +++ b/terraria-tmod/README.md @@ -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 +``` + diff --git a/terraria-tmod/docker-compose.yaml b/terraria-tmod/docker-compose.yaml new file mode 100644 index 0000000..708cb9a --- /dev/null +++ b/terraria-tmod/docker-compose.yaml @@ -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: + 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 +# --- diff --git a/terraria-tmod/enable-root-ssh b/terraria-tmod/enable-root-ssh new file mode 100755 index 0000000..313cbfd --- /dev/null +++ b/terraria-tmod/enable-root-ssh @@ -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 diff --git a/terraria-tmod/notify.sh b/terraria-tmod/notify.sh new file mode 100755 index 0000000..3b1f37c --- /dev/null +++ b/terraria-tmod/notify.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env sh +set -ex + +env + +echo '{ + "username": "' ${DISCORD_USER} '", + "content": "' ${MSG} '" +}' | curl \ + -H "Content-Type: application/json" \ + -d@- \ + "${WEBHOOK_URL}" diff --git a/terraria-tmod/offline.sh b/terraria-tmod/offline.sh new file mode 100755 index 0000000..30c7c7b --- /dev/null +++ b/terraria-tmod/offline.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -ex +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 diff --git a/terraria-tmod/online.sh b/terraria-tmod/online.sh new file mode 100755 index 0000000..2dc9307 --- /dev/null +++ b/terraria-tmod/online.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -ex +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