Skip to content
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
2 changes: 1 addition & 1 deletion template/vanilla/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM mono:slim
# Update and install needed utils
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y curl nuget vim zip && \
apt-get install -y curl nuget vim zip procps && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

Expand Down
39 changes: 38 additions & 1 deletion template/vanilla/run-vanilla.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,42 @@ if [ "${world:-null}" != null ]; then
CMD="$CMD -world /config/$world"
fi

# Create named pipe if one doesn't already exist
# This is so we can send input to TerrariaServer
if [ ! -p "/vanilla/console" ]; then
mkfifo /vanilla/console
fi

# trap SIGTERM signal and call graceful_shutdown
trap 'kill ${!}; graceful_shutdown' SIGTERM

function graceful_shutdown() {
# Send a message to players that the server is shutting down
echo say 'Server shutting down' > /vanilla/console

echo "Stopping Terraria server..."
echo "Saving world"

echo exit > /vanilla/console

# Waiting for server to finish saving & shutting down
pid=$(pgrep -f ^./TerrariaServer)
if [ -z "$pid" ]; then exit 1; fi
while [ -e /proc/$pid ]; do
sleep 1
done
echo "World save complete"
echo "Shutting down"
exit 0
}

echo "Starting container, CMD: $CMD $@"
exec $CMD $@
(tail -f > /vanilla/console & $CMD $@ < console) &

tail -f /dev/null & wait ${!}

pid=$(pgrep -f ^./TerrariaServer)
if [ -z "$pid" ]; then exit 1; fi
while [ -e /proc/$pid ]; do
sleep 5
done