Skip to content

Commit

Permalink
Revert "Implement Valheim Plus mod support (lloesche#76)"
Browse files Browse the repository at this point in the history
This reverts commit 6b8d353.

Server was restarting on every update check. PR not well tested.
  • Loading branch information
lloesche committed Feb 23, 2021
1 parent 3cbc334 commit c19b1d5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 111 deletions.
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@ RUN dpkg --add-architecture i386 \
libsdl2-2.0-0:i386 \
libcurl4 \
libcurl4:i386 \
libc6-dev \
ca-certificates \
supervisor \
procps \
locales \
unzip \
zip \
rsync \
curl \
jq \
&& echo 'LANG="en_US.UTF-8"' > /etc/default/locale \
&& echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
&& ln -s /bin/busybox /sbin/syslogd \
Expand All @@ -41,7 +38,7 @@ RUN dpkg --add-architecture i386 \
&& ln -s /bin/busybox /usr/bin/wget \
&& locale-gen \
&& apt-get clean \
&& mkdir -p /var/spool/cron/crontabs /var/log/supervisor /opt/valheim /opt/valheimplus /opt/steamcmd /root/.config/unity3d/IronGate /config \
&& mkdir -p /var/spool/cron/crontabs /var/log/supervisor /opt/valheim /opt/valheim_dl /opt/steamcmd /root/.config/unity3d/IronGate /config \
&& ln -s /config /root/.config/unity3d/IronGate/Valheim \
&& tar xzvf /tmp/steamcmd_linux.tar.gz -C /opt/steamcmd/ \
&& chown -R root:root /opt/steamcmd \
Expand All @@ -52,7 +49,7 @@ RUN dpkg --add-architecture i386 \
COPY supervisord.conf /etc/supervisor/supervisord.conf

