Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thmhoag committed Mar 10, 2019
0 parents commit 7169aaf
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
helm/
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM thmhoag/steamcmd:latest

USER root

RUN apt-get update && \
apt-get install -y curl cron bzip2 perl-modules lsof libc6-i386 lib32gcc1 sudo

RUN curl -sL "http://git.io/vtf5N" | bash -s steam && \
ln -s /usr/local/bin/arkmanager /usr/bin/arkmanager

COPY arkmanager/arkmanager.cfg /etc/arkmanager/arkmanager.cfg
COPY arkmanager/instance.cfg /etc/arkmanager/instances/main.cfg
COPY run.sh /home/steam/run.sh
COPY log.sh /home/steam/log.sh

RUN mkdir /ark && \
chown -R steam:steam /home/steam/ /ark

RUN echo "%sudo ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers && \
usermod -a -G sudo steam && \
touch /home/steam/.sudo_as_admin_successful

WORKDIR /home/steam
USER steam

ENV am_ark_SessionName="Ark Server" \
am_serverMap="TheIsland" \
am_ark_ServerAdminPassword="k3yb04rdc4t" \
am_ark_MaxPlayers=70 \
am_ark_QueryPort=27015 \
am_ark_Port=7778 \
am_ark_RCONPort=32330 \
am_arkwarnminutes=15

VOLUME /ark

CMD [ "./run.sh" ]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Thomas Hoag

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# arkserver
```
Docker image for a dedicated ARK Server with arkmanager.
```

## Overview

