From 838b0faa06a6471e3c30da8eadf5bbdf53ee05da Mon Sep 17 00:00:00 2001 From: Eric Fossum Date: Thu, 2 Mar 2023 11:16:47 -0800 Subject: [PATCH 1/7] First attempt at creating a user space script. --- .vscode/settings.json | 8 ++- Dockerfile | 4 +- run.sh | 114 ++++++++++++++++++------------------------ user-space.sh | 36 +++++++++++++ 4 files changed, 96 insertions(+), 66 deletions(-) create mode 100644 user-space.sh diff --git a/.vscode/settings.json b/.vscode/settings.json index bfba6c1..a8f8f6e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,11 @@ { "cSpell.words": [ "arkmanager" - ] + ], + "gitlens.autolinks": [ + { + "prefix": "#", + "url": "https://github.com/fossum/ark-cluster/issues/" + } + ], } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index fff6b11..3cfe061 100644 --- a/Dockerfile +++ b/Dockerfile @@ -63,9 +63,11 @@ RUN mkdir -p /ark \ COPY crontab /home/steam/crontab -# Setup run script +# Add run and user scripts COPY run.sh /run.sh RUN chmod +x /run.sh +COPY user-space.sh /user-space.sh +RUN chmod +x /user-space.sh # Skip expose, not all servers will use the same ports. VOLUME /ark /cluster diff --git a/run.sh b/run.sh index 8e5ee9d..e0b6140 100644 --- a/run.sh +++ b/run.sh @@ -3,20 +3,8 @@ function log { echo "`date +\"%Y-%m-%dT%H:%M:%SZ\"`: $@"; } function warn { >&2 echo "`date +\"%Y-%m-%dT%H:%M:%SZ\"`: $@"; } -log "###########################################################################" -log "# Started - `date`" -log "# Server - ${SESSION_NAME} (${SERVERMAP})" -log "# Cluster - ${CLUSTER_ID}" -log "# User - ${USER_ID}" -log "# Group - ${GROUP_ID}" -log "###########################################################################" -[ -p /tmp/FIFO ] && rm /tmp/FIFO -mkfifo /tmp/FIFO - -export TERM=linux - function error { - log "$1" + log "!!! $1" exit 1 } @@ -30,40 +18,64 @@ function stop { else arkmanager stop fi - exit + exit 0 } function verify_dir { + # Must be used after steam UID/GID set. + local dir="$1" if [ ! -d $dir ]; then mkdir -p $dir || error "Could not create $dir directory." fi + # Put steam owner of directories (if the uid changed, then it's needed) - chown -R steam:steam $dir || error "Could not set $dir permissions." + chown -R steam:steam $dir + #chmod -R 777 $dir || error "Could not set $dir permissions." + + # Verify user owns files. + # Can't use chmod code as some file systems will not allow user change. + owner="$(stat --format '%U' "$dir")" + if [ "${owner}" != "steam" ]; then + error "Could not set owner of $dir" + fi } +log "###########################################################################" +log "# Started - `date`" +log "# Server - ${SESSION_NAME} (${SERVERMAP})" +log "# Cluster - ${CLUSTER_ID}" +log "# User - ${USER_ID}" +log "# Group - ${GROUP_ID}" +log "###########################################################################" + +[ -p /tmp/FIFO ] && rm /tmp/FIFO +mkfifo /tmp/FIFO + +export TERM=linux + ######################## # # System Setup # ######################## +if [ -f /usr/share/zoneinfo/${TZ} ]; then + log "Setting timezone to ${TZ} ..." + ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime +else + warn "Timezone '${TZ}' does not exist!" +fi + # Change the USER_ID if needed if [ ! "$(id -u steam)" -eq "$USER_ID" ]; then log "Changing steam uid to $USER_ID." - usermod -o -u "$USER_ID" steam ; + usermod -o -u "$USER_ID" steam fi # Change gid if needed if [ ! "$(id -g steam)" -eq "$GROUP_ID" ]; then log "Changing steam gid to $GROUP_ID." - groupmod -o -g "$GROUP_ID" steam ; -fi - -if [ -f /usr/share/zoneinfo/${TZ} ]; then - log "Setting timezone to ${TZ} ..." - ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime -else - warn "Timezone '${TZ}' does not exist!" + groupmod -o -g "$GROUP_ID" steam fi ######################## @@ -72,19 +84,22 @@ fi # ######################## -# Add a template directory to store the last version of config file verify_dir /ark verify_dir /ark/backup verify_dir /ark/log +verify_dir /ark/server +# verify_dir /ark/server/ShooterGame/Binaries/Linux +# verify_dir /ark/server/ShooterGame/Content/Mods +# verify_dir /ark/server/ShooterGame/Saved/SavedArks verify_dir /ark/staging verify_dir /ark/template verify_dir /cluster -verify_dir /home/steam verify_dir /etc/arkmanager +verify_dir /home/steam # Create custom config if not set, use custom config -[ ! -f /ark/arkmanager.cfg ] && cp /etc/arkmanager/instances/main.cfg /ark/arkmanager.cfg || warn "Could not save default config file." -cp /ark/arkmanager.cfg /etc/arkmanager/instances/main.cfg || warn "Could not save main instance config file." +[ ! -f /ark/arkmanager.cfg ] && su steam -c "cp /etc/arkmanager/instances/main.cfg /ark/arkmanager.cfg" || warn "Could not save default config file." +su steam -c "cp /ark/arkmanager.cfg /etc/arkmanager/instances/main.cfg" || warn "Could not save main instance config file." ######################## # @@ -107,40 +122,11 @@ if [ ! -f /etc/cron.d/arkbackup ]; then fi log "###########################################################################" -if [ ! -f /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer ] || [ ! -f /ark/server/version.txt ]; then - warn "No game files found. Installing..." - export free_space=$(df -Pk . | sed 1d | grep -v used | awk '{ print $4 }') - [ $free_space -gt 20000000 ] || warn "Only $free_space bytes available. Installation may fail." - verify_dir /ark/server/ShooterGame/Saved/SavedArks - verify_dir /ark/server/ShooterGame/Content/Mods - verify_dir /ark/server/ShooterGame/Binaries/Linux - touch /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer - verify_dir /ark/server - arkmanager install || error "Could not install game files." -else - if [ ${BACKUPONSTART} -eq 1 ] && [ "$(ls -A /ark/server/ShooterGame/Saved/SavedArks/)" ]; then - log "Creating Backup ..." - arkmanager backup || warn "Could not create backup." - fi -fi - -log "###########################################################################" -log "Installing Mods ..." -arkmanager installmods || error "Could not install mods." - -log "###########################################################################" -log "Launching ark server ..." -if [ ${UPDATEONSTART} -eq 1 ]; then - arkmanager start || error "Could not start server." -else - arkmanager start -noautoupdate || error "Could not start server." -fi - -# Stop server in case of signal INT or TERM -log "###########################################################################" -log "Running ... (waiting for INT/TERM signal)" -trap stop INT -trap stop TERM +######################## +# +# Steam User Space +# +######################## -read < /tmp/FIFO & -wait +log "Dropping to steam user." +su steam -c "bash /user-space.sh" diff --git a/user-space.sh b/user-space.sh new file mode 100644 index 0000000..fba6072 --- /dev/null +++ b/user-space.sh @@ -0,0 +1,36 @@ + +# Create custom config if not set, use custom config +[ ! -f /ark/arkmanager.cfg ] && cp /etc/arkmanager/instances/main.cfg /ark/arkmanager.cfg || warn "Could not save default config file." +cp /ark/arkmanager.cfg /etc/arkmanager/instances/main.cfg || warn "Could not save main instance config file." + +if [ ! -f /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer ] || [ ! -f /ark/server/version.txt ]; then + warn "No game files found. Installing..." + # touch /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer + arkmanager install || error "Could not install game files." +else + if [ ${BACKUPONSTART} -eq 1 ] && [ "$(ls -A /ark/server/ShooterGame/Saved/SavedArks/)" ]; then + log "Creating Backup ..." + arkmanager backup || warn "Could not create backup." + fi +fi + +log "###########################################################################" +log "Installing Mods ..." +arkmanager installmods || error "Could not install mods." + +log "###########################################################################" +log "Launching ark server ..." +if [ ${UPDATEONSTART} -eq 1 ]; then + arkmanager start || error "Could not start server." +else + arkmanager start -noautoupdate || error "Could not start server." +fi + +# Stop server in case of signal INT or TERM +log "###########################################################################" +log "Running ... (waiting for INT/TERM signal)" +trap stop INT +trap stop TERM + +read < /tmp/FIFO & +wait From 196b0d1e89848789a993a625c87268dab0f0fb9d Mon Sep 17 00:00:00 2001 From: Eric Fossum Date: Thu, 2 Mar 2023 15:05:48 -0800 Subject: [PATCH 2/7] Move shared functions to importable file. Fix combination boolean logic. --- Dockerfile | 2 ++ run.sh | 12 ++++-------- shared.sh | 8 ++++++++ user-space.sh | 6 ++---- 4 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 shared.sh diff --git a/Dockerfile b/Dockerfile index 3cfe061..6f92f75 100644 --- a/Dockerfile +++ b/Dockerfile @@ -64,6 +64,8 @@ RUN mkdir -p /ark \ COPY crontab /home/steam/crontab # Add run and user scripts +COPY shared.sh /shared.sh +RUN chmod +x /shared.sh COPY run.sh /run.sh RUN chmod +x /run.sh COPY user-space.sh /user-space.sh diff --git a/run.sh b/run.sh index e0b6140..6fc9f84 100644 --- a/run.sh +++ b/run.sh @@ -1,12 +1,6 @@ #!/usr/bin/env bash -function log { echo "`date +\"%Y-%m-%dT%H:%M:%SZ\"`: $@"; } -function warn { >&2 echo "`date +\"%Y-%m-%dT%H:%M:%SZ\"`: $@"; } - -function error { - log "!!! $1" - exit 1 -} +. /shared.sh function stop { if [ ${BACKUPONSTOP} -eq 1 ] && [ "$(ls -A /ark/server/ShooterGame/Saved/SavedArks)" ]; then @@ -98,7 +92,9 @@ verify_dir /etc/arkmanager verify_dir /home/steam # Create custom config if not set, use custom config -[ ! -f /ark/arkmanager.cfg ] && su steam -c "cp /etc/arkmanager/instances/main.cfg /ark/arkmanager.cfg" || warn "Could not save default config file." +if [ ! -f /ark/arkmanager.cfg ]; then + su steam -c "cp /etc/arkmanager/instances/main.cfg /ark/arkmanager.cfg" || warn "Could not save default config file." +fi su steam -c "cp /ark/arkmanager.cfg /etc/arkmanager/instances/main.cfg" || warn "Could not save main instance config file." ######################## diff --git a/shared.sh b/shared.sh new file mode 100644 index 0000000..33d6982 --- /dev/null +++ b/shared.sh @@ -0,0 +1,8 @@ + +function log { echo "`date +\"%Y-%m-%dT%H:%M:%SZ\"`: $@"; } +function warn { >&2 echo "`date +\"%Y-%m-%dT%H:%M:%SZ\"`: $@"; } + +function error { + log "!!! $1" + exit 1 +} diff --git a/user-space.sh b/user-space.sh index fba6072..137cc86 100644 --- a/user-space.sh +++ b/user-space.sh @@ -1,11 +1,9 @@ +#!/usr/bin/env bash -# Create custom config if not set, use custom config -[ ! -f /ark/arkmanager.cfg ] && cp /etc/arkmanager/instances/main.cfg /ark/arkmanager.cfg || warn "Could not save default config file." -cp /ark/arkmanager.cfg /etc/arkmanager/instances/main.cfg || warn "Could not save main instance config file." +. /shared.sh if [ ! -f /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer ] || [ ! -f /ark/server/version.txt ]; then warn "No game files found. Installing..." - # touch /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer arkmanager install || error "Could not install game files." else if [ ${BACKUPONSTART} -eq 1 ] && [ "$(ls -A /ark/server/ShooterGame/Saved/SavedArks/)" ]; then From 17cf57c3f3e40247b9107cfac53642b94f8ed5b5 Mon Sep 17 00:00:00 2001 From: Eric Fossum Date: Thu, 2 Mar 2023 16:21:24 -0800 Subject: [PATCH 3/7] Only set dir owner if needed. --- run.sh | 29 +++++++++++++---------------- user-space.sh | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/run.sh b/run.sh index 6fc9f84..71ab74c 100644 --- a/run.sh +++ b/run.sh @@ -20,17 +20,21 @@ function verify_dir { local dir="$1" if [ ! -d $dir ]; then - mkdir -p $dir || error "Could not create $dir directory." + su -c "mkdir -p $dir" steam || error "Could not create $dir directory." fi # Put steam owner of directories (if the uid changed, then it's needed) - chown -R steam:steam $dir - #chmod -R 777 $dir || error "Could not set $dir permissions." + owner_id="$(stat --format '%u' "$dir")" + group_id="$(stat --format '%g' "$dir")" + if [ "${owner_id}" != "${USER_ID}" ] || [ "${group_id}" != "${GROUP_ID}" ]; then + chown -R $USER_ID:$GROUP_ID $dir + #chmod -R 777 $dir || error "Could not set $dir permissions." + fi # Verify user owns files. # Can't use chmod code as some file systems will not allow user change. - owner="$(stat --format '%U' "$dir")" - if [ "${owner}" != "steam" ]; then + owner_id="$(stat --format '%u' "$dir")" + if [ "${owner_id}" != "${USER_ID}" ]; then error "Could not set owner of $dir" fi } @@ -50,7 +54,7 @@ export TERM=linux ######################## # -# System Setup +log "System Setup" # ######################## @@ -74,7 +78,7 @@ fi ######################## # -# File Setup +log "File Setup" # ######################## @@ -91,15 +95,9 @@ verify_dir /cluster verify_dir /etc/arkmanager verify_dir /home/steam -# Create custom config if not set, use custom config -if [ ! -f /ark/arkmanager.cfg ]; then - su steam -c "cp /etc/arkmanager/instances/main.cfg /ark/arkmanager.cfg" || warn "Could not save default config file." -fi -su steam -c "cp /ark/arkmanager.cfg /etc/arkmanager/instances/main.cfg" || warn "Could not save main instance config file." - ######################## # -# CRON Setup +log "CRON Setup" # ######################## @@ -120,9 +118,8 @@ log "########################################################################### ######################## # -# Steam User Space +log "Dropping to steam User Space" # ######################## -log "Dropping to steam user." su steam -c "bash /user-space.sh" diff --git a/user-space.sh b/user-space.sh index 137cc86..6ad41d8 100644 --- a/user-space.sh +++ b/user-space.sh @@ -2,6 +2,21 @@ . /shared.sh +function verify_dir { + # This user space version does not set permissions. + + local dir="$1" + if [ ! -d $dir ]; then + mkdir -p $dir || error "Could not create $dir directory." + fi +} + +# Create custom config if not set, use custom config +if [ ! -f /ark/arkmanager.cfg ]; then + cp /etc/arkmanager/instances/main.cfg /ark/arkmanager.cfg || warn "Could not save default config file." +fi +cp /ark/arkmanager.cfg /etc/arkmanager/instances/main.cfg || warn "Could not save main instance config file." + if [ ! -f /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer ] || [ ! -f /ark/server/version.txt ]; then warn "No game files found. Installing..." arkmanager install || error "Could not install game files." From 3e0b3ec7b84fc79b33d48b3d694dbcc0b4d2a327 Mon Sep 17 00:00:00 2001 From: Eric Fossum Date: Thu, 2 Mar 2023 17:18:41 -0800 Subject: [PATCH 4/7] Allow different file owner if has perms. --- .gitignore | 1 + run.sh | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index cec92f6..ba17baf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff: +.env .idea/**/workspace.xml .idea/**/tasks.xml .idea/dictionaries diff --git a/run.sh b/run.sh index 71ab74c..6c30d65 100644 --- a/run.sh +++ b/run.sh @@ -31,11 +31,13 @@ function verify_dir { #chmod -R 777 $dir || error "Could not set $dir permissions." fi - # Verify user owns files. - # Can't use chmod code as some file systems will not allow user change. + # Verify user can modify files. + # Some file systems may not show user change. owner_id="$(stat --format '%u' "$dir")" if [ "${owner_id}" != "${USER_ID}" ]; then - error "Could not set owner of $dir" + su -c "touch '$dir/test_file'" steam || error "Could get permission for $dir" + su -c "rm '$dir/test_file'" steam || error "Could get permission for $dir" + log "$dir is not owned by steam user, but is writable." fi } From 189c1f030cc65a77b27166fd824fc74600ef3df8 Mon Sep 17 00:00:00 2001 From: Eric Fossum Date: Thu, 2 Mar 2023 23:18:51 -0800 Subject: [PATCH 5/7] Putting TZ file in quotes. --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 6c30d65..775b563 100644 --- a/run.sh +++ b/run.sh @@ -62,7 +62,7 @@ log "System Setup" if [ -f /usr/share/zoneinfo/${TZ} ]; then log "Setting timezone to ${TZ} ..." - ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime + ln -sf "/usr/share/zoneinfo/${TZ}" /etc/localtime else warn "Timezone '${TZ}' does not exist!" fi From 34f18eab3a6dc85ced8058d7185bca6c6118fe87 Mon Sep 17 00:00:00 2001 From: Eric Fossum Date: Thu, 2 Mar 2023 23:19:27 -0800 Subject: [PATCH 6/7] Update tasks to docker dev image --- .vscode/tasks.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index a122c07..d07a722 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,7 +6,7 @@ { "label": "Build Image", "type": "shell", - "command": "docker build -t ark-cluster .", + "command": "docker build -t fossum/ark-cluster:dev .", "problemMatcher": [], "group": { "kind": "build", @@ -16,7 +16,13 @@ { "label": "Run Image", "type": "shell", - "command": "docker stop ark; docker rm ark; docker run -v ${pwd}/ark:/ark -p 7777:7777/udp -p 7778:7778/udp -p 32330:32330 -p 27015:27015/udp -e SESSIONNAME=myserver -e ADMINPASSWORD=\"mypasswordadmin\" --name ark ark-cluster" + "command": "docker stop ark; docker rm ark; docker run -v ${pwd}/ark:/ark -p 7777:7777/udp -p 7778:7778/udp -p 32330:32330 -p 27015:27015/udp -e SESSIONNAME=myserver -e ADMINPASSWORD=\"mypasswordadmin\" --name ark fossum/ark-cluster:dev" + }, + { + "label": "Push Dev Image", + "type": "shell", + "command": "docker push fossum/ark-cluster:dev", + "problemMatcher": [] } ] } \ No newline at end of file From b4e8220ebf1301921a09638d31efe6a01bedce43 Mon Sep 17 00:00:00 2001 From: Eric Fossum Date: Fri, 3 Mar 2023 16:16:47 -0800 Subject: [PATCH 7/7] Allow restore before start. Bash autocomplete Misc MAIL --- .vscode/settings.json | 9 ++- Dockerfile | 6 +- README.md | 24 +++---- arkmanager-completion.bash | 3 + arkmanager-user.cfg | 6 +- docker-compose.yml | 20 ++++-- personal-stack.yml | 144 +++++++++++++++++++++++++++++++++++++ run.sh | 11 ++- user-space.sh | 12 +++- 9 files changed, 207 insertions(+), 28 deletions(-) create mode 100644 arkmanager-completion.bash create mode 100644 personal-stack.yml diff --git a/.vscode/settings.json b/.vscode/settings.json index a8f8f6e..34b4c21 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,13 @@ { "cSpell.words": [ - "arkmanager" + "arkmanager", + "BATTLEYE", + "cifs", + "CROSSPLAY", + "fjordur", + "healthcheck", + "RCON", + "theisland" ], "gitlens.autolinks": [ { diff --git a/Dockerfile b/Dockerfile index 6f92f75..3b98945 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ ENV CRON_AUTO_UPDATE="0 */3 * * *" \ GROUP_ID=1000 \ TZ=UTC \ MAX_BACKUP_SIZE=500 \ - SERVERMAP="TheIsland" \ + SERVER_MAP="TheIsland" \ SESSION_NAME="ARK Cluster" \ MAX_PLAYERS=20 \ RCON_ENABLE="True" \ @@ -36,7 +36,8 @@ ENV CRON_AUTO_UPDATE="0 */3 * * *" \ CLUSTER_ID="" \ KILL_PROCESS_TIMEOUT=300 \ KILL_ALL_PROCESSES_TIMEOUT=300 \ - TOOLS_GIT_REF="" + TOOLS_GIT_REF="" \ + ARK_SERVER_VOLUME="/ark" # Install Ark Server Tools # Get tag version or master. @@ -70,6 +71,7 @@ COPY run.sh /run.sh RUN chmod +x /run.sh COPY user-space.sh /user-space.sh RUN chmod +x /user-space.sh +COPY arkmanager-completion.bash /etc/bash_completion.d/arkmanager-completion.bash # Skip expose, not all servers will use the same ports. VOLUME /ark /cluster diff --git a/README.md b/README.md index e82f6c9..751ce9b 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ For example : After updating the `/my/path/to/ark/crontab` please run the command `docker exec ark crontab -u steam /ark/crontab` -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`. +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 UPDATE_ON_START is enabled, just restart your docker or use `docker exec ark arkmanager update --update-mods`. ## Recommended Usages @@ -109,19 +109,19 @@ To add mods, you only need to change the variable ark_GameModIds in *arkmanager. ## Variables - __SESSIONNAME__: Name of your ark server (default: "Ark Docker") -- __SERVERMAP__: Map of your ark server (default: "TheIsland") -- __SERVERPASSWORD__: Password of your ark server (default: "") -- __ADMINPASSWORD__: Admin password of your ark server (default: "adminpassword") -- __SERVERPORT__: Ark server port (can't rebind with docker, it doesn't work) (default: 27015) -- __STEAMPORT__: Steam server port (can't rebind with docker, it doesn't work) (default: 7778) +- __SERVER_MAP__: Map of your ark server (default: "TheIsland") +- __SERVER_PASSWORD__: Password of your ark server (default: "") +- __ADMIN_PASSWORD__: Admin password of your ark server (default: "adminpassword") +- __SERVER_PORT__: Ark server port (can't rebind with docker, it doesn't work) (default: 27015) +- __STEAM_PORT__: Steam server port (can't rebind with docker, it doesn't work) (default: 7778) - __MAX_PLAYERS__: Number of maximum players (default: 70) -- __BACKUPONSTART__: Backup the server when the container is started. 0: no backup (default: 1) -- __UPDATEPONSTART__: Update the server when the container is started. 0: no update (default: 1) -- __BACKUPONSTOP__: Backup the server when the container is stopped. 0: no backup (default: 1) -- __WARNONSTOP__: Warn the players before the container is stopped. 0: no warning (default: 1) +- __BACKUP_ON_START__: Backup the server when the container is started. 0: no backup (default: 1) +- __UPDATE_ON_START__: Update the server when the container is started. 0: no update (default: 1) +- __BACKUP_ON_STOP__: Backup the server when the container is stopped. 0: no backup (default: 1) +- __WARN_ON_STOP__: Warn the players before the container is stopped. 0: no warning (default: 1) - __TZ__: container timezone (for crontab). (default: "UTC"). -- __UID__: UID of the user used. Owner of the volume /ark (default: 1000) -- __GID__: GID of the user used. Owner of the volume /ark (default: 1000) +- __USER_ID__: UID of the user used. Owner of the volume /ark (default: 1000) +- __GROUP_ID__: GID of the user used. Owner of the volume /ark (default: 1000) ## Volumes diff --git a/arkmanager-completion.bash b/arkmanager-completion.bash new file mode 100644 index 0000000..b398e2f --- /dev/null +++ b/arkmanager-completion.bash @@ -0,0 +1,3 @@ +#/usr/bin/env bash + +complete -W "upgrade-tools uninstall-tools useconfig remove-mods list-instances Command backup restore broadcast saveworld rconcmd checkupdate checkmodupdate install installmod uninstallmod reinstallmod enablemod disablemod installmods uninstallmods install-cronjob remove-cronjob restart run start stop cancelshutdown status printconfig getpid update" arkmanager diff --git a/arkmanager-user.cfg b/arkmanager-user.cfg index b03f9cf..7dd6548 100644 --- a/arkmanager-user.cfg +++ b/arkmanager-user.cfg @@ -1,13 +1,13 @@ # ARK server options - use ark_= # comment out these values if you want to define them # inside your GameUserSettings.ini file -serverMap="${SERVERMAP:=TheIsland}" # server map (default TheIsland) +serverMap="${SERVER_MAP:=TheIsland}" # server map (default TheIsland) #serverMapModId="469987622" # Uncomment this to specify the Map Mod Id ( in http://steamcommunity.com/sharedfiles/filedetails/?id=) #ark_TotalConversionMod="496735411" # Uncomment this to specify a total-conversion mod ark_RCONEnabled="${RCON_ENABLE:=false}" # Enable RCON Protocol -ark_RCONPort="${RCON_PORT:=32330}" # RCON Port +ark_RCONPort="${RCON_PORT:=27020}" # RCON Port ark_SessionName="${SESSION_NAME:=ARK Docker}" # if your session name needs special characters please use the .ini instead -ark_Port="${GAME_PORT:=7778}" # ARK server port (default 7777) +ark_Port="${GAME_PORT:=7777}" # ARK server port (default 7777) ark_QueryPort="${QUERY_PORT:=27015}" # ARK query port (default 27015) ark_ServerPassword="${SERVER_PASSWORD}" # ARK server password, empty: no password required to login ark_ServerAdminPassword="${ADMIN_PASSWORD}" # ARK server admin password, KEEP IT SAFE! diff --git a/docker-compose.yml b/docker-compose.yml index 02f1f12..2d44766 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,14 @@ version: "3.5" services: theisland: image: fossum/ark-cluster:master + + # healthcheck: + # test: arkmanager status | grep 'Server listening:.\+No' && exit 1 + # interval: 60s + # retries: 5 + # start_period: 600s + # timeout: 10s + deploy: restart_policy: condition: on-failure @@ -22,14 +30,14 @@ services: failure_action: rollback environment: - SERVERMAP: "TheIsland" + SERVER_MAP: "TheIsland" SESSION_NAME: "ARK Cluster TheIsland" CRON_AUTO_UPDATE: ${CRON_AUTO_UPDATE:-0 */3 * * *} CRON_AUTO_BACKUP: ${CRON_AUTO_BACKUP:-0 */1 * * *} - UPDATEONSTART: ${UPDATEONSTART:-1} - BACKUPONSTART: ${BACKUPONSTART:-1} - BACKUPONSTOP: ${BACKUPONSTOP:-1} - WARNONSTOP: ${WARNONSTOP:-1} + UPDATE_ON_START: ${UPDATEONSTART:-1} + BACKUP_ON_START: ${BACKUPONSTART:-1} + BACKUP_ON_STOP: ${BACKUPONSTOP:-1} + WARN_ON_STOP: ${WARNONSTOP:-1} USER_ID: ${USER_ID:-1000} GROUP_ID: ${GROUP_ID:-1000} TZ: ${TZ:-UTC} @@ -76,7 +84,7 @@ services: order: stop-first failure_action: rollback environment: - SERVERMAP: "Valguero_P" + SERVER_MAP: "Valguero_P" SESSION_NAME: "ARK Cluster" RCON_PORT: ${RCON_PORT:-32331} GAME_PORT: ${GAME_PORT:-7779} diff --git a/personal-stack.yml b/personal-stack.yml new file mode 100644 index 0000000..1a6147a --- /dev/null +++ b/personal-stack.yml @@ -0,0 +1,144 @@ +version: "3.5" + +services: + theisland: + image: fossum/ark-cluster:dev + # healthcheck: + # test: arkmanager status | grep 'Server listening:.\+No' && exit 1 + # interval: 60s + # retries: 5 + # start_period: 600s + # timeout: 10s + deploy: + restart_policy: + condition: on-failure + delay: 15s + max_attempts: 2 + window: 600s + mode: replicated + replicas: 1 + resources: + reservations: + memory: 8gb + update_config: + parallelism: 1 + delay: 30s + order: stop-first + failure_action: rollback + placement: + constraints: + - node.hostname==dockers + volumes: + # - theisland:/ark + - type: bind + source: /mnt/nfs/ark/theisland + target: /ark + - cluster:/cluster + environment: + SERVER_MAP: TheIsland + SESSION_NAME: Venture Bros (TheIsland) + TZ: ${TIME_ZONE} + SERVER_PASSWORD: ${SERVER_PASSWORD} + ADMIN_PASSWORD: ${ADMIN_PASSWORD} + MAX_PLAYERS: ${MAX_PLAYERS} + UPDATE_ON_START: ${UPDATE_ON_START} + BACKUP_ON_STOP: ${BACKUP_ON_STOP} + PRE_UPDATE_BACKUP: ${PRE_UPDATE_BACKUP} + WARN_ON_STOP: ${WARN_ON_STOP} + ENABLE_CROSSPLAY: ${ENABLE_CROSSPLAY} + DISABLE_BATTLEYE: ${DISABLE_BATTLEYE} + GAME_MOD_IDS: ${GAME_MOD_IDS} + CLUSTER_ID: ${CLUSTER_ID} + GAME_PORT: 7777 + QUERY_PORT: 27015 + RCON_PORT: 27020 + BACKUP_TO_LOAD: backup/main.2023-03-01_20.08.36.tar.bz2 + ports: + - "7777:7777/udp" + - "7778:7778/udp" + - "27015:27015/udp" + - "27020:27020/tcp" + # fjordur: + # image: fossum/ark-cluster:dev + # # entrypoint: /bin/bash + # # command: -c "tail -F anything" + # # healthcheck: + # # test: arkmanager status | grep 'Server listening:.\+No' && exit 1 + # # interval: 60s + # # retries: 5 + # # start_period: 600s + # # timeout: 10s + # deploy: + # restart_policy: + # condition: on-failure + # delay: 15s + # max_attempts: 3 + # window: 600s + # mode: replicated + # replicas: 1 + # resources: + # reservations: + # memory: 8gb + # update_config: + # parallelism: 1 + # delay: 30s + # order: stop-first + # failure_action: rollback + # placement: + # constraints: + # - node.hostname==dockers + # environment: + # SERVER_MAP: Fjordur + # SESSION_NAME: Venture Bros (Fjordur) + # TZ: ${TIME_ZONE} + # SERVER_PASSWORD: ${SERVER_PASSWORD} + # ADMIN_PASSWORD: ${ADMIN_PASSWORD} + # MAX_PLAYERS: ${MAX_PLAYERS} + # UPDATE_ON_START: ${UPDATE_ON_START} + # BACKUP_ON_STOP: ${BACKUP_ON_STOP} + # PRE_UPDATE_BACKUP: ${PRE_UPDATE_BACKUP} + # WARN_ON_STOP: ${WARN_ON_STOP} + # ENABLE_CROSSPLAY: ${ENABLE_CROSSPLAY} + # DISABLE_BATTLEYE: ${DISABLE_BATTLEYE} + # GAME_MOD_IDS: ${GAME_MOD_IDS} + # CLUSTER_ID: ${CLUSTER_ID} + # GAME_PORT: 7780 + # QUERY_PORT: 27016 + # RCON_PORT: 27021 + # ports: + # - "7780:7780/udp" + # - "7781:7781/udp" + # - "27016:27016/udp" + # - "27021:27021/tcp" + # volumes: + # - fjordur:/ark + # - cluster:/cluster + +volumes: + # theisland: + # driver: local + # driver_opts: + # type: "nfs" + # o: "addr=truenas.thefoss.org,nolock,rw,nfsvers=4,sync,noatime,tcp" + # device: ":/mnt/no-backup/games/ark/theisland" + # # type: "cifs" + # # o: "addr=truenas.thefoss.org,username=${CIFS_USER},password=${CIFS_PASS},file_mode=0777,dir_mode=0777" + # # device: "//truenas.thefoss.org/ark/theisland" + # fjordur: + # driver: local + # driver_opts: + # #type: "nfs" + # #o: "addr=truenas.thefoss.org,nolock,rw,nfsvers=4,async,noatime,rsize=8192,wsize=8192,tcp,timeo=14" + # #device: ":/mnt/no-backup/games/ark/fjordur" + # type: "cifs" + # o: "addr=truenas.thefoss.org,username=${CIFS_USER},password=${CIFS_PASS},file_mode=0777,dir_mode=0777" + # device: "//truenas.thefoss.org/ark/fjordur" + cluster: + driver: local + driver_opts: + type: "nfs" + o: "addr=truenas.thefoss.org,nolock,rw,nfsvers=4,sync,noatime,tcp" + device: ":/mnt/no-backup/games/ark/cluster" + # type: "cifs" + # o: "addr=truenas.thefoss.org,username=${CIFS_USER},password=${CIFS_PASS},file_mode=0777,dir_mode=0777" + # device: "//truenas.thefoss.org/ark/cluster" diff --git a/run.sh b/run.sh index 775b563..dad08a8 100644 --- a/run.sh +++ b/run.sh @@ -43,7 +43,7 @@ function verify_dir { log "###########################################################################" log "# Started - `date`" -log "# Server - ${SESSION_NAME} (${SERVERMAP})" +log "# Server - ${SESSION_NAME} (${SERVER_MAP})" log "# Cluster - ${CLUSTER_ID}" log "# User - ${USER_ID}" log "# Group - ${GROUP_ID}" @@ -72,7 +72,8 @@ if [ ! "$(id -u steam)" -eq "$USER_ID" ]; then log "Changing steam uid to $USER_ID." usermod -o -u "$USER_ID" steam fi -# Change gid if needed + +# Change the GROUP_ID if needed if [ ! "$(id -g steam)" -eq "$GROUP_ID" ]; then log "Changing steam gid to $GROUP_ID." groupmod -o -g "$GROUP_ID" steam @@ -97,6 +98,8 @@ verify_dir /cluster verify_dir /etc/arkmanager verify_dir /home/steam +#chmod -R 777 /ark/server || log ">>> Could not set /ark/server permissions." + ######################## # log "CRON Setup" @@ -118,6 +121,10 @@ if [ ! -f /etc/cron.d/arkbackup ]; then fi log "###########################################################################" +# Add bash complete for arkmanager +# cp /home/steam/arkmanager-complete.bash /etc/bash_completion.d/ +# source /home/steam/arkmanager-complete.bash + ######################## # log "Dropping to steam User Space" diff --git a/user-space.sh b/user-space.sh index 6ad41d8..021add0 100644 --- a/user-space.sh +++ b/user-space.sh @@ -11,6 +11,9 @@ function verify_dir { fi } +# Add bash complete for arkmanager +source /etc/bash_completion.d/arkmanager-completion.bash + # Create custom config if not set, use custom config if [ ! -f /ark/arkmanager.cfg ]; then cp /etc/arkmanager/instances/main.cfg /ark/arkmanager.cfg || warn "Could not save default config file." @@ -21,7 +24,7 @@ if [ ! -f /ark/server/ShooterGame/Binaries/Linux/ShooterGameServer ] || [ ! -f warn "No game files found. Installing..." arkmanager install || error "Could not install game files." else - if [ ${BACKUPONSTART} -eq 1 ] && [ "$(ls -A /ark/server/ShooterGame/Saved/SavedArks/)" ]; then + if [ ${BACKUP_ON_STOP} -eq 1 ] && [ "$(ls -A /ark/server/ShooterGame/Saved/SavedArks/)" ]; then log "Creating Backup ..." arkmanager backup || warn "Could not create backup." fi @@ -31,9 +34,14 @@ log "########################################################################### log "Installing Mods ..." arkmanager installmods || error "Could not install mods." +if [ "${BACKUP_TO_LOAD}" != "" ]; then + log "Restoring from backup..." + arkmanager restore "/ark/${BACKUP_TO_LOAD}" +fi + log "###########################################################################" log "Launching ark server ..." -if [ ${UPDATEONSTART} -eq 1 ]; then +if [ ${UPDATE_ON_START} -eq 1 ]; then arkmanager start || error "Could not start server." else arkmanager start -noautoupdate || error "Could not start server."