ENV TZ=Etc/UTC
VOLUME ["/config", "/opt/valheim", "/opt/valheimplus"]
VOLUME ["/config", "/opt/valheim_dl"]
EXPOSE 2456-2458/udp
WORKDIR /
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# lloesche/valheim-server Docker image
![Valheim](https://raw.githubusercontent.com/lloesche/valheim-server-docker/main/misc/Logo_valheim.png "Valheim")

Valheim Server in a Docker Container (with optional [Valheim Plus](https://github.com/nxPublic/ValheimPlus) mod support)
Valheim Server in a Docker Container


# Basic Docker Usage
Expand All @@ -10,27 +10,22 @@ The name of the Docker image is `lloesche/valheim-server`.

Volume mount the server config directory to `/config` within the Docker container.

If you would also like to enable Valheim Plus, please also volume mount the server files directory `/opt/valheim` so that you can modify the mod's config file.

If you have an existing world on a Windows system you can copy it from e.g.
`C:\Users\Lukas\AppData\LocalLow\IronGate\Valheim\worlds`
to e.g.
`$HOME/valheim-server-config/worlds`
and run the image with `$HOME/valheim-server-config` volume mounted to `/config` inside the container.

```
$ mkdir -p $HOME/valheim-server/config/worlds
$ mkdir -p $HOME/valheim-server-config/worlds
# copy existing world
$ docker run -d \
--name valheim-server \
-p 2456-2458:2456-2458/udp \
-v $HOME/valheim-server/config:/config \
-v $HOME/valheim-server/files:/opt/valheim \
-v $HOME/valheim-server-config:/config \
-e SERVER_NAME="My Server" \
-e SERVER_PASS="secret" \
-e WORLD_NAME="Neotopia" \
-e PUBLIC=1 \
-e VALHEIM_PLUS_ENABLED=false
-e SERVER_PASS="secret" \
lloesche/valheim-server
```

Expand Down Expand Up @@ -63,8 +58,6 @@ For more deployment options see the [Deployment section](#deployment).
| `UPDATE_INTERVAL` | `900` | How often we check Steam for an updated server version in seconds |
| `RESTART_CRON` | `0 5 * * *` | [Cron schedule](https://en.wikipedia.org/wiki/Cron#Overview) for server restarts (disabled if set to an empty string) |
| `TZ` | `Etc/UTC` | Container [time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) |
| `VALIDATE` | `false` | Run Steam's validation on container start (does not affect update checks). If Valheim Plus is enabled, then it will be reinstalled |
| `VALHEIM_PLUS_ENABLED` | `false` | Enable support for the popular [Valheim Plus](https://github.com/nxPublic/ValheimPlus) mod |
| `BACKUPS` | `true` | Whether the server should create periodic backups (`true` or `false`) |
| `BACKUPS_INTERVAL` | `3600` | Interval in seconds between backup runs |
| `BACKUPS_DIRECTORY` | `/config/backups` | Path to the backups directory |
Expand All @@ -74,7 +67,7 @@ For more deployment options see the [Deployment section](#deployment).
| `CONFIG_DIRECTORY_PERMISSIONS` | `755` | Unix permissions for the /config directory |
| `WORLDS_DIRECTORY_PERMISSIONS` | `755` | Unix permissions for the /config/worlds directory |
| `WORLDS_FILE_PERMISSIONS` | `644` | Unix permissions for the files in /config/worlds |
| `STEAMCMD_ARGS` | | Additional steamcmd CLI arguments |
| `STEAMCMD_ARGS` | `validate` | Additional steamcmd CLI arguments |
| `DNS_1` | `8.8.8.8` | First DNS server to use for the container to resolve hostnames (systemd only) |
| `DNS_2` | `8.8.4.4` | Second DNS server to use for the container to resolve hostnames (systemd only) |

Expand Down Expand Up @@ -122,7 +115,6 @@ CDK Project for spinning up a Valheim game server on AWS Using ECS Fargate and A
By default the container will check for Valheim server updates every 15 minutes.
If an update is found it is downloaded and the server restarted.
This interval can be changed using the `UPDATE_INTERVAL` environment variable.
Additionally, if Valheim Plus is enabled, it will also automatically check for updates for the mod as well.


# Backups
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "3.9"
services:
valheim:
image: lloesche/valheim-server
volumes:
- /path/to/valheim/settings:/config
ports:
- "2456-2458:2456-2458/udp"
environment:
- SERVER_NAME=Server Name
- SERVER_PASS=secret
- SERVER_PUBLIC=1
17 changes: 0 additions & 17 deletions docker-compose.yml

This file was deleted.

24 changes: 6 additions & 18 deletions valheim-server
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/bin/bash
cd /opt/valheim
valheim_server_dir="/opt/valheim"
valheim_server="$valheim_server_dir/valheim_server.x86_64"
valheim_server="/opt/valheim/valheim_server.x86_64"
valheim_server_pid=-1
SERVER_NAME=${SERVER_NAME:-My Server}
SERVER_PORT=${SERVER_PORT:-2456}
WORLD_NAME=${WORLD_NAME:-Dedicated}
SERVER_PASS=${SERVER_PASS:-secret}
SERVER_PUBLIC=${SERVER_PUBLIC:-1}
VALHEIM_PLUS_ENABLED=${VALHEIM_PLUS_ENABLED:-false}
timeout=20
kill_signal=TERM

export SteamAppId=892970
export LD_LIBRARY_PATH="/opt/valheim/linux64/"

main() {
while :; do
if [ -f "$valheim_server" ]; then
Expand All @@ -22,21 +23,8 @@ main() {
fi
done
echo "Running Valheim Server"
export SteamAppId=892970
export LD_LIBRARY_PATH="$valheim_server_dir/linux64:$LD_LIBRARY_PATH"
if [ $VALHEIM_PLUS_ENABLED = true ]; then
doorstop_libs="$valheim_server_dir/doorstop_libs"
arch="x64"
lib_postfix="so"
doorstop_libname=libdoorstop_${arch}.${lib_postfix}
export DOORSTOP_ENABLE=TRUE
export DOORSTOP_INVOKE_DLL_PATH="$valheim_server_dir/BepInEx/core/BepInEx.Preloader.dll"
export LD_LIBRARY_PATH="${doorstop_libs}":${LD_LIBRARY_PATH}
export LD_PRELOAD=$doorstop_libname:$LD_PRELOAD
export DYLD_LIBRARY_PATH="${doorstop_libs}"
export DYLD_INSERT_LIBRARIES="${doorstop_libs}/$doorstop_libname"
fi
"$valheim_server" -nographics -batchmode -name "$SERVER_NAME" -port $SERVER_PORT -world "$WORLD_NAME" -password "$SERVER_PASS" -public $SERVER_PUBLIC &valheim_server_pid=$!
"$valheim_server" -nographics -batchmode -name "$SERVER_NAME" -port $SERVER_PORT -world "$WORLD_NAME" -password "$SERVER_PASS" -public $SERVER_PUBLIC &
valheim_server_pid=$!
wait
}

Expand Down
73 changes: 15 additions & 58 deletions valheim-updater
Original file line number Diff line number Diff line change
Expand Up @@ -5,82 +5,39 @@ CONFIG_DIRECTORY_PERMISSIONS=${CONFIG_DIRECTORY_PERMISSIONS:-755}
WORLDS_DIRECTORY_PERMISSIONS=${WORLDS_DIRECTORY_PERMISSIONS:-755}
WORLDS_FILE_PERMISSIONS=${WORLDS_FILE_PERMISSIONS:-644}
UPDATE_INTERVAL=${UPDATE_INTERVAL:-900}
STEAMCMD_ARGS=$(echo ${STEAMCMD_ARGS} | tr " " "\n" | sed -n '/\(-validate\b\|^validate\b\)/!p' | tr "\n" " ")
VALIDATE=${VALIDATE:-false}
VALHEIM_PLUS_ENABLED=${VALHEIM_PLUS_ENABLED:-true}
STEAMCMD_ARGS=${STEAMCMD_ARGS-validate}
just_started=true
next_update=$(date +%s)

cd /opt/steamcmd
main() {
while :; do
update_permissions
update_valheim
if [ $VALHEIM_PLUS_ENABLED = true ]; then
update_valheim_plus
fi
update
next_update=$(($(date +%s)+$UPDATE_INTERVAL))
while [ $(date +%s) -lt $next_update ]; do
sleep 5
done
done
}

install_valheim_plus() {
echo "Installing/Updating Valheim Plus"
curl -sL https://api.github.com/repos/nxPublic/ValheimPlus/releases/latest | jq -r '.assets[] | select(.name == "UnixServer.zip") | .updated_at' > "/opt/valheimplus/UnixServer.zip.last_update"
wget -q -O /opt/valheimplus/UnixServer.zip https://github.com/nxPublic/ValheimPlus/releases/latest/download/UnixServer.zip && \
unzip -qo /opt/valheimplus/UnixServer.zip -x changelog.txt run_bepinex.sh -d /opt/valheimplus
if [ -f /opt/valheim/BepInEx/config/valheim_plus.cfg ]; then
cp -a /opt/valheim/BepInEx/config/valheim_plus.cfg /opt/valheimplus/BepInEx/config/valheim_plus.cfg
fi
chmod 666 /opt/valheimplus/BepInEx/config/valheim_plus.cfg
rsync -a --itemize-changes --exclude UnixServer.zip /opt/valheimplus/ /opt/valheim
}

update_valheim_plus() {
remote_update_date=$(curl -sL https://api.github.com/repos/nxPublic/ValheimPlus/releases/latest | jq -r '.assets[] | select(.name == "UnixServer.zip") | .updated_at')
local_update_date=$(cat /opt/valheimplus/UnixServer.zip.last_update)
if [ "$remote_update_date" != "$local_update_date" ]; then
install_valheim_plus
else
echo "Valheim Plus is already the latest version"
fi
}

install_valheim() {
./steamcmd.sh +login anonymous +force_install_dir /opt/valheim +app_update 896660 $STEAMCMD_ARGS $1 +quit
if [ $VALHEIM_PLUS_ENABLED = true ]; then
install_valheim_plus
fi
echo "Valheim Server was updated - restarting"
supervisorctl restart valheim-server
}

update_valheim() {
if [ ! -d /opt/valheim/valheim_server_Data ] || [ $VALIDATE = true ]; then
echo "Installing Valheim Server"
args=""
if [ $VALIDATE = true ]; then
args=validate
VALIDATE=false
fi
install_valheim $args
update() {
local logfile="$(mktemp)"
echo "Updating/Validating Valheim Server"
./steamcmd.sh +login anonymous +force_install_dir /opt/valheim_dl +app_update 896660 $STEAMCMD_ARGS +quit
rsync -a --itemize-changes --delete --exclude server_exit.drp --exclude steamapps /opt/valheim_dl/ /opt/valheim | tee "$logfile"
grep '^[*>]' "$logfile" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Valheim Server was updated - restarting"
supervisorctl restart valheim-server
else
local_version=$(awk '/"896661"/,/"manifest"/{if($1=="\"manifest\"")print $2;}' /opt/valheim/steamapps/appmanifest_896660.acf | xargs)
./steamcmd.sh +login anonymous +force_install_dir /opt/valheim +app_update 896660 $STEAMCMD_ARGS +quit
remote_version=$(./steamcmd.sh +login anonymous +app_info_update 1 +app_info_print 896660 +quit | awk '/"896661"/,/"public"/{if($1=="\"manifest\"")print $2;}' | xargs)
if [ "$local_version" != "$remote_version" ]; then
echo "Updating/Validating Valheim Server"
install_valheim -validate
else
echo "Valheim Server is already the latest version"
if [ $just_started = true ]; then
supervisorctl start valheim-server
fi
echo "Valheim Server is already the latest version"
if [ $just_started = true ]; then
supervisorctl start valheim-server
fi
fi
just_started=false
rm -f "$logfile"
}

update_permissions() {
Expand Down

0 comments on commit c19b1d5

Please sign in to comment.