diff --git a/Dockerfile b/Dockerfile index 18d846b..e73fcce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:14.04 +FROM ubuntu:16.04 MAINTAINER TuRzAm @@ -17,20 +17,24 @@ ENV NBPLAYERS 70 ENV UPDATEONSTART 1 # if the server is backup when start with docker start ENV BACKUPONSTART 1 -# Nb minute between auto update (warm) (-1 : no auto update) -ENV AUTOUPDATE -1 -# Nb minute between auto backup (-1 : no auto backup) -ENV AUTOBACKUP -1 -# branch on github for ark server tools -ENV BRANCH master +# Tag on github for ark server tools +ENV GIT_TAG v1.6.56 # Server PORT (you can't remap with docker, it doesn't work) ENV SERVERPORT 27015 # Steam port (you can't remap with docker, it doesn't work) ENV STEAMPORT 7778 +# if the server should backup after stopping +ENV BACKUPONSTOP 0 +# If the server warn the players before stopping +ENV WARNONSTOP 0 +# UID of the user steam +ENV UID 1000 +# GID of the user steam +ENV GID 1000 # Install dependencies RUN apt-get update &&\ - apt-get install -y curl lib32gcc1 lsof git + apt-get install -y curl lib32gcc1 lsof git sudo # Enable passwordless sudo for users under the "sudo" group RUN sed -i.bkp -e \ @@ -48,28 +52,37 @@ RUN usermod -a -G sudo steam # Copy & rights to folders COPY run.sh /home/steam/run.sh +COPY user.sh /home/steam/user.sh +COPY crontab /home/steam/crontab COPY arkmanager-user.cfg /home/steam/arkmanager.cfg +RUN touch /root/.bash_profile RUN chmod 777 /home/steam/run.sh +RUN chmod 777 /home/steam/user.sh RUN mkdir /ark # We use the git method, because api github has a limit ;) -RUN git clone -b $BRANCH https://github.com/FezVrasta/ark-server-tools.git /home/steam/ark-server-tools +RUN git clone https://github.com/FezVrasta/ark-server-tools.git /home/steam/ark-server-tools +WORKDIR /home/steam/ark-server-tools/ +RUN git checkout $GIT_TAG # Install WORKDIR /home/steam/ark-server-tools/tools RUN chmod +x install.sh RUN ./install.sh steam -# Define default config file in /ark +# Allow crontab to call arkmanager +RUN ln -s /usr/local/bin/arkmanager /usr/bin/arkmanager + +# Define default config file in /etc/arkmanager COPY arkmanager-system.cfg /etc/arkmanager/arkmanager.cfg +# Define default config file in /etc/arkmanager +COPY instance.cfg /etc/arkmanager/instances/main.cfg RUN chown steam -R /ark && chmod 755 -R /ark - - -USER steam +#USER steam # download steamcmd RUN mkdir /home/steam/steamcmd &&\ @@ -78,13 +91,17 @@ RUN mkdir /home/steam/steamcmd &&\ # First run is on anonymous to download the app -RUN /home/steam/steamcmd/steamcmd.sh +login anonymous +quit - - +# We can't download from docker hub anymore -_- +#RUN /home/steam/steamcmd/steamcmd.sh +login anonymous +quit EXPOSE ${STEAMPORT} 32330 ${SERVERPORT} +# Add UDP +EXPOSE ${STEAMPORT}/udp ${SERVERPORT}/udp VOLUME /ark +# Change the working directory to /arkd +WORKDIR /ark + # Update game launch the game. -ENTRYPOINT ["/home/steam/run.sh"] +ENTRYPOINT ["/home/steam/user.sh"] diff --git a/README.md b/README.md index 04e6377..79dc045 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,15 @@ Docker build for managing an ARK: Survival Evolved server. This image uses [Ark Server Tools](https://github.com/FezVrasta/ark-server-tools) to manage an ark server. -*If you use an old volume, delete arkmanager.cfg to get the new configuration file.* -__Don't forger to use `docker pull turzam/ark` to get the latest version of the image__ +*If you use an old volume, get the new arkmanager.cfg in the template directory.* +__Don't forget to use `docker pull turzam/ark` to get the latest version of the image__ ## Features - Easy install (no steamcmd / lib32... to install) - - Use Ark Server Tools : update/install/start/backup/rcon - - Auto update (on start or on timer) - - Auto backup (on start or on timer) + - Use Ark Server Tools : update/install/start/backup/rcon/mods + - Easy crontab configuration + - Easy access to ark config file - Mods handling (via Ark Server Tools) - `Docker stop` is a clean stop @@ -22,14 +22,11 @@ Fast & Easy server setup : You can map the ark volume to access config files : `docker run -d -p 7778:7778 -p 7778:7778/udp -p 27015:27015 -p 27015:27015/udp -e SESSIONNAME=myserver -v /my/path/to/ark:/ark --name ark turzam/ark` -Then you can edit */my/path/to/ark/arkcmanager.cfg* (the values override GameUserSetting.ini) and */my/path/to/ark/server/ShooterGame/Saved/Config/LinuxServer/[GameUserSetting.ini/Game.ini]* +Then you can edit */my/path/to/ark/arkmanager.cfg* (the values override GameUserSetting.ini) and */my/path/to/ark/[GameUserSetting.ini/Game.ini]* You can manager your server with rcon if you map the rcon port (you can rebind the rcon port with docker): `docker run -d -p 7778:7778 -p 7778:7778/udp -p 27015:27015 -p 27015:27015/udp -p 32330:32330 -e SESSIONNAME=myserver --name ark turzam/ark` -You can define a server that updates itself every 2 hours (with 1 hour warning) and backups itself every hours: -`docker run -d -p 7778:7778 -p 7778:7778/udp -p 27015:27015 -p 27015:27015/udp -e SESSIONNAME=myserver -e AUTOBACKUP=60 -e AUTOUPDATE=120 -e WARNMINUTE=60 --name ark turzam/ark` - You can change server and steam port to allow multiple servers on same host: *(You can't just rebind the port with docker. It won't work, you need to change STEAMPORT & SERVERPORT variable)* `docker run -d -p 7779:7779 -p 7779:7779/udp -p 27016:27016 -p 27016:27016/udp -p 32331:32330 -e SESSIONNAME=myserver2 -e SERVERPORT=27016 -e STEAMPORT=7779 --name ark2 turzam/ark` @@ -37,6 +34,9 @@ You can change server and steam port to allow multiple servers on same host: You can check your server with : `docker exec ark arkmanager status` +You can manually update your mods: +`docker exec ark arkmanager update --update-mods` + You can manually update your server: `docker exec ark arkmanager update --force` @@ -55,13 +55,28 @@ You can use rcon command via docker : __You can check all available command for arkmanager__ [here](https://github.com/FezVrasta/ark-server-tools/blob/master/README.md) +You can easily configure automatic update and backup. +If you edit the file `/my/path/to/ark/crontab` you can add your crontab job. +For example : +`# Update the server every hours` +`0 * * * * arkmanager update --warn --update-mods >> /ark/log/crontab.log 2>&1` +`# Backup the server each day at 00:00 ` +`0 0 * * * arkmanager backup >> /ark/log/crontab.log 2>&1` +*You can check [this website](http://www.unix.com/man-page/linux/5/crontab/) for more information on cron.* + +To add mods, you only need to change the variable ark_GameModIds in *arkmanager.cfg* with a list of your modIds (like this `ark_GameModIds="987654321,1234568"`). If UPDATEONSTART is enable, just restart your docker or use `docker exec ark arkmanager update --update-mods`. + --- ## Recommended Usage - First run `docker run -it -p 7778:7778 -p 7778:7778/udp -p 27015:27015 -p 27015:27015/udp -p 32330:32330 -e SESSIONNAME=myserver -e ADMINPASSWORD="mypasswordadmin" -e AUTOUPDATE=120 -e AUTOBACKUP=60 -e WARNMINUTE=30 -v /my/path/to/ark:/ark --name ark turzam/ark` - Wait for ark to be downloaded installed and launched, then Ctrl+C to stop the server. -- Modify */my/path/to/ark/server/ShooterGame/Saved/Config/LinuxServer/GameUserSetting.ini and Game.ini* +- Edit */my/path/to/ark/GameUserSetting.ini and Game.ini* +- Edit */my/path/to/ark/arkserver.cfg* to add mods and configure warning time. +- Add auto update every day and autobackup by editing */my/path/to/ark/crontab* with this lines : +`0 0 * * * arkmanager update --warn --update-mods >> /ark/log/crontab.log 2>&1` +`0 0 * * * arkmanager backup >> /ark/log/crontab.log 2>&1` - `docker start ark` - Check your server with : `docker exec ark arkmanager status` @@ -84,14 +99,17 @@ Steam server port (can't rebind with docker, it doesn't work) (default : 7778) + __BACKUPONSTART__ 1 : Backup the server when the container is started. 0: no backup (default : 1) + __UPDATEPONSTART__ -1 : Update the server when the container is started. 0: no update (default : 1) -+ __AUTOUPDATE__ -Number of minute between each check for une newer version (-1 disable auto update) (default : -1) -Auto update is set to --warn and warn the players 30 minutes before update (default, can be changed in /ark/arkmanager.cfg). -+ __AUTOBACKUP__ -Number of minute between each backup (-1 disable auto backup) (default : -1) -+ __WARNMINUTE__ -Number of minute to warn the players when auto-update (default : 30) +1 : Update the server when the container is started. 0: no update (default : 1) ++ __BACKUPONSTOP__ +1 : Backup the server when the container is stopped. 0: no backup (default : 0) ++ __WARNONSTOP__ +1 : Warn the players before the container is stopped. 0: no warning (default : 0) ++ __TZ__ +Time Zone : Set the container timezone (for crontab). (You can get your timezone posix format with the command `tzselect`. For example, France is "Europe/Paris"). ++ __UID__ +UID of the user used. Owner of the volume /ark ++ __GID__ +GID of the user used. Owner of the volume /ark --- @@ -101,7 +119,14 @@ Number of minute to warn the players when auto-update (default : 30) + /ark/server : Server files and data. + /ark/log : logs + /ark/backup : backups - + /ark/arkmanager.cfg : config file + + /ark/arkmanager.cfg : config file for Ark Server Tools + + /ark/crontab : crontab config file + + /ark/Game.ini : ark game.ini config file + + /ark/GameUserSetting.ini : ark gameusersetting.ini config file + + /ark/template : Default config files + + /ark/template/arkmanager.cfg : default config file for Ark Server Tools + + /ark/template/crontab : default config file for crontab + + /ark/staging : default directory if you use the --downloadonly option when updating. --- @@ -123,4 +148,20 @@ Number of minute to warn the players when auto-update (default : 30) + 1.1 : - Works with Ark Server Tools 1.4 [See changelog here](https://github.com/FezVrasta/ark-server-tools/releases/tag/v1.4) - Handle mods && auto update mods ++ 1.2 : + - Remove variable AUTOBACKUP & AUTOUPDATE + - Remove variable WARNMINUTE (can now be find in arkmanager.cfg) + - Add crontab support + - You can now config crontab with the file /your/ark/path/crontab + - Add template directory with default config files. + - Add documentation on TZ variable. ++ 1.3 : + - Add BACKUPONSTOP to backup the server when you stop the server (thanks to [fkoester](https://github.com/fkoester)) + - Add WARNONSTOP to add warning message when you stop the server (default: 60 min) + - Works with Ark Server Tools v1.5 + - Compressing backups so they take up less space + - Downloading updates to a staging directory before applying + - Added support for automatically updating on restart + - Show a spinner when updating + - Add UID & GID to set the uid & gid of the user used in the container (and permissions on the volume /ark) diff --git a/arkmanager-system.cfg b/arkmanager-system.cfg index b4f4480..b15199a 100644 --- a/arkmanager-system.cfg +++ b/arkmanager-system.cfg @@ -16,8 +16,8 @@ steamcmd_appinfocache="/home/steam/Steam/appcache/appinfo.vdf" # cache of t 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="30" # number of minutes to warn players when using update --warn arkautorestartfile="ShooterGame/Saved/.autorestart" # path to autorestart file +arkStagingDir="/ark/staging" # config Service servicename="arkserv" # Name of the service (don't change if you don't know what are you doing) @@ -31,5 +31,14 @@ ark_RCONPort="32330" # RCON Port # 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" + +# We don't use the dots because it doesn't show. +progressDisplayType=spinner source /ark/arkmanager.cfg diff --git a/arkmanager-user.cfg b/arkmanager-user.cfg index e82ca30..f5d3ff2 100644 --- a/arkmanager-user.cfg +++ b/arkmanager-user.cfg @@ -3,6 +3,8 @@ # comment out these values if you want to define them # inside your GameUserSettings.ini file serverMap=${SERVERMAP} # 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_SessionName=${SESSIONNAME} # if your session name needs special characters please use the .ini instead ark_ServerPassword=${SERVERPASSWORD} # ARK server password, empty: no password required to login ark_ServerAdminPassword=${ADMINPASSWORD} # ARK server admin password, KEEP IT SAFE! @@ -26,9 +28,22 @@ mod_branch=Windows # ARK server options - i.e. for -optname=val, use arkopt_optname=val #arkopt_StructureDestructionTag=DestroySwampSnowStructures +#ark_AltSaveDirectoryName="SotF" # Uncomment to specify a different save directory name # 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" + +# config environment +arkwarnminutes="60" # number of minutes to warn players when using update --warn arkBackupPreUpdate="false" # set this to true if you want to perform a backup before updating + +# Options to automatically remove old backups to keep backup size in check +# Each compressed backup is generally about 1-2MB in size. +arkMaxBackupSizeMB="500" # Set to automatically remove old backups when size exceeds this limit +#arkMaxBackupSizeGB="2" # Uncomment this and comment the above to specify the limit in whole GB diff --git a/crontab b/crontab new file mode 100644 index 0000000..91e388f --- /dev/null +++ b/crontab @@ -0,0 +1,16 @@ +# 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 command to be executed +# Example : update every hour +# 0 * * * * arkmanager update +# Example : backup every 15min +# */15 * * * * arkmanager backup +# Example : backup every day at midnight +# 0 0 * * * arkmanager backup +# WARNING : the container timezone is maybe not your current timezone +# You can sync them with option -v /etc/localtime:/etc/localtime:ro or -e "TZ=UTC" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..71126e9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +ark: + container_name: ark + image: turzam/ark + environment: + - SESSIONNAME=Ark Docker + - SERVERMAP=TheIsland + - SERVERPASSWORD="" + - ADMINPASSWORD=adminpassword + - BACKUPONSTART=1 + - UPDATEONSTART=1 + - TZ=Europe/Paris + - GID=1000 + - UID=1000 + volumes: + - /my/path/to/ark:/ark + ports: + - 7778:7778/udp + - 7778:7778 + - 27015:27015/udp + - 27015:27015 + - 32330:32330 diff --git a/instance.cfg b/instance.cfg new file mode 100644 index 0000000..1585d84 --- /dev/null +++ b/instance.cfg @@ -0,0 +1,2 @@ +# Config root directory +arkserverroot="/ark/server" diff --git a/run.sh b/run.sh index 382d994..80fff6b 100644 --- a/run.sh +++ b/run.sh @@ -1,56 +1,88 @@ #!/usr/bin/env bash echo "###########################################################################" echo "# Ark Server - " `date` +echo "# UID $UID - GID $GID" echo "###########################################################################" [ -p /tmp/FIFO ] && rm /tmp/FIFO mkfifo /tmp/FIFO export TERM=linux +function stop { + if [ ${BACKUPONSTOP} -eq 1 ] && [ "$(ls -A server/ShooterGame/Saved/SavedArks)" ]; then + echo "[Backup on stop]" + arkmanager backup + fi + if [ ${WARNONSTOP} -eq 1 ];then + arkmanager stop --warn + else + arkmanager stop + fi + exit +} + + + +# Change working directory to /ark to allow relative path +cd /ark + +# Add a template directory to store the last version of config file +[ ! -d /ark/template ] && mkdir /ark/template +# We overwrite the template file each time +cp /home/steam/arkmanager.cfg /ark/template/arkmanager.cfg +cp /home/steam/crontab /ark/template/crontab +# Creating directory tree && symbolic link [ ! -f /ark/arkmanager.cfg ] && cp /home/steam/arkmanager.cfg /ark/arkmanager.cfg [ ! -d /ark/log ] && mkdir /ark/log [ ! -d /ark/backup ] && mkdir /ark/backup - -#echo "Upgrade Ark server tools..." -#arkmanager upgrade-tools +[ ! -d /ark/staging ] && mkdir /ark/staging +[ ! -L /ark/Game.ini ] && ln -s server/ShooterGame/Saved/Config/LinuxServer/Game.ini Game.ini +[ ! -L /ark/GameUserSettings.ini ] && ln -s server/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini GameUserSettings.ini +[ ! -f /ark/crontab ] && cp /ark/template/crontab /ark/crontab -if [ ! -d "/ark/server" ] && [ ! -f "/ark/server/arkversion" ];then - echo "Install ark..." + +if [ ! -d /ark/server ] || [ ! -f /ark/server/version.txt ];then + echo "No game files found. Installing..." + mkdir -p /ark/server/ShooterGame/Saved/SavedArks + mkdir -p /ark/server/ShooterGame/Content/Mods + mkdir -p /ark/server/ShooterGame/Binaries/Linux/ + touch /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer arkmanager install # Create mod dir - mkdir /ark/server/ShooterGame/Content/Mods else - if [ ${BACKUPONSTART} -eq 1 ]; then + if [ ${BACKUPONSTART} -eq 1 ] && [ "$(ls -A server/ShooterGame/Saved/SavedArks/)" ]; then echo "[Backup]" arkmanager backup fi +fi - if [ ${UPDATEONSTART} -eq 1 ]; then - echo "[Update]" - arkmanager update --update-mods - fi + +# If there is uncommented line in the file +CRONNUMBER=`grep -v "^#" /ark/crontab | wc -l` +if [ $CRONNUMBER -gt 0 ]; then + echo "Loading crontab..." + # We load the crontab file if it exist. + crontab /ark/crontab + # Cron is attached to this process + sudo cron -f & +else + echo "No crontab set." fi # Launching ark server -arkmanager start +if [ $UPDATEONSTART -eq 0 ]; then + arkmanager start -noautoupdate +else + arkmanager start +fi # Stop server in case of signal INT or TERM echo "Waiting..." -trap 'arkmanager stop' INT -trap 'arkmanager stop' TERM - -# Auto update every $AUTOUPDATE minutes -if [ $AUTOUPDATE -gt 0 ]; then - while :; do sleep $(($AUTOUPDATE * 60)); echo "[`date +'%y/%m/%d %H:%M'`] [Auto-Update]"; arkmanager update --warn --update-mods --backup ; done & -fi - -# Auto backup every $AUTOBACKUP minutes -if [ $AUTOBACKUP -gt 0 ]; then - while :; do sleep $(($AUTOBACKUP * 60)); echo "[`date +'%Y/%m/%d %H:%M'`] [Auto-Backup]"; arkmanager backup ; done & -fi +trap stop INT +trap stop TERM read < /tmp/FIFO & wait diff --git a/user.sh b/user.sh new file mode 100644 index 0000000..a49bdfc --- /dev/null +++ b/user.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Change the UID if needed +if [ ! "$(id -u steam)" -eq "$UID" ]; then + echo "Changing steam uid to $UID." + usermod -o -u "$UID" steam ; +fi +# Change gid if needed +if [ ! "$(id -g steam)" -eq "$GID" ]; then + echo "Changing steam gid to $GID." + groupmod -o -g "$GID" steam ; +fi + +# Put steam owner of directories (if the uid changed, then it's needed) +chown -R steam:steam /ark /home/steam + +# avoid error message when su -p (we need to read the /root/.bash_rc ) +chmod -R 777 /root/ + +# Launch run.sh with user steam (-p allow to keep env variables) +su -p - steam -c /home/steam/run.sh