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

Moved trap to init #39

Merged
merged 2 commits into from
Feb 10, 2021
Merged
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
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ RUN apt-get update \
&& apt-get install -y \
htop net-tools nano \
netcat curl wget \
cron sudo
cron sudo gosu \
&& gosu nobody true

# Set up timezone information
ENV TZ=America/Los_Angeles
Expand Down Expand Up @@ -65,4 +66,4 @@ RUN usermod -u ${PUID} steam \
&& groupmod -g ${PGID} steam \
&& chsh -s /bin/bash steam

ENTRYPOINT ["/init.sh"]
ENTRYPOINT ["/bin/bash","/init.sh"]
2 changes: 1 addition & 1 deletion src/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ log "Starting server..."

odin start || exit 1

trap 'cleanup' INT TERM EXIT

cleanup() {
log "Halting server! Received interrupt!"
odin stop
exit
}
trap 'cleanup' INT TERM EXIT SIGINT SIGTERM

initialize "
Valheim Server Started...
Expand Down
15 changes: 13 additions & 2 deletions src/scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ write_env_var() {
# shellcheck disable=SC2039
VARIABLE_VALUE=$(printf '%s\n' "${!env_name}" | tr -d '"')
echo "Writing $1 to env file..."
if [ $2 = true ]; then
if [[ $2 = true ]]; then
echo "${env_name}=\"${VARIABLE_VALUE}\"" >> /home/steam/.env
else
echo "${env_name}=${VARIABLE_VALUE}" >> /home/steam/.env
Expand All @@ -71,6 +71,17 @@ write_env_var "PUBLIC"
write_env_var "PASSWORD" true
write_env_var "AUTO_UPDATE" true

su -s /bin/bash --login steam -c "/bin/bash /home/steam/scripts/entrypoint.sh"

trap 'cleanup' INT TERM EXIT

cleanup() {
echo "Running Cleanup!....."
gosu steam:steam /home/steam/scripts/shutdown.sh
exit 0
}

gosu steam:steam /home/steam/scripts/entrypoint.sh

while :; do
sleep 1s
done
7 changes: 7 additions & 0 deletions src/scripts/shutdown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
. /home/steam/scripts/load_env.sh
echo "
Shutting down the server.........
"
cd /home/steam/valheim || exit 1
odin stop || exit 1