Skip to content

Commit

Permalink
Docker and Management Script Bugfixes (#3900)
Browse files Browse the repository at this point in the history
* docker and management bugfixes

* fix Ctrl+C not propagating to tml server

* fix management script permissions in a docker container

* add optional compose file configuration

* misc code cleanup

* fix entrypoint folder path

* use mkdir -p instead of try_make_dir

* bump management script version
  • Loading branch information
turtletowerz committed Jan 11, 2024
1 parent b1faab1 commit baa7ff1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ WORKDIR $HOME
# Update SteamCMD and verify latest version
RUN steamcmd +quit

RUN curl -O https://raw.githubusercontent.com/tModLoader/tModLoader/1.4.4/patches/tModLoader/Terraria/release_extras/DedicatedServerUtils/manage-tModLoaderServer.sh \
&& chmod u+x manage-tModLoaderServer.sh \
&& /bin/bash ./manage-tModLoaderServer.sh install-tml --github --tml-version $TML_VERSION
ADD --chown=tml:tml https://raw.githubusercontent.com/tModLoader/tModLoader/1.4.4/patches/tModLoader/Terraria/release_extras/DedicatedServerUtils/manage-tModLoaderServer.sh .

# If you need to make local edits to the management script copy it to the same
# directory as this file, comment out the above line and uncomment this line:
# COPY --chown=tml:tml manage-tModLoaderServer.sh .

RUN ./manage-tModLoaderServer.sh install-tml --github --tml-version $TML_VERSION

EXPOSE 7777

ENTRYPOINT [ "/bin/bash", "-c", "./manage-tModLoaderServer.sh docker --folder ~/.local/share/Terraria/tModLoader" ]
ENTRYPOINT [ "./manage-tModLoaderServer.sh", "docker", "--folder", "/home/tml/.local/share/Terraria/tModLoader" ]
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ To install and run the container:
1. Install `docker` from your package manager or [Docker's Official Page](https://docs.docker.com/engine/install/)
* **To check if Compose V2 is installed in this package**, run `docker compose version`. If the command errors, your manager still uses V1 and will need to additionally install the `docker-compose` package. All commands below assume Compose V2 is installed, so if you have V1 replace any `docker compose` commands with `docker-compose`
2. Download [docker-compose.yml](https://github.com/tModLoader/tModLoader/tree/1.4.4/patches/tModLoader/Terraria/release_extras/DedicatedServerUtils/docker-compose.yml) and the [Dockerfile](https://github.com/tModLoader/tModLoader/tree/1.4.4/patches/tModLoader/Terraria/release_extras/DedicatedServerUtils/Dockerfile)
3. If you would like to install mods or use existing worlds, create a folder named `tModLoader`. In that directory setup a proper [folder structure](#folder-structure)
3. Create an empty folder named `tModLoader`. This is **required**. If you would like to install mods or use existing worlds then setup a proper [folder structure](#folder-structure) in that directory
4. Edit `docker-compose.yml` with your GID and UID. These can be found by running `id`, and generally default to 1000
* You can also add the `TML_VERSION` arg to your compose file to set a specific tModLoader version. Read about how to set build arguments [here](https://docs.docker.com/compose/compose-file/build/#args)
* Uncomment the `restart` line to have the server automatically restart if it crashes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
args:
UID: 1000
GID: 1000
#TML_VERSION: v2023.8.3.3
#entrypoint: [ "/bin/bash" ] # Uncomment this line if you need to poke around in the container
tty: true
stdin_open: true
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#shellcheck disable=2164

# Only update the major version when a breaking change is introduced
script_version="3.0.0.0"
script_version="3.0.0.1"
script_url="https://raw.githubusercontent.com/tModLoader/tModLoader/1.4.4/patches/tModLoader/Terraria/release_extras/DedicatedServerUtils/manage-tModLoaderServer.sh"

# Shut up both commands
Expand All @@ -15,6 +15,12 @@ function popd {
command popd > /dev/null || return
}

function try_make_link {
if ! [[ -L "$2" ]]; then
ln -s "$1" "$2"
fi
}

# NOTE: There is seemingly no official documentation on this file but other more "official" software does this same check.
# See: https://github.com/moby/moby/blob/v24.0.5/libnetwork/drivers/bridge/setup_bridgenetfiltering.go#L162-L165
function is_in_docker {
Expand All @@ -25,6 +31,10 @@ function is_in_docker {
}

function update_script {
if is_in_docker; then
return
fi

echo "Checking for script updates"

# Go to where the script currently is
Expand All @@ -44,7 +54,7 @@ function update_script {
echo "There is a script update from v$script_version to v$new_version, consider rebuilding your Docker container for the updated script"
return
fi

if [[ "${script_version:0:1}" != "${new_version:0:1}" ]]; then
read -t 15 -p "A major version change has been detected (v$script_version -> v$new_version) Major versions mean incompatibilities with previous versions, so you should check the wiki for any updates to how the script works. Update anyways? (y/n): " update_major
if [[ "$update_major" != [Yy]* ]]; then
Expand Down Expand Up @@ -104,7 +114,7 @@ function move_serverconfig {
echo "Removing duplicate server/serverconfig.txt"
rm serverconfig.txt
fi
else
elif ! is_in_docker; then # Only move the server config if it's not in Docker
echo "Moving default serverconfig.txt"
mv serverconfig.txt "$folder"
fi
Expand All @@ -119,7 +129,7 @@ function get_version {
echo "v$(cat $folder/Mods/tmlversion.txt | sed -E "s/\.([0-9])\./\.0\1\./g")"
else
# Get the latest release if no other options are provided
local release_url="https://api.github.com/repos/tModLoader/tModLoader/releases"
local release_url="https://api.github.com/repos/tModLoader/tModLoader/releases/latest"
local latest_release
latest_release=$({
curl -s "$release_url" 2>/dev/null || wget -q -O- "$release_url";
Expand Down Expand Up @@ -199,21 +209,21 @@ function install_tml_steam {
}

function install_tml {
mkdir server 2>/dev/null
mkdir -p server
pushd server
if $steamcmd; then
install_tml_steam
else
install_tml_github
fi

move_serverconfig
popd

# Make folder structure
if !is_in_docker; then
if ! is_in_docker; then
echo "Creating folder structure"
mkdir Mods Worlds server logs 2>/dev/null
mkdir -p Mods Worlds logs
fi

# Install .NET
Expand Down Expand Up @@ -259,7 +269,7 @@ function install_workshop_mods {
eval "$steam_cmd +force_install_dir $folder +login anonymous $steamcmd_command +quit"

popd

echo "Done"
}

Expand Down Expand Up @@ -377,20 +387,17 @@ case $cmd in
fi

# Make proper directories to bypass install_workshop_mods warnings
mkdir Mods Worlds 2>/dev/null
mkdir -p Mods Worlds

install_workshop_mods

# Link the server folder to the Docker installation and cli args for debugging (if it exists)
if ! [[ -L "$folder/server" ]]; then
ln -s "$HOME/server" "$folder/server"
fi
try_make_link "$HOME/server" "$folder/server"

# Also symlink banlist
if ! [[ -L "$folder/banlist.txt" ]]; then
ln -s "$folder/banlist.txt" "$folder/server/banlist.txt"
fi
try_make_link "$folder/banlist.txt" "$folder/server/banlist.txt"

# Provide option to use custom argsConfig file
if [[ -f "$folder/cli-argsConfig.txt" ]]; then
ln -s "$folder/cli-argsConfig.txt" "$folder/server/cli-argsConfig.txt"
fi
Expand All @@ -403,13 +410,11 @@ case $cmd in
fi

# Link logs to a more convenient place
mkdir "$folder/logs" 2>/dev/null
ln -s "$folder/logs" "$folder/server/tModLoader-Logs"
mkdir -p "$folder/logs"
try_make_link "$folder/logs" "$folder/server/tModLoader-Logs"

# Link workshop to tMod dir so we don't need to pass -steamworkshopfolder
if ! [[ -L "$folder/server/steamapps" ]]; then
ln -s "$folder/steamapps" "$folder/server/steamapps"
fi
try_make_link "$folder/steamapps" "$folder/server/steamapps"

cd "$folder/server" || exit
chmod u+x start-tModLoaderServer.sh
Expand Down

0 comments on commit baa7ff1

Please sign in to comment.