Skip to content

Commit

Permalink
New functionality + permissions fix
Browse files Browse the repository at this point in the history
- Added DEBUG flag for debugging
- Added PGID and PUID flags for more control over permissions
- Added SKIPUPDATE flag to skip updating the server
- Fixed permissions issue (#44) by dropping to `root`
- Fixed server settings not persisting (#57)
- Split `init.sh` script into `init.sh ` and `run.sh`
  • Loading branch information
wolveix committed Oct 30, 2021
1 parent f0cf69f commit 5e4ed50
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 45 deletions.
18 changes: 14 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
FROM cm2network/steamcmd:root

COPY --chown=steam:steam Game.ini Engine.ini Scalability.ini init.sh /home/steam/
RUN set -x \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y sudo \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p /config \
&& chown steam:steam /config

USER steam
COPY init.sh /

COPY --chown=steam:steam Game.ini Engine.ini Scalability.ini run.sh /home/steam/

WORKDIR /config

ENV GAMECONFIGDIR="/config/gamefiles/FactoryGame/Saved" \
ENV DEBUG="false" \
GAMECONFIGDIR="/config/gamefiles/FactoryGame/Saved" \
GAMESAVESDIR="/home/steam/.config/Epic/FactoryGame/Saved/SaveGames" \
MAXPLAYERS="16" \
PGID="1000" \
PUID="1000" \
SKIPUPDATE="false" \
STEAMAPPID="1690800" \
STEAMBETA="false"

EXPOSE 7777/udp 15000/udp 15777/udp

ENTRYPOINT [ "/home/steam/init.sh" ]
ENTRYPOINT [ "/init.sh" ]
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ If you're currently playing `v4` (early access, **not** experimental), then plea

## Setup

According to [the official wiki](https://satisfactory.fandom.com/wiki/Dedicated_servers), expect to need 5GB - 10GB of RAM. This implementation raises the player cap from 4 to 16 by default, but you can specify any number by using the `MAXPLAYERS` environment variable.
According to [the official wiki](https://satisfactory.fandom.com/wiki/Dedicated_servers), expect to need 5GB - 10GB of RAM. This implementation raises the player cap from 4 to 8 by default, but you can specify any number by using the `MAXPLAYERS` environment variable.

You'll need to bind a local directory to the Docker container's `/config` directory. This directory will hold the following directories:

- `/backups` - the server will automatically backup your saves when the container first starts
- `/gamefiles` - this is for the game's files. They're stored outside of the container to avoid needing to redownload 15GB+ every time you want to rebuild the container
- `/saves` - this is for the game's saves. They're copied into the container on start

Before running the server image, you should find your user ID that will be running the container. This isn't necessary in most cases, but it's good to find out regardless. If you're seeing `permission denied` errors, then this is probably why. Find your ID in `Linux` by running the `id` command. Then grab the user ID (usually something like `1000`) and pass it into the `--user=1000` argument.
Before running the server image, you should find your user ID that will be running the container. This isn't necessary in most cases, but it's good to find out regardless. If you're seeing `permission denied` errors, then this is probably why. Find your ID in `Linux` by running the `id` command. Then grab the user ID (usually something like `1000`) and pass it into the `-e PGID=1000` and `-e PUID=1000` environment variables.

Run the Satisfactory server image like this:

```bash
docker run -d --name=satisfactory-server -h satisfactory-server -e MAXPLAYERS=16 -e STEAMBETA=false -v /path/to/config:/config -p 7777:7777/udp -p 15000:15000/udp -p 15777:15777/udp --user=1000 wolveix/satisfactory-server:latest
docker run -d --name=satisfactory-server -h satisfactory-server -e DEBUG=false -e MAXPLAYERS=8 -e PGID=1000 -e PUID=1000 -e SKIPUPDATE=false -e STEAMBETA=false -v /path/to/config:/config -p 7777:7777/udp -p 15000:15000/udp -p 15777:15777/udp wolveix/satisfactory-server:latest
```

If you're using [Docker Compose](https://docs.docker.com/compose/):
Expand All @@ -37,11 +37,14 @@ services:
- '7777:7777/udp'
- '15000:15000/udp'
- '15777:15777/udp'
user: '1000'
volumes:
- '/path/to/config:/config'
environment:
- MAXPLAYERS=16
- DEBUG=false
- MAXPLAYERS=8
- PGID=1000
- PUID=1000
- SKIPUPDATE=false
- STEAMBETA=false
restart: unless-stopped
```
Expand Down Expand Up @@ -70,4 +73,5 @@ The [Satisfactory Wiki](https://satisfactory.fandom.com/wiki/Multiplayer#Engine.

## Known Issues

- The container is run as `root`. This is pretty common for Docker images, but is bad practice for security reasons. This change was made to address [permissions issues](https://github.com/wolveix/satisfactory-server/issues/44)
- The server log will show various errors; most of which can be safely ignored. As long as the container continues to run and your log looks similar to the example log, the server should be functioning just fine: [example log](https://github.com/wolveix/satisfactory-server/blob/main/server.log)
59 changes: 23 additions & 36 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,37 @@

set -e

# temporary addition as the game doesn't respect the config directory being within /config/gamefiles
GAMESAVESDIR="/home/steam/.config/Epic/FactoryGame/Saved/SaveGames"
if [[ "$DEBUG" == "true" ]]; then
printf "Debugging enabled (the container will exit after printing the debug info)\\n\\nPrinting environment variables:\\n"
export

mkdir -p /config/backups /config/gamefiles /config/saves "${GAMECONFIGDIR}/Config/LinuxServer" "${GAMECONFIGDIR}/Logs" "${GAMECONFIGDIR}/SaveGames/server" "${GAMESAVESDIR}/server" || exit 1
printf "\\n\\nDisk usage:\\n"
df -h | awk '$NF=="/"{printf "%d/%dGB (%s)\n", $3,$2,$5}'

printf "\\nCurent user:\\n"
id

NUMCHECK='^[0-9]+$'
if ! [[ "$MAXPLAYERS" =~ $NUMCHECK ]] ; then
printf "Invalid max players given: ${MAXPLAYERS}\\n"
MAXPLAYERS="16"
printf "\\nExiting...\\n"
exit 1
fi

printf "Setting max players to ${MAXPLAYERS}\\n"
sed "s/MaxPlayers\=16/MaxPlayers=$MAXPLAYERS/" -i "/home/steam/Game.ini"

if [[ "$STEAMBETA" == "true" ]]; then
printf "Experimental flag is set. Experimental will be downloaded instead of Early Access.\\n"
STEAMBETAFLAG=" -beta experimental"
fi
mkdir -p /config/backups /config/gamefiles /config/saves "${GAMECONFIGDIR}/Config/LinuxServer" "${GAMECONFIGDIR}/Logs" "${GAMECONFIGDIR}/SaveGames/server" "${GAMESAVESDIR}/server" || exit 1

printf "Checking available space...\\n"
space=$(stat -f --format="%a*%S" .)
space=$((space/1024/1024/1024))
NUMCHECK='^[0-9]+$'

if [[ "$space" -lt 5 ]]; then
printf "You have less than 5GB (${space}GB detected) of available space to download the game.\\nIf this is a fresh install, it will probably fail.\\n"
if ! [[ "$PGID" =~ $NUMCHECK ]] ; then
printf "Invalid group id given: ${PGID}\\n"
PGID="1000"
fi

printf "Downloading the latest version of the game...\\n"

/home/steam/steamcmd/steamcmd.sh +login anonymous +force_install_dir /config/gamefiles +app_update "$STEAMAPPID$STEAMBETAFLAG" +quit

cp -a /config/saves/. /config/backups/
cp -a "${GAMESAVESDIR}/server/." /config/backups # useless in first run, but useful in additional runs
rm -rf "${GAMESAVESDIR}/server"
ln -sf /config/saves "${GAMESAVESDIR}/server"
ln -sf /config/ServerSettings.15777 "${GAMESAVESDIR}/ServerSettings.15777"

cp /home/steam/{Engine.ini,Game.ini,Scalability.ini} "${GAMECONFIGDIR}/Config/LinuxServer"

if [ ! -f "/config/gamefiles/Engine/Binaries/Linux/UE4Server-Linux-Shipping" ]; then
printf "Game binary is missing.\\n"
exit 1
if ! [[ "$PUID" =~ $NUMCHECK ]] ; then
printf "Invalid user id given: ${PUID}\\n"
PUID="1000"
fi

cd /config/gamefiles || exit 1
groupmod -g "${PGID}" steam || exit 1
usermod -u "${PUID}" steam || exit 1

chown -R steam:steam /config /home/steam

Engine/Binaries/Linux/UE4Server-Linux-Shipping FactoryGame -log -NoSteamClient -unattended
sudo -u steam -E -H sh -c "/home/steam/run.sh"
52 changes: 52 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

set -e

NUMCHECK='^[0-9]+$'

if ! [[ "$MAXPLAYERS" =~ $NUMCHECK ]] ; then
printf "Invalid max players given: ${MAXPLAYERS}\\n"
MAXPLAYERS="16"
fi

printf "Setting max players to ${MAXPLAYERS}\\n"
sed "s/MaxPlayers\=16/MaxPlayers=$MAXPLAYERS/" -i "/home/steam/Game.ini"

if [[ "$SKIPUPDATE" == "false" ]]; then
if [[ "$STEAMBETA" == "true" ]]; then
printf "Experimental flag is set. Experimental will be downloaded instead of Early Access.\\n"
STEAMBETAFLAG=" -beta experimental"
fi

space=$(stat -f --format="%a*%S" .)
space=$((space/1024/1024/1024))
printf "Checking available space...${space}GB detected\\n"

if [[ "$space" -lt 5 ]]; then
printf "You have less than 5GB (${space}GB detected) of available space to download the game.\\nIf this is a fresh install, it will probably fail.\\n"
fi

printf "Downloading the latest version of the game...\\n"

/home/steam/steamcmd/steamcmd.sh +login anonymous +force_install_dir /config/gamefiles +app_update "$STEAMAPPID$STEAMBETAFLAG" +quit
else
printf "Skipping update as flag is set\\n"
fi

cp -a /config/saves/. /config/backups/
cp -a "${GAMESAVESDIR}/server/." /config/backups # useless in first run, but useful in additional runs
rm -rf "${GAMESAVESDIR}/server"
ln -sf /config/saves "${GAMESAVESDIR}/server"
ln -sf /config/ServerSettings.15777 "${GAMESAVESDIR}/ServerSettings.15777"
chmod 755 /config/ServerSettings.15777

cp /home/steam/{Engine.ini,Game.ini,Scalability.ini} "${GAMECONFIGDIR}/Config/LinuxServer"

if [ ! -f "/config/gamefiles/Engine/Binaries/Linux/UE4Server-Linux-Shipping" ]; then
printf "Game binary is missing.\\n"
exit 1
fi

cd /config/gamefiles || exit 1

Engine/Binaries/Linux/UE4Server-Linux-Shipping FactoryGame -log -NoSteamClient -unattended

0 comments on commit 5e4ed50

Please sign in to comment.