CanadaBry / ValheimDocker

A Docker image to easily setup and run a dedicated server for the early access game Valheim
25 stars 6 forks source link

Disk Failure #2 #9

Closed MoryCorp closed 3 years ago

MoryCorp commented 3 years ago

Opening a new issue as all files changed.

image

Inside valheim directory

image

docker-compose.yml :

version: '3.3'
services:
    valheim:
        image: wilso224/valheim_dedicated_server
        container_name: valheim
        volumes:
            - '/home/holory/apps/valheim_sever/valheim:/home/steam/valheim'
        ports:
            - '2456:2456/udp'
            - '2457:2457/udp'
            - '2458:2458/udp'
        environment:
            - SERVER_NAME=Holory
            - SERVER_PORT=2456
            - SERVER_PASSWORD=morycorp
            - SERVER_WORLD=Holory
            - PUID=1000
            - PGID=1000

Dockerfile :

FROM debian:buster

# download requirements
RUN apt-get -y update && \
    apt-get -y install lib32gcc1 lib32stdc++6 curl && \
    apt-get clean && \
    rm -rf /var/lib/{apt,dpkg,cache,log}/

# setup steam user
RUN useradd -m steam
WORKDIR /home/steam

COPY server.sh .

# download steamcmd
RUN mkdir steamcmd && cd steamcmd && \
    curl "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar zxvf -

# start steamcmd to force it to update itself
RUN ./steamcmd/steamcmd.sh +quit && \
    mkdir -pv /home/steam/.steam/sdk32/ && \
    ln -s /home/steam/steamcmd/linux32/steamclient.so /home/steam/.steam/sdk32/steamclient.so

# start the server main script
ENTRYPOINT ["bash", "/home/steam/server.sh"]

server.sh

#!/bin/bash

PUID=${PUID:-1000}
PGID=${PGID:-1000}

usermod -u ${PUID} steam
groupmod -g ${PGID} steam
su -s /bin/bash -c 'id' steam

# update server's data
/home/steam/steamcmd/steamcmd.sh \
        +login anonymous \
            +force_install_dir /home/steam/valheim/server \
            +app_update 896660 \
                +exit

#Copy 64bit steamclient, since it keeps using 32bit
cp /home/steam/steamcmd/linux64/steamclient.so /home/steam/valheim/server/

#Apply default values for server if not set
SERVER_NAME=${SERVER_NAME:-My\ server}
SERVER_PORT=${SERVER_PORT:-2456}
SERVER_WORLD=${SERVER_WORLD:-Dedicated}
SERVER_PASSWORD=${SERVER_PASSWORD:-secret}

#Launch server
export LD_LIBRARY_PATH=./linux64:$LD_LIBRARY_PATH
export SteamAppId=892970
/home/steam/valheim/server/valheim_server.x86_64 -name "$SERVER_NAME" -port $SERVER_PORT -world "$SERVER_WORLD" -password "$SERVER_PASSWORD" -savedir "/home/steam/valheim/data" -public 1 &

#Trap Container Stop for graceful exit
trap "kill -SIGINT $!;" SIGTERM

#Wait for server to exit
while wait $!; [ $? != 0 ]; do true; done

Please tell me what I am doing wrong @CanadaBry @InB4DevOps

CanadaBry commented 3 years ago

Try taking my current repo (the one I just reverted to) and using this Dockerfile.

Dockerfile:

FROM debian:buster

# download requirements
RUN apt-get -y update && \
    apt-get -y install lib32gcc1 lib32stdc++6 curl && \
    apt-get clean && \
    rm -rf /var/lib/{apt,dpkg,cache,log}/

ENV PUID=1001
ENV PGID=1001

# setup steam user  # setup steam user
RUN groupadd --gid "${PGID}" -r steam 
RUN useradd -u "${PUID}" -r -g "${PGID}" -m -d /home/steam -c "Valheim server user" steam
WORKDIR /home/steam
USER steam

COPY server.sh .

# download steamcmd
RUN mkdir steamcmd && cd steamcmd && \
    curl "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar zxvf -

# start steamcmd to force it to update itself
RUN ./steamcmd/steamcmd.sh +quit && \
    mkdir -pv /home/steam/.steam/sdk32/ && \
    ln -s /home/steam/steamcmd/linux32/steamclient.so /home/steam/.steam/sdk32/steamclient.so

# start the server main script
ENTRYPOINT ["bash", "/home/steam/server.sh"]

In docker-compose.yml replace the line

image: wilso224/valheim_dedicated_server

with

image: valheim

Then run this in the directory:

mkdir valheim/
docker build . -t valheim
docker-compose up -d

This should make the user in the container have the same UID as your host user (assuming its still 1001).

MoryCorp commented 3 years ago

Trying

Edit : it seems to work. Server started with my imported map.

Inside the container :

image That's the first time "valheim" directory is created by the right user

InB4DevOps commented 3 years ago

Glad you have it working! :)

I guess this kinda means that my #7 is working :P

CanadaBry commented 3 years ago

Glad it’s finally working!

Glad you have it working! :)

I guess this kinda means that my #7 is working :P

Yeah, I found one issue with it when I merged it. The server.sh script was still running as root because su line only ran id as steam. The rest of the script was still running with root.

From some looking around, there wasn’t any nice (read: non hacky) way to change user mid shell script.

So the only option really is to build the image with the correct uid/gid you want.

MoryCorp commented 3 years ago

Many thanks for the help. So for next updates of the repo I'll have to change my user id to 1000 or build image myself ?

CanadaBry commented 3 years ago

Many thanks for the help. So for next updates of the repo I'll have to change my user id to 1000 or build image myself ?

Yeah, you’ll likely have to keep building it yourself with 1001. I’ll update the dockerfile in a bit to match the one I gave you here.

Haven’t had to address this sort of issue before, so I have to assess if this is the way I want to handle it or if I can find a better alternative

InB4DevOps commented 3 years ago

Why would @MoryCorp need to have UID&GID hard coded in the dockerfile? Can't he pass the values using the ENV variables? After all the dockerfile then uses those PGID and PUID variables.

CanadaBry commented 3 years ago

Why would @MoryCorp need to have UID&GID hard coded in the dockerfile? Can't he pass the values using the ENV variables? After all the dockerfile then uses those PGID and PUID variables.

Yeah, as long as the docker-compose is building the image as well as running it. Was busy for the last week, sorry for the late reply.