This is an image for running an ARK: Survival Evolved server in a Docker container. It is heavily based off of [TuRz4m](https://github.com/TuRz4m)'s work located here: [TuRz4m/Ark-docker](https://github.com/TuRz4m/Ark-docker). It uses [FezVrasta](https://github.com/FezVrasta)'s [arkmanager](https://github.com/FezVrasta/ark-server-tools) (ark-server-tools) to managed a single-instance ARK: Survival Evolved server inside a docker container.

This image inherits from the [thmhoag/steamcmd](https://github.com/thmhoag/steamcmd) image to include the latest version of `steamcmd`.

For more information on `arkmanager`, see the repo here: https://github.com/FezVrasta/ark-server-tools

### Features
* Automated install (pull the image and run, no additional commands necessary)
* Configuration via Environment Variables
* Easy crontab manipulation for automated backups, updates, daily restarts, weekly dino wipes, etc
* Simple volume structure for server files, config, logs, backups, etc
* Inherently includes all features present in `arkmanager`

### Tags
| Tag | Description |
|--|--|
| latest | most recent build from the master branch |
| x.x.x (semver) | release builds |

## Usage

### Installing the image

Pull the latest (or any other desired version):
```bash
docker pull thmhoag/arkserver:latest
```

### Running the server

To run a generic server with no configuration modifications:
```bash
$ docker run -d \
-v steam:/home/steam/Steam \ # mounted so that workshop (mod) downloads are persisted
-v ark:/ark \ # mounted as the directory to contain the server/backup/log/config files
-p 27015:27015 -p 27015:27015/udp \ # steam query port
-p 7778:7778 -p 7778:7778/udp \ # gameserver port
thmhoag/arkserver
```

If the exposed ports are modified (in the case of multiple containers/servers on the same host) the `arkmanager` config will need to be modified to reflect the change as well. This is required so that `arkmanager` can properly check the server status and so that the ARK server itself can properly publish its IP address and query port to steam.

## Environment Variables

A set of required environment variables have default values provided as part of the image:

| Variable | Value | Description |
| - | - | - |
| am_ark_SessionName | `Ark Server` | Server name as it will show on the steam server list |
| am_serverMap | `TheIsland` | Game map to load |
| am_ark_ServerAdminPassword | `k3yb04rdc4t` | Admin password to be used via ingame console or RCON |
| am_ark_MaxPlayers | `70` | Max concurrent players in the game |
| am_ark_QueryPort | `27015` | Steam query port (allows the server to show up on the steam list) |
| am_ark_Port | `7778` | Game server port (allows clients to connect to the server) |
| am_ark_RCONPort | `32330` | RCON port |
| am_arkwarnminutes | `15` | Number of minutes to wait/warn players before updating/restarting |

### Adding Additional Variables

Any configuration value that is available via `arkmanager` can be set using an environment variable. This works by taking any environment variable on the container that is prefixed with `am_` and mapping it to the corresponding environment variable in the `arkmanager.cfg` file.

For a complete list of configuration values available, please see [FezVrasta](https://github.com/FezVrasta)'s great documentation here: [arkmanager Configuration Files](https://github.com/FezVrasta/ark-server-tools#configuration-files)

## Volumes

This image has two main volumes that should be mounted as named volumes or host directories for the persistence of the server install and all related configuration files. More information on Docker volumes here: [Docker: Use Volumes](https://docs.docker.com/storage/volumes/)

| Path | Description |
| - | - |
| /home/steam/Steam | Directory of steam cache and other steamcmd-related files. Should be mounted so that mod installs are persisted between container runs/restarts |
| /ark | Directory that will contain the server files, config files, logs and backups. More information below |

### Subdirectories of /ark

Inside the `/ark` volume there are several directories containing server related files:

| Path | Description |
| - | - |
| /ark/backup | Location of the zipped backups genereated from the `arkmaanger backup` command. Compressed using bz2. |
| /ark/config | Location of server config files. More information: |
| /ark/log | Location of the arkmanager and arkserver log files |
| /ark/server | Location of the server installation performed by `steamcmd`. This will contain the ShooterGame directory and the actual server binaries. |
| /ark/staging | Default directory for staging game and mod updates. Can be changed using in `arkmanager.cfg` |
86 changes: 86 additions & 0 deletions arkmanager/arkmanager.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# --- SYSTEM CONFIG - DO NOT TOUCH ---#
arkstChannel="master" # change it to a different branch to get non-stable versions
install_bindir="/usr/bin"
install_libexecdir="/usr/libexec/arkmanager"
install_datadir="/usr/share/arkmanager"


# config SteamCMD
steamcmdroot="/home/steam/.steam/steamcmd" # path of your steamcmd instance
steamcmdexec="steamcmd.sh" # name of steamcmd executable
steamcmd_user="steam" # name of the system user who own steamcmd folder
steamcmd_appinfocache="/home/steam/.steam/appcache/appinfo.vdf" # cache of the appinfo command
steamcmd_workshoplog="/home/steam/.steam/logs/workshop_log.txt" # Steam workshop log

# config environment
arkserverroot="/ark/server" # path of your ARK server files (default ~/ARK)
arkserverexec="ShooterGame/Binaries/Linux/ShooterGameServer" # name of ARK server executable
arkbackupdir="/ark/backup" # path to backup directory
arkwarnminutes="60" # number of minutes to warn players when using update --warn
arkautorestartfile="ShooterGame/Saved/.autorestart" # path to autorestart file
arkStagingDir="/ark/staging"

# Port config
ark_Port="7778" # ARK server port (default 7778)
ark_QueryPort="27016" # ARK query port (default 27016)
ark_RCONEnabled="True" # Enable RCON Protocol
ark_RCONPort="32330" # RCON Port

# Update warning messages
# Modify as desired, putting the %d replacement operator where the number belongs
msgWarnUpdateMinutes="This ARK server will shutdown for an update in %d minutes"
msgWarnUpdateSeconds="This ARK server will shutdown for an update in %d seconds"
msgWarnRestartMinutes="This ARK server will shutdown for a restart in %d minutes"
msgWarnRestartSeconds="This ARK server will shutdown for a restart in %d seconds"
msgWarnShutdownMinutes="This ARK server will shutdown in %d minutes"
msgWarnShutdownSeconds="This ARK server will shutdown in %d seconds"
msgWarnCancelled="Restart cancelled by player request"

# Restart cancel chat command
#chatCommandRestartCancel="/cancelupdate"

# ARK server common options - use ark_<optionname>=<value>
# comment out these values if you want to define them
# inside your GameUserSettings.ini file
serverMap="TheIsland" # server map (default TheIsland)
#serverMapModId="469987622" # Uncomment this to specify the Map Mod Id (<fileid> in http://steamcommunity.com/sharedfiles/filedetails/?id=<fileid>)
#ark_TotalConversionMod="496735411" # Uncomment this to specify a total-conversion mod
ark_RCONEnabled="True" # Enable RCON Protocol
ark_ServerPassword="" # ARK server password, empty: no password required to login
ark_ServerAdminPassword="k3yb04rdc4t" # ARK server admin password, KEEP IT SAFE!
ark_MaxPlayers="70"
#ark_GameModIds="487516323,487516324,487516325" # Uncomment to specify additional mods by Mod Id separated by commas
#ark_AltSaveDirectoryName="SotF" # Uncomment to specify a different save directory name
arkflag_log=""

# ----- Mods ----- #
#ark_GameModIds="487516323,487516324,487516325" # Uncomment to specify additional mods by Mod Id separated by commas
# Mod OS Selection
mod_branch=Windows
# Add mod-specific OS selection below:
#mod_branch_496735411=Windows
# ----------------#

# ARK server flags - use arkflag_<optionname>=true
#arkflag_OnlyAdminRejoinAsSpectator=true # Uncomment to only allow admins to rejoin as spectator
#arkflag_DisableDeathSpectator=true # Uncomment to disable players from becoming spectators when they die

# ARK server options - i.e. for -optname=val, use arkopt_optname=val
#arkopt_StructureDestructionTag=DestroySwampSnowStructures

# config Service
servicename="arkserv" # Name of the service (don't change if you don't know what are you doing)
logdir="/ark/log/" # Logs path (default /var/log/arktools)

# steamdb specific
appid=376030 # Linux server App ID
mod_appid=346110 # App ID for mods

# Need to be true to work with UPDATEPONSTART (See #10)
arkAutoUpdateOnStart="true" # set this to true if you want to always update before startup

defaultinstance="main"
configfile_main="/ark/config/arkmanager.cfg"

# We don't use the dots because it doesn't show.
progressDisplayType=spinner
2 changes: 2 additions & 0 deletions arkmanager/instance.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Config root directory
arkserverroot="/ark/server"
6 changes: 6 additions & 0 deletions log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

while true; do
sleep 1
arkmanager rconcmd GetChat 2>/dev/null | sed '/^Running command.*$/d' | tr -d '"' | sed '/^\s*$/d' | sed '/^Command processed.*$/d' | sed '/^Error connecting to server.*$/d'
done
108 changes: 108 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env bash

echo "###########################################################################"
echo "# Ark Server - " `date`
echo "###########################################################################"



echo "Ensuring correct permissions..."
sudo chown steam:steam -R /ark

# Remove arkmanager tracking files if they exist
# They can cause issues with starting the server multiple times
# due to the restart command not completing when the container exits
echo "Cleaning up any leftover arkmanager files..."
[ -f /ark/server/ShooterGame/Saved/.ark-warn-main.lock ] && rm -rf /ark/server/ShooterGame/Saved/.ark-warn-main.lock
[ -f /ark/server/ShooterGame/Saved/.ark-update.lock ] && rm -rf /ark/server/ShooterGame/Saved/.ark-update.lock
[ -f /ark/server/ShooterGame/Saved/.ark-update.time ] && rm -rf /ark/server/ShooterGame/Saved/.ark-update.time
[ -f /ark/server/ShooterGame/Saved/.arkmanager-main.pid ] && rm -rf /ark/server/ShooterGame/Saved/.arkmanager-main.pid
[ -f /ark/server/ShooterGame/Saved/.arkserver-main.pid ] && rm -rf /ark/server/ShooterGame/Saved/.arkserver-main.pid
[ -f /ark/server/ShooterGame/Saved/.autorestart ] && rm -rf /ark/server/ShooterGame/Saved/.autorestart
[ -f /ark/server/ShooterGame/Saved/.autorestart-main ] && rm -rf /ark/server/ShooterGame/Saved/.autorestart-main

# Create directories if they don't exist
[ ! -d /ark/config ] && mkdir /ark/config
[ ! -d /ark/log ] && mkdir /ark/log
[ ! -d /ark/backup ] && mkdir /ark/backup
[ ! -d /ark/staging ] && mkdir /ark/staging

echo "Creating arkmanager.cfg from environment variables..."
echo -e "# Ark Server Tools - arkmanager config\n# Generated from container environment variables\n\n" > /ark/config/arkmanager.cfg
if [ -f /ark/config/arkmanager_base.cfg ]; then
cat /ark/config/arkmanager_base.cfg >> /ark/config/arkmanager.cfg
fi

echo -e "\n\narkserverroot=\"/ark/server\"\n" >> /ark/config/arkmanager.cfg
printenv | sed -n -r 's/am_(.*)=(.*)/\1=\"\2\"/ip' >> /ark/config/arkmanager.cfg

if [ ! -d /ark/server ] || [ ! -f /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer ]; then
echo "No game files found. Installing..."
mkdir -p /ark/server/ShooterGame/Saved/SavedArks
mkdir -p /ark/server/ShooterGame/Saved/Config/LinuxServer
mkdir -p /ark/server/ShooterGame/Content/Mods
mkdir -p /ark/server/ShooterGame/Binaries/Linux/
fi

if [ ! -f /ark/config/crontab ]; then
echo "Creating crontab..."
cat << EOF >> /ark/config/crontab
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
# Examples for Ark:
# 0 * * * * arkmanager update # update every hour
# */15 * * * * arkmanager backup # backup every 15min
# 0 0 * * * arkmanager backup # backup every day at midnight
*/30 * * * * arkmanager update --update-mods --warn --saveworld
10 */8 * * * arkmanager saveworld && arkmanager backup
15 10 * * * arkmanager restart --warn --saveworld
EOF
fi

# If there is uncommented line in the file
CRONNUMBER=`grep -v "^#" /ark/config/crontab | wc -l`
if [ $CRONNUMBER -gt 0 ]; then
echo "Starting cron service..."
sudo service cron start

echo "Loading crontab..."
# We load the crontab file if it exist.
crontab /ark/config/crontab
else
echo "No crontab set."
fi

# Create symlinks for configs
[ -f /ark/config/AllowedCheaterSteamIDs.txt ] && ln -sf /ark/config/AllowedCheaterSteamIDs.txt /ark/server/ShooterGame/Saved/AllowedCheaterSteamIDs.txt
[ -f /ark/config/Game.ini ] && ln -sf /ark/config/Game.ini /ark/server/ShooterGame/Saved/Config/LinuxServer/Game.ini
[ -f /ark/config/GameUserSettings.ini ] && ln -sf /ark/config/GameUserSettings.ini /ark/server/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini

echo "Backing up on start..."
arkmanager backup

function stop {

arkmanager stop
exit 0
}

# Stop server in case of signal INT or TERM
trap stop INT
trap stop TERM

# TODO: Provide IF statement here with ENV variable
# to allow server logs to be scraped from RCON to stdout
# bash -c ./log.sh &

arkmanager start --no-background --verbose &
arkmanpid=$!
wait $arkmanpid

0 comments on commit 7169aaf

Please sign in to comment.