From 325529010b6b8d27599c2d0323a3cee6f2f95f9e Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 31 Oct 2015 16:26:54 +1000 Subject: [PATCH 01/71] Begin 1.5 development --- .version | 2 +- tools/arkmanager | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.version b/.version index c068b244..c239c60c 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -1.4 +1.5 diff --git a/tools/arkmanager b/tools/arkmanager index 4ecdeca5..f0b05fc7 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -7,7 +7,7 @@ # Contributors: Sispheor, Atriusftw, klightspeed, lexat, puseidr # Script version -arkstVersion="1.4" +arkstVersion="1.5" arkstCommit='' doUpgradeTools() { From 314416f07c940dc7b46ab2df349e186d74e96a13 Mon Sep 17 00:00:00 2001 From: Budman17r Date: Mon, 2 Nov 2015 11:09:30 -0600 Subject: [PATCH 02/71] Tar the Backup files, #Tar the files and remove the original Backup Directory. Saves about 50MB of disk space per backup --- tools/arkmanager | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index 4ecdeca5..68052ce5 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1160,6 +1160,10 @@ doBackup(){ else echo -e "${NORMAL}[ ${RED}FAILED${NORMAL} ]" fi +#Tar the files and remove the original Backup Directory. Saves about 50MB of disk space per backup +tar -Pzcvf "${datestamp}.tar.gz" "${backupdir}" +rm -rf ${backupdir} + } # From 1286145c9db819f972d168ba233447866067900d Mon Sep 17 00:00:00 2001 From: Budman17r Date: Tue, 3 Nov 2015 08:36:49 -0600 Subject: [PATCH 03/71] Update arkmanager Adding Knight's recommendation. --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 68052ce5..3dce3ac1 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1161,7 +1161,7 @@ doBackup(){ echo -e "${NORMAL}[ ${RED}FAILED${NORMAL} ]" fi #Tar the files and remove the original Backup Directory. Saves about 50MB of disk space per backup -tar -Pzcvf "${datestamp}.tar.gz" "${backupdir}" + tar -zcvf "${arkbackupdir}/${datestamp}.tar.gz" -C "${arkbackupdir}" "${datestamp}" rm -rf ${backupdir} } From a945b954c35b996d17a7ec3d5751018c1ce685e1 Mon Sep 17 00:00:00 2001 From: Budman17r Date: Tue, 3 Nov 2015 10:27:43 -0600 Subject: [PATCH 04/71] Update arkmanager Updating for bz2. --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 3dce3ac1..267c8510 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1161,7 +1161,7 @@ doBackup(){ echo -e "${NORMAL}[ ${RED}FAILED${NORMAL} ]" fi #Tar the files and remove the original Backup Directory. Saves about 50MB of disk space per backup - tar -zcvf "${arkbackupdir}/${datestamp}.tar.gz" -C "${arkbackupdir}" "${datestamp}" + tar -jcvf "${arkbackupdir}/${datestamp}.tar.bz2" -C "${arkbackupdir}" "${datestamp}" rm -rf ${backupdir} } From db3bc524e05ec112bdaf53c17a2d892c347bfce4 Mon Sep 17 00:00:00 2001 From: Budman17r Date: Tue, 3 Nov 2015 12:19:18 -0600 Subject: [PATCH 05/71] Update arkmanager Added the OK. Still needs work. --- tools/arkmanager | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 267c8510..e9bf3870 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1160,12 +1160,21 @@ doBackup(){ else echo -e "${NORMAL}[ ${RED}FAILED${NORMAL} ]" fi -#Tar the files and remove the original Backup Directory. Saves about 50MB of disk space per backup - tar -jcvf "${arkbackupdir}/${datestamp}.tar.bz2" -C "${arkbackupdir}" "${datestamp}" -rm -rf ${backupdir} + #Tar the files and remove the original Backup Directory. Saves about 50MB of disk space per backup + echo -ne "${NORMAL} Compressing Directory " + + tar -jcvf "${arkbackupdir}/${datestamp}.tar.bz2" -C "${arkbackupdir}" "${datestamp}" + rm -rf ${backupdir} + + if [ -f "${arkbackupdir}/${datestamp}.tar.bz2" ]; then + echo -e "${NORMAL}[ ${GREEN}OK${NORMAL} ]" + else + echo -e "${NORMAL}[ ${RED}FAILED${NORMAL} ]" + fi } + # # Print the status of the server (running? online? version?) # From 2df713d4885f5b57c34746cc0ceb067f52f3201d Mon Sep 17 00:00:00 2001 From: Budman17r Date: Tue, 3 Nov 2015 13:53:16 -0600 Subject: [PATCH 06/71] Update arkmanager Add the backups to a folder ${arkbackupdir}/${daystamp} /ARK-Backups/2015-11-03/Tars --- tools/arkmanager | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index e9bf3870..a746108b 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1062,10 +1062,13 @@ doInstallMod(){ # doBackup(){ local datestamp=`date +"%Y-%m-%d_%H.%M.%S"` + local daystamp=`date +"%Y-%m-%d"` local backupdir="${arkbackupdir}/${datestamp}" + local backupdirdaily="${arkbackupdir}/${daystamp}" local savedir="SavedArks" mkdir -p "$backupdir" - + mkdir -p "$backupdirdaily" + # extract the map name from the active map mod if [ -n "$serverMapModId" ]; then serverMap="$(perl -e ' @@ -1160,18 +1163,20 @@ doBackup(){ else echo -e "${NORMAL}[ ${RED}FAILED${NORMAL} ]" fi + #Tar the files and remove the original Backup Directory. Saves about 50MB of disk space per backup echo -ne "${NORMAL} Compressing Directory " - tar -jcvf "${arkbackupdir}/${datestamp}.tar.bz2" -C "${arkbackupdir}" "${datestamp}" + tar -jcvf "${arkbackupdir}/${daystamp}/${datestamp}.tar.bz2" -C "${arkbackupdir}" "${datestamp}" rm -rf ${backupdir} - if [ -f "${arkbackupdir}/${datestamp}.tar.bz2" ]; then + if [ -f "${arkbackupdir}/${daystamp}/${datestamp}.tar.bz2" ]; then echo -e "${NORMAL}[ ${GREEN}OK${NORMAL} ]" else echo -e "${NORMAL}[ ${RED}FAILED${NORMAL} ]" fi + } From b7d2715ed67a9a20f2ecad79e5e7c1e3880fb97b Mon Sep 17 00:00:00 2001 From: Budman17r Date: Tue, 3 Nov 2015 14:41:53 -0600 Subject: [PATCH 07/71] Update arkmanager --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index a746108b..69916d82 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1172,7 +1172,7 @@ doBackup(){ rm -rf ${backupdir} if [ -f "${arkbackupdir}/${daystamp}/${datestamp}.tar.bz2" ]; then - echo -e "${NORMAL}[ ${GREEN}OK${NORMAL} ]" + echo -e "${NORMAL}[ ${GREEN}OK${NORMAL} ]" else echo -e "${NORMAL}[ ${RED}FAILED${NORMAL} ]" fi From e7cdf60095887cce322defd395b62703b76f7a84 Mon Sep 17 00:00:00 2001 From: Budman17r Date: Tue, 3 Nov 2015 15:46:56 -0600 Subject: [PATCH 08/71] Update arkmanager removing verbose on tar. (makes it look cleaner --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 69916d82..1b2da1d4 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1168,7 +1168,7 @@ doBackup(){ echo -ne "${NORMAL} Compressing Directory " - tar -jcvf "${arkbackupdir}/${daystamp}/${datestamp}.tar.bz2" -C "${arkbackupdir}" "${datestamp}" + tar -jcf "${arkbackupdir}/${daystamp}/${datestamp}.tar.bz2" -C "${arkbackupdir}" "${datestamp}" rm -rf ${backupdir} if [ -f "${arkbackupdir}/${daystamp}/${datestamp}.tar.bz2" ]; then From 9dbb28c0b65489462034b1910ee1d3d7d396f174 Mon Sep 17 00:00:00 2001 From: Budman17r Date: Wed, 4 Nov 2015 09:01:28 -0600 Subject: [PATCH 09/71] Update arkmanager added \e[68G --- tools/arkmanager | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 1b2da1d4..7080ebfb 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1101,9 +1101,9 @@ doBackup(){ cp -p "${arkserverroot}/ShooterGame/Saved/${savedir}/${serverMap##*/}.tmp" "${backupdir##*/}/${serverMap##*/}.ark" fi if [ -f "${backupdir}/${serverMap##*/}.ark" ]; then - echo -e "${NORMAL}[ ${GREEN}OK${NORMAL} ]" + echo -e "${NORMAL}\e[68G[ ${GREEN}OK${NORMAL} ]" else - echo -e "${NORMAL}[ ${RED}FAILED${NORMAL} ]" + echo -e "${NORMAL}\e[68G[ ${RED}FAILED${NORMAL} ]" fi # ARK server uses Lock-Truncate-Write-Unlock @@ -1124,9 +1124,9 @@ doBackup(){ cp -p "${f%.arkprofile}.tmpprofile" "${backupdir}/${f##*/}" fi if [ -s "${backupdir}/${f##*/}" ]; then - echo -e "${NORMAL}[ ${GREEN}OK${NORMAL} ]" + echo -e "${NORMAL}\e[68G[ ${GREEN}OK${NORMAL} ]" else - echo -e "${NORMAL}[ ${RED}FAILED${NORMAL} ]" + echo -e "${NORMAL}\e[68G[ ${RED}FAILED${NORMAL} ]" fi done @@ -1145,9 +1145,9 @@ doBackup(){ cp -p "${f%.arktribe}.tmptribe" "${backupdir}/${f##*/}" fi if [ -s "${backupdir}/${f##*/}" ]; then - echo -e "${NORMAL}[ ${GREEN}OK${NORMAL} ]" + echo -e "${NORMAL}\e[68G[ ${GREEN}OK${NORMAL} ]" else - echo -e "${NORMAL}[ ${RED}FAILED${NORMAL} ]" + echo -e "${NORMAL}\e[68G[ ${RED}FAILED${NORMAL} ]" fi done @@ -1159,9 +1159,9 @@ doBackup(){ cp -p "${f}" "${backupdir}/${f##*/}" fi if [ -f "${backupdir}/GameUserSettings.ini" ]; then - echo -e "${NORMAL}[ ${GREEN}OK${NORMAL} ]" + echo -e "${NORMAL}\e[68G[ ${GREEN}OK${NORMAL} ]" else - echo -e "${NORMAL}[ ${RED}FAILED${NORMAL} ]" + echo -e "${NORMAL}\e[68G[ ${RED}FAILED${NORMAL} ]" fi #Tar the files and remove the original Backup Directory. Saves about 50MB of disk space per backup @@ -1172,9 +1172,9 @@ doBackup(){ rm -rf ${backupdir} if [ -f "${arkbackupdir}/${daystamp}/${datestamp}.tar.bz2" ]; then - echo -e "${NORMAL}[ ${GREEN}OK${NORMAL} ]" + echo -e "${NORMAL}\e[68G[ ${GREEN}OK${NORMAL} ]" else - echo -e "${NORMAL}[ ${RED}FAILED${NORMAL} ]" + echo -e "${NORMAL}\e[68G[ ${RED}FAILED${NORMAL} ]" fi } From c384fe6b64adde7f712c55d2fe390b088f7eb4e1 Mon Sep 17 00:00:00 2001 From: Budman17r Date: Wed, 4 Nov 2015 09:40:31 -0600 Subject: [PATCH 10/71] Update arkmanager.cfg Adding Backup Logic. --- tools/arkmanager.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index a5c9f518..b2a174fb 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -17,6 +17,7 @@ arkbackupdir="/home/steam/ARK-Backups" # path to ba arkwarnminutes="60" # number of minutes to warn players when using update --warn arkautorestartfile="ShooterGame/Saved/.autorestart" # path to autorestart file arkBackupPreUpdate="false" # set this to true if you want to perform a backup before updating +arkTimeToKeepBackupFiles="10" #Set to Automatically Remove backups older than n days # Update warning messages # Modify as desired, putting the %d replacement operator where the number belongs From edaea141feb04bf9471d4a72010b45b7788e1734 Mon Sep 17 00:00:00 2001 From: Budman17r Date: Wed, 4 Nov 2015 15:16:22 -0600 Subject: [PATCH 11/71] Setting the Backup script to backup Game.ini (Has additional Settings Setting the Backup script to backup Game.ini (Has additional Settings --- tools/arkmanager | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 6ada483e..cb888bbb 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1163,7 +1163,22 @@ doBackup(){ else echo -e "${NORMAL}\e[68G[ ${RED}FAILED${NORMAL} ]" fi - + + + echo -ne "${NORMAL} Copying Game.ini " + + cp -p "${arkserverroot}/ShooterGame/Saved/Config/LinuxServer/Game.ini" "${backupdir}/Game.ini" + if [ ! -s "${backupdir}/Game.ini" ]; then + sleep 2 + cp -p "${f}" "${backupdir}/${f##*/}" + fi + if [ -f "${backupdir}/Game.ini" ]; then + echo -e "${NORMAL}\e[68G[ ${GREEN}OK${NORMAL} ]" + else + echo -e "${NORMAL}\e[68G[ ${RED}FAILED${NORMAL} ]" + fi + + #Tar the files and remove the original Backup Directory. Saves about 50MB of disk space per backup echo -ne "${NORMAL} Compressing Directory " From c4fc86c0b9fb41228eafc0b46afd65374fb19e2a Mon Sep 17 00:00:00 2001 From: Budman17r Date: Thu, 5 Nov 2015 08:21:22 -0600 Subject: [PATCH 12/71] Added Created backup with filename, changed directory to backup. --- tools/arkmanager | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index cb888bbb..14bcbf5c 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1181,7 +1181,7 @@ doBackup(){ #Tar the files and remove the original Backup Directory. Saves about 50MB of disk space per backup - echo -ne "${NORMAL} Compressing Directory " + echo -ne "${NORMAL} Compressing Backup " tar -jcf "${arkbackupdir}/${daystamp}/${datestamp}.tar.bz2" -C "${arkbackupdir}" "${datestamp}" rm -rf ${backupdir} @@ -1191,7 +1191,7 @@ doBackup(){ else echo -e "${NORMAL}\e[68G[ ${RED}FAILED${NORMAL} ]" fi - + echo -e "${NORMAL} Created Backup: ${GREEN} ${datestamp}.tar.bz2${NORMAL}" } From 130d665f1a07a24923e18be2354bfceffcddb693 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 16 Oct 2015 21:02:42 +1000 Subject: [PATCH 13/71] Add support for downloading updates before applying --- tools/arkmanager | 70 ++++++++++++++++++++++++++++++++++++-------- tools/arkmanager.cfg | 1 + 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 14bcbf5c..8c7ed596 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -749,6 +749,7 @@ doUpdate() { local validate= local modupdate= local saveworld= + local downloadonly= for arg in "$@"; do if [ "$arg" == "--force" ]; then @@ -766,6 +767,10 @@ doUpdate() { modupdate=1 elif [ "$arg" == "--backup" ]; then arkBackupPreUpdate=true + elif [ "$arg" =~ "^--stagingdir=" ]; then + arkStagingDir="${ark#--stagingdir=}" + elif [ "$arg" == "--downloadonly" ]; then + downloadonly=1 fi done @@ -782,9 +787,37 @@ doUpdate() { if isUpdateNeeded; then appupdate=1 + + if [ -n "${arkStagingDir}" -a "${arkStagingDir}" != "${arkserverroot}" ]; then + if [ ! -d "$arkStagingDir/ShooterGame" ]; then + cp -al "$arkserverroot/ShooterGame/." "$arkStagingDir/ShooterGame" + cp -al "$arkserverroot/Engine/." "$arkStagingDir/Engine" + cp -al "$arkserverroot/linux64/." "$arkStagingDir/linux64" + cp -al "$arkserverroot/PackageInfo.bin" "$arkStagingDir/PackageInfo.bin" + cp -al "$arkserverroot/steamclient.so" "$arkStagingDir/steamclient.so" + cp -a "$arkserverroot/steamapps/." "$arkStagingDir/steamapps" + rm -rf "$arkStagingDir/ShooterGame/Content/Mods/"* + rm -rf "$arkStagingDir/ShooterGame/Saved/"* + fi + + cd "$steamcmdroot" + ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkStagingDir" +app_update $appid $validate +quit + if [ -d "${arkStagingDir}/steamapps/downloading/${appid}" ]; then + echo "Update download interrupted" + return 1 + fi + fi fi - if [ -n "$appupdate" -o -n "$modupdate" ]; then + if [ -n "$downloadonly" ]; then + if [ -n "$appupdate" -a -n "$arkStagingDir" -a "$arkStagingDir" != "$arkserverroot" ]; then + echo "Server update downloaded" + fi + if [ -n "$modupdate" ]; then + echo "Mod update downloaded" + fi + echo "Not applying update - download-only enabled" + elif [ -n "$appupdate" -o -n "$modupdate" ]; then if isTheServerRunning; then if [ "$updatetype" == "safe" ]; then while [ ! `find $arkserverroot/ShooterGame/Saved/SavedArks -mmin -1 -name ${serverMap##*/}.ark` ]; do @@ -811,16 +844,25 @@ doUpdate() { fi doStop - + # If user wants to back-up, we do it here. - + if [ "$arkBackupPreUpdate" == "true" ]; then doBackup fi if [ -n "$appupdate" ]; then - cd "$steamcmdroot" - ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkserverroot" +app_update $appid $validate +quit + if [ -d "${arkStagingDir}" -a "${arkStagingDir}" != "${arkserverroot}" ]; then + cp -alu --remove-destination "$arkStagingDir/ShooterGame/." "$arkserverroot/ShooterGame" + cp -alu --remove-destination "$arkStagingDir/Engine/." "$arkserverroot/Engine" + cp -alu --remove-destination "$arkStagingDir/linux64/." "$arkserverroot/linux64" + cp -alu --remove-destination "$arkStagingDir/PackageInfo.bin" "$arkserverroot/PackageInfo.bin" + cp -alu --remove-destination "$arkStagingDir/steamclient.so" "$arkserverroot/steamclient.so" + cp -au --remove-destination "$arkStagingDir/steamapps/." "$arkserverroot/steamapps" + else + cd "$steamcmdroot" + ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkserverroot" +app_update $appid $validate +quit + fi # the current version should be the last version. We set our version getCurrentVersion echo "`timestamp`: update to $instver complete" >> "$logdir/update.log" @@ -834,7 +876,7 @@ doUpdate() { fi done fi - + # we restart the server only if it was started before the update if [ $serverWasAlive -eq 1 ]; then doStart @@ -1365,13 +1407,15 @@ while true; do echo "useconfig Use the configuration overrides in the specified config name or file" echo echo "Update command takes the below options:" - echo " --force Apply update without checking the current version" - echo " --safe Wait for server to perform world save and update." - echo " --warn Warn players before updating server" - echo " --validate Validates all ARK server files" - echo " --saveworld Saves world before update" - echo " --update-mods Updates installed and requested mods" - echo " --backup Takes a backup of the save files before updating" + echo " --force Apply update without checking the current version" + echo " --safe Wait for server to perform world save and update." + echo " --warn Warn players before updating server" + echo " --validate Validates all ARK server files" + echo " --saveworld Saves world before update" + echo " --update-mods Updates installed and requested mods" + echo " --backup Takes a backup of the save files before updating" + echo " --downloadonly Download the mod and/or server update without applying it" + echo " Requires arkStagingDir be set to a staging directory on the same filesystem as the server" exit 1 ;; *) diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index b2a174fb..22ef80d9 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -18,6 +18,7 @@ arkwarnminutes="60" # number of arkautorestartfile="ShooterGame/Saved/.autorestart" # path to autorestart file arkBackupPreUpdate="false" # set this to true if you want to perform a backup before updating arkTimeToKeepBackupFiles="10" #Set to Automatically Remove backups older than n days +#arkStagingDir="/home/steam/ARK-Staging" # Uncomment to enable downloading updates before restarting the server # Update warning messages # Modify as desired, putting the %d replacement operator where the number belongs From f5d9ddc0c0f13aa223df04e9d6f4cad38a4c4a42 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 5 Nov 2015 22:33:48 +1000 Subject: [PATCH 14/71] Add support for separate filesystems --- tools/arkmanager | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 8c7ed596..01fd8113 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -790,12 +790,17 @@ doUpdate() { if [ -n "${arkStagingDir}" -a "${arkStagingDir}" != "${arkserverroot}" ]; then if [ ! -d "$arkStagingDir/ShooterGame" ]; then - cp -al "$arkserverroot/ShooterGame/." "$arkStagingDir/ShooterGame" - cp -al "$arkserverroot/Engine/." "$arkStagingDir/Engine" - cp -al "$arkserverroot/linux64/." "$arkStagingDir/linux64" - cp -al "$arkserverroot/PackageInfo.bin" "$arkStagingDir/PackageInfo.bin" - cp -al "$arkserverroot/steamclient.so" "$arkStagingDir/steamclient.so" - cp -a "$arkserverroot/steamapps/." "$arkStagingDir/steamapps" + mkdir -p "$arkStagingDir" + if [ "$(stat -c "%d" "$arkserverroot")" == "$(stat -c "%d" "$arkStagingDir")" ]; then + cp -al "$arkserverroot/ShooterGame/." "$arkStagingDir/ShooterGame" + cp -al "$arkserverroot/Engine/." "$arkStagingDir/Engine" + cp -al "$arkserverroot/linux64/." "$arkStagingDir/linux64" + cp -al "$arkserverroot/PackageInfo.bin" "$arkStagingDir/PackageInfo.bin" + cp -al "$arkserverroot/steamclient.so" "$arkStagingDir/steamclient.so" + cp -a "$arkserverroot/steamapps/." "$arkStagingDir/steamapps" + else + rsync -a "$arkserverroot/." "$arkStagingDir/." + fi rm -rf "$arkStagingDir/ShooterGame/Content/Mods/"* rm -rf "$arkStagingDir/ShooterGame/Saved/"* fi @@ -853,12 +858,16 @@ doUpdate() { if [ -n "$appupdate" ]; then if [ -d "${arkStagingDir}" -a "${arkStagingDir}" != "${arkserverroot}" ]; then - cp -alu --remove-destination "$arkStagingDir/ShooterGame/." "$arkserverroot/ShooterGame" - cp -alu --remove-destination "$arkStagingDir/Engine/." "$arkserverroot/Engine" - cp -alu --remove-destination "$arkStagingDir/linux64/." "$arkserverroot/linux64" - cp -alu --remove-destination "$arkStagingDir/PackageInfo.bin" "$arkserverroot/PackageInfo.bin" - cp -alu --remove-destination "$arkStagingDir/steamclient.so" "$arkserverroot/steamclient.so" - cp -au --remove-destination "$arkStagingDir/steamapps/." "$arkserverroot/steamapps" + if [ "$(stat -c "%d" "$arkserverroot")" == "$(stat -c "%d" "$arkStagingDir")" ]; then + cp -alu --remove-destination "$arkStagingDir/ShooterGame/." "$arkserverroot/ShooterGame" + cp -alu --remove-destination "$arkStagingDir/Engine/." "$arkserverroot/Engine" + cp -alu --remove-destination "$arkStagingDir/linux64/." "$arkserverroot/linux64" + cp -alu --remove-destination "$arkStagingDir/PackageInfo.bin" "$arkserverroot/PackageInfo.bin" + cp -alu --remove-destination "$arkStagingDir/steamclient.so" "$arkserverroot/steamclient.so" + cp -au --remove-destination "$arkStagingDir/steamapps/." "$arkserverroot/steamapps" + else + rsync -a "$arkStagingDir/." "$arkserverroot" + fi else cd "$steamcmdroot" ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkserverroot" +app_update $appid $validate +quit From c71ffd2dd9d00e3a4fb49d6f78671500ed811be8 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 5 Nov 2015 22:42:50 +1000 Subject: [PATCH 15/71] Fix error in update option parsing --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 01fd8113..0b189fa7 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -767,7 +767,7 @@ doUpdate() { modupdate=1 elif [ "$arg" == "--backup" ]; then arkBackupPreUpdate=true - elif [ "$arg" =~ "^--stagingdir=" ]; then + elif [[ "$arg" =~ "^--stagingdir=" ]]; then arkStagingDir="${ark#--stagingdir=}" elif [ "$arg" == "--downloadonly" ]; then downloadonly=1 From 78f0ccbc4af54edf1b5a7ea24186743a26aac86c Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 6 Nov 2015 00:34:36 +1000 Subject: [PATCH 16/71] Add some notifications on what the updater is doing --- tools/arkmanager | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index 0b189fa7..dbfb2938 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -771,6 +771,10 @@ doUpdate() { arkStagingDir="${ark#--stagingdir=}" elif [ "$arg" == "--downloadonly" ]; then downloadonly=1 + else + echo "Unrecognized option $arg" + echo "Try 'arkmanager -h' or 'arkmanager --help' for more information." + exit 1 fi done @@ -790,6 +794,7 @@ doUpdate() { if [ -n "${arkStagingDir}" -a "${arkStagingDir}" != "${arkserverroot}" ]; then if [ ! -d "$arkStagingDir/ShooterGame" ]; then + echo "Copying to staging directory" mkdir -p "$arkStagingDir" if [ "$(stat -c "%d" "$arkserverroot")" == "$(stat -c "%d" "$arkStagingDir")" ]; then cp -al "$arkserverroot/ShooterGame/." "$arkStagingDir/ShooterGame" @@ -805,6 +810,7 @@ doUpdate() { rm -rf "$arkStagingDir/ShooterGame/Saved/"* fi + echo "Downloading ARK update" cd "$steamcmdroot" ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkStagingDir" +app_update $appid $validate +quit if [ -d "${arkStagingDir}/steamapps/downloading/${appid}" ]; then @@ -858,6 +864,7 @@ doUpdate() { if [ -n "$appupdate" ]; then if [ -d "${arkStagingDir}" -a "${arkStagingDir}" != "${arkserverroot}" ]; then + echo "Applying update from staging directory" if [ "$(stat -c "%d" "$arkserverroot")" == "$(stat -c "%d" "$arkStagingDir")" ]; then cp -alu --remove-destination "$arkStagingDir/ShooterGame/." "$arkserverroot/ShooterGame" cp -alu --remove-destination "$arkStagingDir/Engine/." "$arkserverroot/Engine" @@ -869,6 +876,7 @@ doUpdate() { rsync -a "$arkStagingDir/." "$arkserverroot" fi else + echo "Performing ARK update" cd "$steamcmdroot" ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkserverroot" +app_update $appid $validate +quit fi @@ -880,6 +888,7 @@ doUpdate() { if [ -n "$modupdate" ]; then for modid in $(getModIds); do if isModUpdateNeeded $modid; then + echo "Updating mod $modid" doExtractMod $modid echo "`timestamp`: Mod $modid updated" >> "$logdir/update.log" fi From 388b8b180d6638a82f09e7fa70a581d1d6786b37 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 6 Nov 2015 00:38:43 +1000 Subject: [PATCH 17/71] Update arkStagingDir comment --- tools/arkmanager.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 22ef80d9..07be3217 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -18,7 +18,7 @@ arkwarnminutes="60" # number of arkautorestartfile="ShooterGame/Saved/.autorestart" # path to autorestart file arkBackupPreUpdate="false" # set this to true if you want to perform a backup before updating arkTimeToKeepBackupFiles="10" #Set to Automatically Remove backups older than n days -#arkStagingDir="/home/steam/ARK-Staging" # Uncomment to enable downloading updates before restarting the server +#arkStagingDir="/home/steam/ARK-Staging" # Uncomment to enable updates to be fully downloaded before restarting the server (reduces downtime while updating) # Update warning messages # Modify as desired, putting the %d replacement operator where the number belongs From ffdeafec0cd807fc4d7fd6463c8ab28f48fb00f4 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 6 Nov 2015 00:52:40 +1000 Subject: [PATCH 18/71] Move `steamcmd` execution to a helper function --- tools/arkmanager | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index dbfb2938..a9c42385 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -285,6 +285,13 @@ doBroadcastWithEcho(){ doBroadcast "$1" } +# +# SteamCMD helper function +# +function runSteamCMD(){ + "$steamcmdroot/$steamcmdexec" +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} "$@" +quit +} + # # Check if a new version is available but not apply it # @@ -364,7 +371,7 @@ function getCurrentVersion(){ # function getAvailableVersion(){ rm -f "$steamcmd_appinfocache" - bnumber=`$steamcmdroot/$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +app_info_update 1 +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamACF ".depots.branches.public" "buildid"; break; fi; done` + bnumber=`runSteamCMD +app_info_update 1 +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamACF ".depots.branches.public" "buildid"; break; fi; done` if [ -z "$bnumber" ]; then bnumber="Unknown" fi @@ -659,6 +666,13 @@ doStopAll(){ done } +# +# install / update / download update +# +runSteamCMDAppUpdate(){ + runSteamCMD +force_install_dir "$1" +app_update $appid $2 +} + # # install of ARK server # @@ -676,7 +690,7 @@ doInstall() { cd "$steamcmdroot" # install the server - ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkserverroot" +app_update $appid validate +quit + runSteamCMDAppUpdate "$arkserverroot" validate # the current version should be the last version. We set our version getCurrentVersion } @@ -812,7 +826,7 @@ doUpdate() { echo "Downloading ARK update" cd "$steamcmdroot" - ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkStagingDir" +app_update $appid $validate +quit + runSteamCMDAppUpdate "$arkStagingDir" $validate if [ -d "${arkStagingDir}/steamapps/downloading/${appid}" ]; then echo "Update download interrupted" return 1 @@ -878,7 +892,7 @@ doUpdate() { else echo "Performing ARK update" cd "$steamcmdroot" - ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkserverroot" +app_update $appid $validate +quit + runSteamCMDAppUpdate "$arkserverroot" $validate fi # the current version should be the last version. We set our version getCurrentVersion @@ -928,7 +942,7 @@ doDownloadMod(){ cd "$steamcmdroot" while true; do - ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +workshop_download_item $mod_appid $modid +quit + runSteamCMD +workshop_download_item $mod_appid $modid if [ ! -d "$moddldir" ]; then break; fi local newsize="`du -s "$moddldir" | cut -f1`" if [ $newsize -eq $dlsize ]; then break; fi From 914bbdb626f861e0f8cfd5bf9e8668504d4c0ad0 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 8 Nov 2015 06:42:39 +1000 Subject: [PATCH 19/71] Add status messages in mod download --- tools/arkmanager | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index a9c42385..f97c9e8e 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -942,11 +942,15 @@ doDownloadMod(){ cd "$steamcmdroot" while true; do + echo "Downloading mod $modid" runSteamCMD +workshop_download_item $mod_appid $modid + echo + echo "Checking mod $modid" if [ ! -d "$moddldir" ]; then break; fi local newsize="`du -s "$moddldir" | cut -f1`" if [ $newsize -eq $dlsize ]; then break; fi dlsize=$newsize + echo "Mod $modid not fully downloaded - retrying" done if [ -f "$modsrcdir/mod.info" ]; then From 74fe4c958ecc29d31d1063aa7bf423b53b3f2658 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 12 Nov 2015 01:19:49 +1000 Subject: [PATCH 20/71] Remove files removed by Steam update --- tools/arkmanager | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index f97c9e8e..647d2eb7 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -889,6 +889,18 @@ doUpdate() { else rsync -a "$arkStagingDir/." "$arkserverroot" fi + cd "$arkserverroot" + find Engine ShooterGame linux64 -depth -print | + grep -v '^ShooterGame/\(Saved\|Content/Mods\)' | + while read f; do + if [ ! -e "staging/${f}" ]; then + if [ -f "$f" ]; then + rm "${f}" + else + rmdir "${f}" + fi + fi + done else echo "Performing ARK update" cd "$steamcmdroot" From c267cdf43499b02295b1af89e42d461f1c3b4a2c Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 14 Nov 2015 00:10:24 +1000 Subject: [PATCH 21/71] Add support for updating when nobody is connected --- tools/arkmanager | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index 14bcbf5c..7ae954d5 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -453,6 +453,24 @@ function isTheServerOnline(){ fi } +# +# Check if anybody is connected to the server +# +function numPlayersConnected(){ + perl -MSocket -e ' + my $port = int($ARGV[0]); + socket(my $socket, PF_INET, SOCK_DGRAM, 0); + setsockopt($socket, SOL_SOCKET, SO_RCVTIMEO, pack("i4", 1, 0, 0, 0)); + my $sockaddr = pack_sockaddr_in($port, inet_aton($ARGV[1])); + send($socket, "\xff\xff\xff\xffTSource Engine Query\x00", 0, $sockaddr); + my $data = ""; + recv($socket, $data, 1400, 0) or (print "0" and exit(1)); + my ($servername, $mapname, $game, $fullname, $rest) = split(/\x00/, substr($data, 6), 5); + my $players = ord(substr($rest, 2, 1)); + print "$players\n"; + ' "${ark_QueryPort}" "${ark_MultiHome:-127.0.0.1}" +} + # # run function # @@ -757,6 +775,8 @@ doUpdate() { updatetype=safe elif [ "$arg" == "--warn" ]; then updatetype=warn + elif [ "$arg" == "--ifempty" ]; then + updatetype=ifempty elif [ "$arg" == "--validate" ]; then validate=validate appupdate=1 @@ -796,6 +816,12 @@ doUpdate() { if ! doUpdateWarn; then return 1 fi + elif [ "$updatetype" == "ifempty" ]; then + numplayers=$(( $(numPlayersConnected) + 0 )) + if (( numplayers == 0 )); then + echo "${numplayers} players are still connected" + return 1 + fi fi fi From d3155120354c656eb29d42959e2fac306a2db995 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 14 Nov 2015 02:11:42 +1000 Subject: [PATCH 22/71] When warning players, update now if nobody's there --- tools/arkmanager | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 7ae954d5..0bd1ab45 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -706,6 +706,7 @@ doUpdateWarn(){ cd "$arkserverroot" local pid=`getServerPID` + local sleeppid if [ -n "$pid" ]; then local warnmsg local warnminutes=$(( arkwarnminutes )) @@ -721,13 +722,26 @@ doUpdateWarn(){ return 1 fi if (( arkwarnminutes > warninterval )); then + sleep 1m & + sleeppid=$! if [ -n "$msgWarnUpdateMinutes" ]; then warnmsg="$(printf "$msgWarnUpdateMinutes" "$warnminutes")" else warnmsg="$(printf "This ARK server will shutdown for an update in %d minutes" "$warnminutes")" fi doBroadcastWithEcho "$warnmsg" - sleep $(( warnminutes - warninterval ))m + for (( min = warnminutes - 1; min >= warninterval; min-- )); do + numplayers=$(numPlayersConnected) + if (( numplayers + 0 == 0 )); then + echo "Nobody is connected. Updating immediately" + return 0 + fi + wait $sleeppid + if (( $min > $warninterval )); then + sleep 1m & + sleeppid=$! + fi + done warnminutes=$warninterval fi done @@ -735,6 +749,8 @@ doUpdateWarn(){ local warnseconds=90 warnintervals=( 60 45 30 20 15 10 5 0 ) for warninterval in "${warnintervals[@]}"; do + sleep $(( warnseconds - warninterval ))s & + sleeppid=$! if [ "`getServerPID`" != "$pid" ]; then echo "Server has stopped. Aborting update" return 1 @@ -745,7 +761,14 @@ doUpdateWarn(){ warnmsg="$(printf "This ARK server will shutdown for an update in %d seconds" "$warnseconds")" fi doBroadcastWithEcho "$warnmsg" - sleep $(( warnseconds - warninterval ))s + if (( warnseconds >= 20 )); then + numplayers=$(numPlayersConnected) + if (( numplayers + 0 == 0 )); then + echo "Nobody is connected. Updating immediately" + return 0 + fi + fi + wait $sleeppid warnseconds=$warninterval done fi From 0b5a6f0cbac6155e3ffc187046034ac877370aa3 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 15 Nov 2015 00:23:32 +1000 Subject: [PATCH 23/71] Fix a couple of bugs in update --warn * Due to a bug in the minutes remaining check, the warning period was defaulting to 90 seconds, when it should have defaulted to 60 minutes. * The time between 2 minutes and 90 seconds was 60 seconds, when it should be 30 seconds --- tools/arkmanager | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 0bd1ab45..656d24b3 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -714,14 +714,14 @@ doUpdateWarn(){ warnminutes=60 fi - local warnintervals=( 90 60 45 30 20 15 10 5 4 3 2 1 ) + local warnintervals=( 90 60 45 30 20 15 10 5 4 3 2 ) for warninterval in "${warnintervals[@]}"; do if [ "`getServerPID`" != "$pid" ]; then echo "Server has stopped. Aborting update" return 1 fi - if (( arkwarnminutes > warninterval )); then + if (( warnminutes > warninterval )); then sleep 1m & sleeppid=$! if [ -n "$msgWarnUpdateMinutes" ]; then @@ -746,8 +746,8 @@ doUpdateWarn(){ fi done - local warnseconds=90 - warnintervals=( 60 45 30 20 15 10 5 0 ) + local warnseconds=120 + warnintervals=( 90 60 45 30 20 15 10 5 0 ) for warninterval in "${warnintervals[@]}"; do sleep $(( warnseconds - warninterval ))s & sleeppid=$! From 6606ed3cd29dfac1bf4f52814152fcea3f996a1e Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 11 Dec 2015 05:36:36 +1000 Subject: [PATCH 24/71] Allow all commands to take options --- tools/arkmanager | 62 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 4547ebe7..7bb59936 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1456,12 +1456,51 @@ useConfig() { checkConfig while true; do - case "$1" in + options=( ) + args=( ) + command="$1" + shift + nrarg=0 + + # get the number of arguments for commands that take arguments + case "$command" in + installmod) nrarg=1; ;; + broadcast) nrarg=1; ;; + rconcmd) nrarg=1; ;; + useconfig) nrarg=1; ;; + esac + + # Enumerate the options and arguments + while [ $# -ne 0 ]; do + case "$1" in + --) + shift + break + ;; + --args) + nrarg=$# + ;; + --*) + options+=( "$1" ) + ;; + *) + if [ $nrarg -gt 0 ]; then + args+=( "$1" ) + (( nrarg-- )) + else + break + fi + ;; + esac + shift + done + + case "$command" in run) doRun ;; start) - if [ "$2" == "--all" ]; then + if [ " ${options[*]} " =~ " --all " ]; then doStartAll shift else @@ -1469,6 +1508,7 @@ while true; do fi ;; stop) + if [ " ${options[*]} " =~ " --all " ]; then if [ "$2" == "--all" ]; then doStopAll shift @@ -1477,6 +1517,7 @@ while true; do fi ;; restart) + if [ " ${options[*]} " =~ " --all " ]; then if [ "$2" == "--all" ]; then doStopAll else @@ -1484,6 +1525,7 @@ while true; do fi echo "`timestamp`: stop" >> "$logdir/$arkmanagerLog" sleep 1 + if [ " ${options[*]} " =~ " --all " ]; then if [ "$2" == "--all" ]; then doStartAll shift @@ -1497,34 +1539,27 @@ while true; do doInstall ;; update) - args=() - - while [[ "$2" =~ ^-- ]]; do - args=( "${args[@]}" "$2" ) - shift - done - - doUpdate "${args[@]}" + doUpdate "${options[@]}" ;; checkupdate) checkForUpdate ;; installmod) - doInstallMod "$2" + doInstallMod "${args[@]}" shift ;; backup) doBackup ;; broadcast) - doBroadcast "$2" + doBroadcast "${args[@]}" shift ;; saveworld) doSaveWorld ;; rconcmd) - rconcmd "$2" + rconcmd "${args[@]}" shift ;; status) @@ -1597,7 +1632,6 @@ while true; do ;; esac status=$? - shift if [ $# -eq 0 ]; then break fi From 45ace7756505bbf07a3ac87a058c5a78e28155c8 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 11 Dec 2015 06:00:00 +1000 Subject: [PATCH 25/71] Add the option to warn on shutdown and restart --- tools/arkmanager | 69 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 7bb59936..01d60fb4 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -682,6 +682,9 @@ doStartAll(){ # doStop() { if isTheServerRunning; then + if [ " $* " =~ " --warn " ]; then + doWarn "$1" + fi tput sc echo "Stopping server..." echo "`timestamp`: stopping" >> "$logdir/$arkmanagerLog" @@ -758,9 +761,47 @@ doInstall() { # # Waits for a configurable number of minutes before updating the server # -doUpdateWarn(){ +doWarn(){ cd "$arkserverroot" + local warnmsgmin + local warnmsgsec + + if [ "$1" == "update" ]; then + if [ -n "$msgWarnUpdateMinutes" ]; then + warnmsgmin="$msgWarnUpdateMinutes" + else + warnmsgmin="This ARK server will shutdown for an update in %d minutes" + fi + if [ -n "$msgWarnUpdateSeconds" ]; then + warnmsgsec="$msgWarnUpdateSeconds" + else + warnmsgsec="This ARK server will shutdown for an update in %d seconds" + fi + elif [ "$1" == "restart" ]; then + if [ -n "$msgWarnRestartMinutes" ]; then + warnmsgmin="$msgWarnRestartMinutes" + else + warnmsgmin="This ARK server will shutdown for a restart in %d minutes" + fi + if [ -n "$msgWarnRestartSeconds" ]; then + warnmsgsec="$msgWarnRestartSeconds" + else + warnmsgsec="This ARK server will shutdown for a restart in %d seconds" + fi + else + if [ -n "$msgWarnShutdownMinutes" ]; then + warnmsgmin="$msgWarnShutdownMinutes" + else + warnmsgmin="This ARK server will shutdown in %d minutes" + fi + if [ -n "$msgWarnShutdownSeconds" ]; then + warnmsgsec="$msgWarnShutdownSeconds" + else + warnmsgsec="This ARK server will shutdown in %d seconds" + fi + fi + local pid=`getServerPID` local sleeppid if [ -n "$pid" ]; then @@ -774,22 +815,18 @@ doUpdateWarn(){ for warninterval in "${warnintervals[@]}"; do if [ "`getServerPID`" != "$pid" ]; then - echo "Server has stopped. Aborting update" + echo "Server has stopped. Aborting $1" return 1 fi if (( warnminutes > warninterval )); then sleep 1m & sleeppid=$! - if [ -n "$msgWarnUpdateMinutes" ]; then - warnmsg="$(printf "$msgWarnUpdateMinutes" "$warnminutes")" - else - warnmsg="$(printf "This ARK server will shutdown for an update in %d minutes" "$warnminutes")" - fi + warnmsg="$(printf "$warnmsgmin" "$warnminutes")" doBroadcastWithEcho "$warnmsg" for (( min = warnminutes - 1; min >= warninterval; min-- )); do numplayers=$(numPlayersConnected) if (( numplayers + 0 == 0 )); then - echo "Nobody is connected. Updating immediately" + echo "Nobody is connected. Shutting down immediately" return 0 fi wait $sleeppid @@ -811,16 +848,12 @@ doUpdateWarn(){ echo "Server has stopped. Aborting update" return 1 fi - if [ -n "$msgWarnUpdateSeconds" ]; then - warnmsg="$(printf "$msgWarnUpdateSeconds" "$warnseconds")" - else - warnmsg="$(printf "This ARK server will shutdown for an update in %d seconds" "$warnseconds")" - fi + warnmsg="$(printf "$warnmsgsec" "$warnseconds")" doBroadcastWithEcho "$warnmsg" if (( warnseconds >= 20 )); then numplayers=$(numPlayersConnected) if (( numplayers + 0 == 0 )); then - echo "Nobody is connected. Updating immediately" + echo "Nobody is connected. Shutting down immediately" return 0 fi fi @@ -830,7 +863,7 @@ doUpdateWarn(){ fi if [ "`getServerPID`" != "$pid" ]; then - echo "Server has stopped. Aborting update" + echo "Server has stopped. Aborting $1" return 1 fi @@ -952,7 +985,7 @@ doUpdate() { done echo "`timestamp`: Save file newer than 1 minute. Performing an update." >> "$logdir/update.log" elif [ "$updatetype" == "warn" ]; then - if ! doUpdateWarn; then + if ! doWarn update; then return 1 fi elif [ "$updatetype" == "ifempty" ]; then @@ -1513,7 +1546,7 @@ while true; do doStopAll shift else - doStop + doStop stop "${options[@]}" fi ;; restart) @@ -1521,7 +1554,7 @@ while true; do if [ "$2" == "--all" ]; then doStopAll else - doStop + doStop restart "${options[@]}" fi echo "`timestamp`: stop" >> "$logdir/$arkmanagerLog" sleep 1 From c13afcb0d8545997e3be4da15efee40d944099a8 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 11 Dec 2015 10:35:52 +1000 Subject: [PATCH 26/71] Add restart / shutdown warning text to config --- tools/arkmanager | 3 --- tools/arkmanager.cfg | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 01d60fb4..de36fc98 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1542,7 +1542,6 @@ while true; do ;; stop) if [ " ${options[*]} " =~ " --all " ]; then - if [ "$2" == "--all" ]; then doStopAll shift else @@ -1551,7 +1550,6 @@ while true; do ;; restart) if [ " ${options[*]} " =~ " --all " ]; then - if [ "$2" == "--all" ]; then doStopAll else doStop restart "${options[@]}" @@ -1559,7 +1557,6 @@ while true; do echo "`timestamp`: stop" >> "$logdir/$arkmanagerLog" sleep 1 if [ " ${options[*]} " =~ " --all " ]; then - if [ "$2" == "--all" ]; then doStartAll shift else diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 51e62375..96c8c05c 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -24,6 +24,10 @@ arkTimeToKeepBackupFiles="10" #Set to Auto # 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" # ARK server options - use ark_= # comment out these values if you want to define them From 0dc4439c4ca14b3b00d93e3c83ad01ae5e979d00 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 11 Dec 2015 11:55:39 +1000 Subject: [PATCH 27/71] Fix annoying syntax highlighting issue --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index de36fc98..172e49ef 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -491,7 +491,7 @@ function isTheServerOnline(){ # If the Steam server response contains "addr": "$ip:$port", # then the server has registered with the Steam master server - if [[ "$serverresp" =~ \"addr\":\ \"([^\"]*):([0-9]*)\" ]]; then + if [[ "$serverresp" =~ "\"addr\": \""([^\"]*):([0-9]*)"\"" ]]; then return 0 else return 1 From 448945ac059e4a5ec4fa644d27fcdbd84d8ae242 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 12 Dec 2015 06:31:20 +1000 Subject: [PATCH 28/71] Add --saveworld option to stop and restart --- tools/arkmanager | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index de36fc98..6b439878 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -685,6 +685,9 @@ doStop() { if [ " $* " =~ " --warn " ]; then doWarn "$1" fi + if [ " $* " =~ " --saveworld " ]; then + doSaveWorld + fi tput sc echo "Stopping server..." echo "`timestamp`: stopping" >> "$logdir/$arkmanagerLog" From de298e8a2d64a14ba2a1ce7c627c0ffbebf7bf28 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 12 Dec 2015 07:02:48 +1000 Subject: [PATCH 29/71] Fix useconfig --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 6b439878..10e3f903 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1605,7 +1605,7 @@ while true; do doUninstallTools ;; useconfig) - useConfig "$2" + useConfig "${args[0]}" shift ;; --version) From 73a85935e988d4c5ceae012d4d5f643891728a37 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 12 Dec 2015 07:11:25 +1000 Subject: [PATCH 30/71] Add stop and restart options to help --- tools/arkmanager | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index 10e3f903..5b4672a1 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1651,6 +1651,10 @@ while true; do echo " --backup Takes a backup of the save files before updating" echo " --downloadonly Download the mod and/or server update without applying it" echo " Requires arkStagingDir be set to a staging directory on the same filesystem as the server" + echo + echo "stop and restart commands take the below options:" + echo " --warn Warn players before shutting down the server" + echo " --saveworld Saves world before shutdown" exit 1 ;; *) From 6a6c1e7fa7d3a62e7828b305ee3b242be2640703 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 13 Dec 2015 06:26:41 +1000 Subject: [PATCH 31/71] Remove unnecessary shifts from command processing --- tools/arkmanager | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 294cd6a1..49db4b7c 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1538,7 +1538,6 @@ while true; do start) if [ " ${options[*]} " =~ " --all " ]; then doStartAll - shift else doStart fi @@ -1546,7 +1545,6 @@ while true; do stop) if [ " ${options[*]} " =~ " --all " ]; then doStopAll - shift else doStop stop "${options[@]}" fi @@ -1561,7 +1559,6 @@ while true; do sleep 1 if [ " ${options[*]} " =~ " --all " ]; then doStartAll - shift else doStart fi @@ -1579,21 +1576,18 @@ while true; do ;; installmod) doInstallMod "${args[@]}" - shift ;; backup) doBackup ;; broadcast) doBroadcast "${args[@]}" - shift ;; saveworld) doSaveWorld ;; rconcmd) rconcmd "${args[@]}" - shift ;; status) printStatus @@ -1606,7 +1600,6 @@ while true; do ;; useconfig) useConfig "${args[0]}" - shift ;; --version) echo "Version: ${arkstVersion}" From 7cd3d9e15f6bac658fce03eee48ab36aed767841 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Tue, 17 Nov 2015 00:29:06 +1000 Subject: [PATCH 32/71] Add per-command multi-instance support --- tools/arkmanager | 267 ++++++++++++++++++++++++++++------------------- 1 file changed, 159 insertions(+), 108 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 49db4b7c..10be771e 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1484,6 +1484,48 @@ useConfig() { source "$1" } +showUsage() { + echo -e "Usage: arkmanager [Commands]\n" + echo "Commands can be followed by one or more @instance arguments" + echo "The special '@all' instance selects all instances" + echo "Commands may also be followed by zero or more --options" + echo + echo "Commands that take no instances:" + echo "Command Description" + echo "upgrade-tools Check for a new ARK Server Tools version and upgrades it if needed" + echo "uninstall-tools Uninstall the ARK Server Tools" + echo "useconfig Sets the default instance for the commands that follow" + echo "--help Show this help" + echo "--version Show the version info of ARK Server Tools" + echo + echo "Commands that take one or more instances:" + echo "Command Description" + echo "backup Saves a backup of your server inside the backup directory" + echo "broadcast Sends a message to all users connected to server" + echo "saveworld Saves the game world to disk" + echo "rconcmd Execute RCON command on server" + echo "checkupdate Check for a new ARK server version" + echo "install Install the ARK server files from steamcmd" + echo "installmod Installs a mod from the Steam workshop" + echo "restart Stops the server and then starts it" + echo "run Runs the server without daemonizing" + echo "start Starts the server" + echo "stop Stops the server" + echo "status Returns the status of the current ARK server instance" + echo "update Check for a new ARK server version, if needed, stops the server, updates it, and starts it again" + echo + echo "Update command takes the below options:" + echo " --force Apply update without checking the current version" + echo " --safe Wait for server to perform world save and update." + echo " --warn Warn players before updating server" + echo " --validate Validates all ARK server files" + echo " --saveworld Saves world before update" + echo " --update-mods Updates installed and requested mods" + echo " --backup Takes a backup of the save files before updating" + echo " --downloadonly Download the mod and/or server update without applying it" + echo " Requires arkStagingDir be set to a staging directory on the same filesystem as the server" +} + #--------------------- # Main program #--------------------- @@ -1493,6 +1535,8 @@ checkConfig while true; do options=( ) + allinstances=no + instances=( ) args=( ) command="$1" shift @@ -1519,6 +1563,12 @@ while true; do --*) options+=( "$1" ) ;; + @all) + allinstances=yes + ;; + @*) + instances+=( "${1#@}" ) + ;; *) if [ $nrarg -gt 0 ]; then args+=( "$1" ) @@ -1531,75 +1581,19 @@ while true; do shift done + # handle non-instance separately case "$command" in - run) - doRun - ;; - start) - if [ " ${options[*]} " =~ " --all " ]; then - doStartAll - else - doStart - fi - ;; - stop) - if [ " ${options[*]} " =~ " --all " ]; then - doStopAll - else - doStop stop "${options[@]}" - fi - ;; - restart) - if [ " ${options[*]} " =~ " --all " ]; then - doStopAll - else - doStop restart "${options[@]}" - fi - echo "`timestamp`: stop" >> "$logdir/$arkmanagerLog" - sleep 1 - if [ " ${options[*]} " =~ " --all " ]; then - doStartAll - else - doStart - fi - echo "`timestamp`: start" >> "$logdir/$arkmanagerLog" - echo "`timestamp`: restart" >> "$logdir/$arkmanagerLog" - ;; - install) - doInstall - ;; - update) - doUpdate "${options[@]}" - ;; - checkupdate) - checkForUpdate - ;; - installmod) - doInstallMod "${args[@]}" - ;; - backup) - doBackup - ;; - broadcast) - doBroadcast "${args[@]}" - ;; - saveworld) - doSaveWorld - ;; - rconcmd) - rconcmd "${args[@]}" - ;; - status) - printStatus - ;; upgrade-tools) doUpgradeTools + exit ;; uninstall-tools) doUninstallTools + exit ;; useconfig) - useConfig "${args[0]}" + defaultinstance="${args[0]}" + continue ;; --version) echo "Version: ${arkstVersion}" @@ -1610,58 +1604,115 @@ while true; do exit 1 ;; -h|--help) - echo -e "Usage: arkmanager [OPTION]\n" - echo "Option Description" - echo "backup Saves a backup of your server inside the backup directory" - echo "broadcast Sends a message to all users connected to server" - echo "saveworld Saves the game world to disk" - echo "rconcmd Execute RCON command on server" - echo "checkupdate Check for a new ARK server version" - echo "install Install the ARK server files from steamcmd" - echo "installmod Installs a mod from the Steam workshop" - echo "restart Stops the server and then starts it" - echo "restart --all Restarts all servers specified in configfile_xxxxx" - echo "run Runs the server without daemonizing" - echo "start Starts the server" - echo "start --all Starts all servers specified in configfile_xxxxx" - echo "stop Stops the server" - echo "stop --all Stops all servers specified in configfile_xxxxx" - echo "status Returns the status of the current ARK server instance" - echo "update [OPTION ...] Check for a new ARK server version, if needed, stops the server, updates it, and starts it again" - echo "upgrade-tools Check for a new ARK Server Tools version and upgrades it if needed" - echo "uninstall-tools Uninstall the ARK Server Tools" - echo "useconfig Use the configuration overrides in the specified config name or file" - echo "--help Show this help" - echo "--version Show the version info of ARK Server Tools" - echo - echo "Update command takes the below options:" - echo " --force Apply update without checking the current version" - echo " --safe Wait for server to perform world save and update." - echo " --warn Warn players before updating server" - echo " --validate Validates all ARK server files" - echo " --saveworld Saves world before update" - echo " --update-mods Updates installed and requested mods" - echo " --backup Takes a backup of the save files before updating" - echo " --downloadonly Download the mod and/or server update without applying it" - echo " Requires arkStagingDir be set to a staging directory on the same filesystem as the server" - echo - echo "stop and restart commands take the below options:" - echo " --warn Warn players before shutting down the server" - echo " --saveworld Saves world before shutdown" + showUsage exit 1 ;; - *) - echo -n "arkmanager v${arkstVersion}: " - if [ $# -eq 0 ]; then - echo "no command specified" - else - echo "unknown command '$1' specified" - fi - echo "Try 'arkmanager -h' or 'arkmanager --help' for more information." + "") + echo "arkmanager v${arkstVersion}: no command specified" + showUsage exit 1 ;; esac - status=$? + + # Handle no instances being specified + if [[ "${#instances[@]}" == 0 && "$allinstances" == "no" ]]; then + if [ -n "$defaultinstance" ]; then + instances=( "$defaultinstance" ) + else + echo "No instances supplied for command ${command} ${options[*]} ${args[*]}" + read -p "Do you wish to run this command for all instances?" -n 1 -r + echo + if [[ "$REPLY" =~ ^[Yy]$ ]]; then + allinstances=yes + else + exit 1 + fi + fi + fi + + # Handle all instances being requested + if [[ "$allinstances" == "yes" ]]; then + instances=( ) + for varname in "${!configfile_@}"; do + instances+=( "${varname#configfile_}" ) + done + fi + + # Run the command for each instance requested + for instance in "${instances[@]}"; do + ( + echo "Running command '${command}' for instance '${instance}'" + useConfig "$instance" + + case "$command" in + run) + doRun + ;; + start) + doStart + ;; + stop) + doStop shutdown "${options[@]}" + ;; + restart) + doStop restart "${options[@]}" + echo "`timestamp`: stop" >> "$logdir/$arkmanagerLog" + ;; + install) + doInstall + ;; + update) + doUpdate "${options[@]}" + ;; + checkupdate) + checkForUpdate + ;; + installmod) + doInstallMod "${args[@]}" + ;; + backup) + doBackup + ;; + broadcast) + doBroadcast "${args[@]}" + ;; + saveworld) + doSaveWorld + ;; + rconcmd) + rconcmd "${args[@]}" + ;; + status) + printStatus + ;; + *) + echo -n "arkmanager v${arkstVersion}: unknown command '$command' specified" + showUsage + exit 255 + ;; + esac + ) + laststatus=$? + if [ $laststatus -eq 255 ]; then + exit 1 + elif [ $laststatus -ne 0 ]; then + status=$laststatus + fi + done + + # Perform the restart portion of the restart command + if [[ "$command" == "restart" ]]; then + sleep 1 + for instance in "${instances[@]}"; do + ( + useConfig "$instance" + doStart + echo "`timestamp`: start" >> "$logdir/$arkmanagerLog" + echo "`timestamp`: restart" >> "$logdir/$arkmanagerLog" + ) + done + fi + if [ $# -eq 0 ]; then break fi From 33b94c63a1d1e80b7fb66ca3bdd66fb8ff8eaf84 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 21 Nov 2015 22:30:44 +1000 Subject: [PATCH 33/71] Add support for instance config files Imports settings from /etc/arkmanager/instances/instancename.cfg and $HOME/.config/arkmanager/instances/instancename.cfg if those files exist. --- tools/arkmanager | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index 10be771e..dd5934ef 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1472,6 +1472,12 @@ printStatus(){ } useConfig() { + if [ -f "/etc/arkmanager/instances/${1}.cfg" ]; then + source "/etc/arkmanager/instances/${1}.cfg" + fi + if [ -f "${HOME}/.config/arkmanager/instances/${1}.cfg" ]; then + source "${HOME}/.config/arkmanager/instances/${1}.cfg" + fi if [ "$1" == "main" ]; then return fi From 80fd25a33db5f822964b96c8539ece74ad82f9ee Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 21 Nov 2015 22:39:46 +1000 Subject: [PATCH 34/71] Move config file migration to separate install-time script --- tools/install.sh | 40 ++-------------------------------------- tools/migrate-config.sh | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 38 deletions(-) create mode 100755 tools/migrate-config.sh diff --git a/tools/install.sh b/tools/install.sh index 3c3fbbc4..f81348d1 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -168,25 +168,7 @@ if [ "$userinstall" == "yes" ]; then # Copy arkmanager.cfg to ~/.arkmanager.cfg if it doesn't already exist if [ -f "${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg" ]; then - newopts=( arkbackupdir arkautorestartfile install_bindir install_libexecdir install_datadir mod_appid ) - newopt_steamcmd_appinfocache="${PREFIX}/Steam/appcache/appinfo.vdf" - newopt_arkbackupdir="${PREFIX}/ARK-Backups" - newopt_arkautorestartfile="ShooterGame/Saved/.autorestart" - newopt_install_bindir="${BINDIR}" - newopt_install_libexecdir="${LIBEXECDIR}" - newopt_install_datadir="${DATADIR}" - newopt_mod_appid=346110 - - if grep '^\(servermail\|arkstVersion\)=' "${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg" >/dev/null 2>&1; then - sed -i '/^\(servermail\|arkstVersion\)=/d' "${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg" - fi - - for optname in "${newopts[@]}"; do - if ! grep "^${optname}=" "${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg" >/dev/null 2>&1; then - noptname="newopt_${optname}" - echo "${optname}='${!noptname}'" >>"${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg" - fi - done + bash ./migrate-config.sh "${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg" echo "A previous version of ARK Server Tools was detected in your system, your old configuration was not overwritten. You may need to manually update it." echo "A copy of the new configuration file was included in '${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg.NEW'. Make sure to review any changes and update your config accordingly!" @@ -303,25 +285,7 @@ else "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg.NEW" if [ -f "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg" ]; then - newopts=( arkbackupdir arkautorestartfile install_bindir install_libexecdir install_datadir mod_appid ) - newopt_steamcmd_appinfocache="/home/${steamcmd_user}/Steam/appcache/appinfo.vdf" - newopt_arkbackupdir="/home/${steamcmd_user}/ARK-Backups" - newopt_arkautorestartfile="ShooterGame/Saved/.autorestart" - newopt_install_bindir="${BINDIR}" - newopt_install_libexecdir="${LIBEXECDIR}" - newopt_install_datadir="${DATADIR}" - newopt_mod_appid=346110 - - if grep '^\(servermail\|arkstVersion\)=' "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg" >/dev/null 2>&1; then - sed -i '/^\(servermail\|arkstVersion\)=/d' "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg" - fi - - for optname in "${newopts[@]}"; do - if ! grep "^${optname}=" "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg" >/dev/null 2>&1; then - noptname="newopt_${optname}" - echo "${optname}='${!noptname}'" >>"${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg" - fi - done + bash ./migrate-config.sh "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg" echo "A previous version of ARK Server Tools was detected in your system, your old configuration was not overwritten. You may need to manually update it." echo "A copy of the new configuration file was included in /etc/arkmanager. Make sure to review any changes and update your config accordingly!" diff --git a/tools/migrate-config.sh b/tools/migrate-config.sh new file mode 100755 index 00000000..e7bd0176 --- /dev/null +++ b/tools/migrate-config.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +configfile="$1" +newopts=( arkbackupdir arkautorestartfile install_bindir install_libexecdir install_datadir mod_appid ) +newopt_steamcmd_appinfocache="${PREFIX}/Steam/appcache/appinfo.vdf" +newopt_arkbackupdir="${PREFIX}/ARK-Backups" +newopt_arkautorestartfile="ShooterGame/Saved/.autorestart" +newopt_install_bindir="${BINDIR}" +newopt_install_libexecdir="${LIBEXECDIR}" +newopt_install_datadir="${DATADIR}" +newopt_mod_appid=346110 + +if grep '^\(servermail\|arkstVersion\)=' "${configfile}" >/dev/null 2>&1; then + sed -i '/^\(servermail\|arkstVersion\)=/d' "${configfile}" +fi + +for optname in "${newopts[@]}"; do + if ! grep "^${optname}=" "${configfile}" >/dev/null 2>&1; then + noptname="newopt_${optname}" + echo "${optname}='${!noptname}'" >>"${configfile}" + fi +done + From 627220de57e8808940fad649cf843842731bf71a Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 21 Nov 2015 22:44:58 +1000 Subject: [PATCH 35/71] Create instance config directory during install --- tools/install.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/install.sh b/tools/install.sh index f81348d1..99696dd6 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -155,6 +155,9 @@ if [ "$userinstall" == "yes" ]; then # Create a folder in ~/logs to let Ark tools write its own log files mkdir -p "${INSTALL_ROOT}${PREFIX}/logs/arktools" + # Create a folder in ~/.config/arkamanger to hold instance configs + mkdir -p "${INSTALL_ROOT}${PREFIX}/.config/arkmanager/instances" + # Copy arkmanager.cfg to ~/.arkmanager.cfg.NEW cp arkmanager.cfg "${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg.NEW" # Change the defaults in the new config file @@ -273,6 +276,10 @@ else mkdir -p "${INSTALL_ROOT}/var/log/arktools" chown "$steamcmd_user" "${INSTALL_ROOT}/var/log/arktools" + # Create a folder in /etc/arkmanager to hold instance config files + mkdir -p "${INSTALL_ROOT}/etc/arkmanager/instances" + chown "$steamcmd_user" "${INSTALL_ROOT}/etc/arkmanager/instances" + # Copy arkmanager.cfg inside linux configuation folder if it doesn't already exists mkdir -p "${INSTALL_ROOT}/etc/arkmanager" cp arkmanager.cfg "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg.NEW" From 15162c50fef5ebd1ac3bcb842f73fd6cadff1a36 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 21 Nov 2015 22:53:41 +1000 Subject: [PATCH 36/71] Move instance-specific settings to instance.cfg.example --- tools/arkmanager.cfg | 9 +++------ tools/install.sh | 6 ++++++ tools/instance.cfg.example | 28 ++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 tools/instance.cfg.example diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 96c8c05c..72105552 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -11,7 +11,6 @@ steamcmd_appinfocache="/home/steam/Steam/appcache/appinfo.vdf" # cache of t #steamlogin="anonymous" # Uncomment this to specify steam login instead of using anonymous login # config environment -arkserverroot="/home/steam/ARK" # path of your ARK server files (default ~/ARK) arkserverexec="ShooterGame/Binaries/Linux/ShooterGameServer" # name of ARK server executable arkbackupdir="/home/steam/ARK-Backups" # path to backup directory arkwarnminutes="60" # number of minutes to warn players when using update --warn @@ -29,17 +28,13 @@ 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" -# ARK server options - use ark_= +# ARK server common options - use ark_= # 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 ( in http://steamcommunity.com/sharedfiles/filedetails/?id=) #ark_TotalConversionMod="496735411" # Uncomment this to specify a total-conversion mod ark_RCONEnabled="True" # Enable RCON Protocol -ark_RCONPort="32330" # RCON Port -ark_SessionName="ARK Server Tools" # if your session name needs special characters please use the .ini instead -ark_Port="7778" # ARK server port (default 7778) -ark_QueryPort="27015" # ARK query port (default 27015) ark_ServerPassword="" # ARK server password, empty: no password required to login ark_ServerAdminPassword="keyboardcat" # ARK server admin password, KEEP IT SAFE! ark_MaxPlayers="70" @@ -69,3 +64,5 @@ mod_branch=Windows # alternate configs # example for config name "ark1": #configfile_ark1="/path/to/config/file" + +#defaultinstance="main" diff --git a/tools/install.sh b/tools/install.sh index 99696dd6..c28e7129 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -158,6 +158,9 @@ if [ "$userinstall" == "yes" ]; then # Create a folder in ~/.config/arkamanger to hold instance configs mkdir -p "${INSTALL_ROOT}${PREFIX}/.config/arkmanager/instances" + # Copy example instance config + cp instance.cfg.example "${INSTALL_ROOT}/${PREFIX}/.config/arkamanger/instances/instance.cfg.example" + # Copy arkmanager.cfg to ~/.arkmanager.cfg.NEW cp arkmanager.cfg "${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg.NEW" # Change the defaults in the new config file @@ -280,6 +283,9 @@ else mkdir -p "${INSTALL_ROOT}/etc/arkmanager/instances" chown "$steamcmd_user" "${INSTALL_ROOT}/etc/arkmanager/instances" + # Copy example instance config + cp instance.cfg.example "${INSTALL_ROOT}/etc/arkamanger/instances/instance.cfg.example" + # Copy arkmanager.cfg inside linux configuation folder if it doesn't already exists mkdir -p "${INSTALL_ROOT}/etc/arkmanager" cp arkmanager.cfg "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg.NEW" diff --git a/tools/instance.cfg.example b/tools/instance.cfg.example new file mode 100644 index 00000000..0513b44e --- /dev/null +++ b/tools/instance.cfg.example @@ -0,0 +1,28 @@ +# config environment +arkserverroot="/home/steam/ARK" # path of your ARK server files (default ~/ARK) + +# ARK server options - use ark_= +# 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 ( in http://steamcommunity.com/sharedfiles/filedetails/?id=) +#ark_TotalConversionMod="496735411" # Uncomment this to specify a total-conversion mod +ark_RCONEnabled="True" # Enable RCON Protocol +ark_RCONPort="32330" # RCON Port +ark_SessionName="ARK Server Tools" # if your session name needs special characters please use the .ini instead +ark_Port="7778" # ARK server port (default 7778) +ark_QueryPort="27015" # ARK query port (default 27015) +ark_ServerPassword="" # ARK server password, empty: no password required to login +ark_ServerAdminPassword="keyboardcat" # 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 + +# ARK server flags - use arkflag_=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 + + From 61446ab88c986da27694b14a3192aa53b37cd152 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 21 Nov 2015 23:12:34 +1000 Subject: [PATCH 37/71] Add CONFIGFILE and INSTANCEDIR variables in install.sh --- tools/install.sh | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index c28e7129..5c66dabe 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -99,10 +99,14 @@ if [ "$userinstall" == "yes" ]; then PREFIX="${PREFIX:-${HOME}}" EXECPREFIX="${EXECPREFIX:-${PREFIX}}" DATAPREFIX="${DATAPREFIX:-${PREFIX}/.local/share}" + CONFIGFILE="${PREFIX}/.arkmanager.cfg" + INSTANCEDIR="${PREFIX}/.config/arkmanager/instances" else PREFIX="${PREFIX:-/usr/local}" EXECPREFIX="${EXECPREFIX:-${PREFIX}}" DATAPREFIX="${DATAPREFIX:-${PREFIX}/share}" + CONFIGFILE="/etc/arkmanager/.arkmanager.cfg" + INSTANCEDIR="/etc/arkmanager/instances" fi BINDIR="${BINDIR:-${EXECPREFIX}/bin}" @@ -156,13 +160,16 @@ if [ "$userinstall" == "yes" ]; then mkdir -p "${INSTALL_ROOT}${PREFIX}/logs/arktools" # Create a folder in ~/.config/arkamanger to hold instance configs - mkdir -p "${INSTALL_ROOT}${PREFIX}/.config/arkmanager/instances" + mkdir -p "${INSTALL_ROOT}${INSTANCEDIR}" # Copy example instance config - cp instance.cfg.example "${INSTALL_ROOT}/${PREFIX}/.config/arkamanger/instances/instance.cfg.example" + cp instance.cfg.example "${INSTALL_ROOT}/${INSTANCEDIR}/instance.cfg.example" + # Change the defaults in the new instance config template + sed -i -e "s|\"/home/steam|\"${PREFIX}|" \ + "${INSTALL_ROOT}${INSTANCEDIR}/instance.cfg.example" # Copy arkmanager.cfg to ~/.arkmanager.cfg.NEW - cp arkmanager.cfg "${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg.NEW" + cp arkmanager.cfg "${INSTALL_ROOT}${CONFIGFILE}.NEW" # Change the defaults in the new config file sed -i -e "s|^steamcmd_user=\"steam\"|steamcmd_user=\"--me\"|" \ -e "s|\"/home/steam|\"${PREFIX}|" \ @@ -170,17 +177,17 @@ if [ "$userinstall" == "yes" ]; then -e "s|^install_bindir=.*|install_bindir=\"${BINDIR}\"|" \ -e "s|^install_libexecdir=.*|install_libexecdir=\"${LIBEXECDIR}\"|" \ -e "s|^install_datadir=.*|install_datadir=\"${DATADIR}\"|" \ - "${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg.NEW" + "${INSTALL_ROOT}${CONFIGFILE}.NEW" # Copy arkmanager.cfg to ~/.arkmanager.cfg if it doesn't already exist - if [ -f "${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg" ]; then - bash ./migrate-config.sh "${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg" + if [ -f "${INSTALL_ROOT}${CONFIGFILE}" ]; then + bash ./migrate-config.sh "${INSTALL_ROOT}${CONFIGFILE}" echo "A previous version of ARK Server Tools was detected in your system, your old configuration was not overwritten. You may need to manually update it." - echo "A copy of the new configuration file was included in '${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg.NEW'. Make sure to review any changes and update your config accordingly!" + echo "A copy of the new configuration file was included in '${CONFIGFILE}.NEW'. Make sure to review any changes and update your config accordingly!" exit 2 else - mv -n "${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg.NEW" "${INSTALL_ROOT}${PREFIX}/.arkmanager.cfg" + mv -n "${INSTALL_ROOT}${CONFIGFILE}.NEW" "${INSTALL_ROOT}${CONFIGFILE}" fi else # Copy arkmanager to /usr/bin and set permissions @@ -280,31 +287,31 @@ else chown "$steamcmd_user" "${INSTALL_ROOT}/var/log/arktools" # Create a folder in /etc/arkmanager to hold instance config files - mkdir -p "${INSTALL_ROOT}/etc/arkmanager/instances" - chown "$steamcmd_user" "${INSTALL_ROOT}/etc/arkmanager/instances" + mkdir -p "${INSTALL_ROOT}${INSTANCEDIR}" + chown "$steamcmd_user" "${INSTALL_ROOT}${INSTANCEDIR}" # Copy example instance config - cp instance.cfg.example "${INSTALL_ROOT}/etc/arkamanger/instances/instance.cfg.example" + cp instance.cfg.example "${INSTALL_ROOT}${INSTANCEDIR}/instance.cfg.example" # Copy arkmanager.cfg inside linux configuation folder if it doesn't already exists mkdir -p "${INSTALL_ROOT}/etc/arkmanager" - cp arkmanager.cfg "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg.NEW" - chown "$steamcmd_user" "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg.NEW" + cp arkmanager.cfg "${INSTALL_ROOT}${CONFIGFILE}.NEW" + chown "$steamcmd_user" "${INSTALL_ROOT}${CONFIGFILE}.NEW" sed -i -e "s|^steamcmd_user=\"steam\"|steamcmd_user=\"$steamcmd_user\"|" \ -e "s|\"/home/steam|\"/home/$steamcmd_user|" \ -e "s|^install_bindir=.*|install_bindir=\"${BINDIR}\"|" \ -e "s|^install_libexecdir=.*|install_libexecdir=\"${LIBEXECDIR}\"|" \ -e "s|^install_datadir=.*|install_datadir=\"${DATADIR}\"|" \ - "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg.NEW" + "${INSTALL_ROOT}${CONFIGFILE}.NEW" - if [ -f "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg" ]; then - bash ./migrate-config.sh "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg" + if [ -f "${INSTALL_ROOT}${CONFIGFILE}" ]; then + bash ./migrate-config.sh "${INSTALL_ROOT}${CONFIGFILE}" echo "A previous version of ARK Server Tools was detected in your system, your old configuration was not overwritten. You may need to manually update it." echo "A copy of the new configuration file was included in /etc/arkmanager. Make sure to review any changes and update your config accordingly!" exit 2 else - mv -n "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg.NEW" "${INSTALL_ROOT}/etc/arkmanager/arkmanager.cfg" + mv -n "${INSTALL_ROOT}${CONFIGFILE}.NEW" "${INSTALL_ROOT}${CONFIGFILE}.cfg" fi fi From b2ae770b994763c400ffb2503bd9d3332d817b4a Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 21 Nov 2015 23:14:53 +1000 Subject: [PATCH 38/71] Add script to migrate main instance --- tools/install.sh | 2 ++ tools/migrate-main-instance.sh | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100755 tools/migrate-main-instance.sh diff --git a/tools/install.sh b/tools/install.sh index 5c66dabe..73bfb986 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -182,6 +182,7 @@ if [ "$userinstall" == "yes" ]; then # Copy arkmanager.cfg to ~/.arkmanager.cfg if it doesn't already exist if [ -f "${INSTALL_ROOT}${CONFIGFILE}" ]; then bash ./migrate-config.sh "${INSTALL_ROOT}${CONFIGFILE}" + bash ./migrate-main-instance.sh "${INSTALL_ROOT}${CONFIGFILE}" "${INSTALL_ROOT}${INSTANCEDIR}/main.cfg" echo "A previous version of ARK Server Tools was detected in your system, your old configuration was not overwritten. You may need to manually update it." echo "A copy of the new configuration file was included in '${CONFIGFILE}.NEW'. Make sure to review any changes and update your config accordingly!" @@ -306,6 +307,7 @@ else if [ -f "${INSTALL_ROOT}${CONFIGFILE}" ]; then bash ./migrate-config.sh "${INSTALL_ROOT}${CONFIGFILE}" + bash ./migrate-main-instance.sh "${INSTALL_ROOT}${CONFIGFILE}" "${INSTALL_ROOT}${INSTANCEDIR}/main.cfg" echo "A previous version of ARK Server Tools was detected in your system, your old configuration was not overwritten. You may need to manually update it." echo "A copy of the new configuration file was included in /etc/arkmanager. Make sure to review any changes and update your config accordingly!" diff --git a/tools/migrate-main-instance.sh b/tools/migrate-main-instance.sh new file mode 100755 index 00000000..79cdfd6a --- /dev/null +++ b/tools/migrate-main-instance.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +configfile="$1" +instancefile="$2" + +if grep "^arkserverroot=" <"$configfile" >/dev/null 2>&1 && [ ! -f "$instancefile" ]; then + sed -n '/^#*\(ark\(\|flag\|opt\)_[^=]*\|arkserverroot\|serverMap\(\|ModId\)\)=/p' <"$configfile" >"$instancefile" + sed -i '/^ark\(serverroot\|_\(RCONPort\|Port\|QueryPort\)\)=/d' "$configfile" + echo 'defaultinstance="main"' >>"$configfile" +fi From f158b943e2079c2aaefcddcbb032b9e258a2d737 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 21 Nov 2015 23:15:26 +1000 Subject: [PATCH 39/71] Remove support for main instance in core config --- tools/arkmanager | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index dd5934ef..6e4553a2 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1478,9 +1478,6 @@ useConfig() { if [ -f "${HOME}/.config/arkmanager/instances/${1}.cfg" ]; then source "${HOME}/.config/arkmanager/instances/${1}.cfg" fi - if [ "$1" == "main" ]; then - return - fi for varname in "${!configfile_@}"; do if [ "configfile_$1" == "$varname" ]; then source "${!varname}" From 3f1110bd0a448edcb4e1ae4e6a5fd4d04bdcec5d Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 21 Nov 2015 23:25:54 +1000 Subject: [PATCH 40/71] Give steamcmd_user ownership of /etc/arkmanager --- tools/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/install.sh b/tools/install.sh index 73bfb986..e2f526b1 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -296,6 +296,7 @@ else # Copy arkmanager.cfg inside linux configuation folder if it doesn't already exists mkdir -p "${INSTALL_ROOT}/etc/arkmanager" + chown "$steamcmd_user" "${INSTALL_ROOT}/etc/arkmanager" cp arkmanager.cfg "${INSTALL_ROOT}${CONFIGFILE}.NEW" chown "$steamcmd_user" "${INSTALL_ROOT}${CONFIGFILE}.NEW" sed -i -e "s|^steamcmd_user=\"steam\"|steamcmd_user=\"$steamcmd_user\"|" \ From f7e8b1ada9ae920ea016bf8397b5bbeabe975fa9 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 21 Nov 2015 23:37:52 +1000 Subject: [PATCH 41/71] Error out if arkserverroot is not set --- tools/arkmanager | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 6e4553a2..d2c9f9ae 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1484,7 +1484,10 @@ useConfig() { return fi done - source "$1" + if [ -z "$arkserverroot" ]; then + echo "Error: arkserverroot not set" + exit 1 + fi } showUsage() { From 95cd1002e18035024ffab98b6b19d93bafd9e85c Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 21 Nov 2015 23:52:29 +1000 Subject: [PATCH 42/71] Enumerate all instances in @all; add list-instances command --- tools/arkmanager | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index d2c9f9ae..a26c7b21 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1471,6 +1471,41 @@ printStatus(){ echo -e "$NORMAL" "Server version: " "$GREEN" $instver "$NORMAL" } +getAllInstanceNames(){ + declare -A instancenames + for varname in "${!configfile_@}"; do + instancename="${varname#configfile_}" + instancenames[${instancename}]="${instancename}" + done + for f in /etc/arkmanager/instances/*.cfg; do + if [ -f "${f}" ]; then + instancename="${f##*/}" + instancename="${instancename%.cfg}" + instancenames[${instancename}]="${instancename}" + fi + done + for f in ${HOME}/.config/arkmanager/instances/*.cfg; do + if [ -f "${f}" ]; then + instancename="${f##*/}" + instancename="${instancename%.cfg}" + instancenames[${instancename}]="${instancename}" + fi + done + + echo "${instancenames[@]}" +} + +doListAllInstances(){ + echo "The following instances are available:" + for n in $(getAllInstanceNames); do + ( + echo -n " @${n}: " + useConfig "$n" + echo "${arkserverroot}" + ) + done +} + useConfig() { if [ -f "/etc/arkmanager/instances/${1}.cfg" ]; then source "/etc/arkmanager/instances/${1}.cfg" @@ -1501,6 +1536,7 @@ showUsage() { echo "upgrade-tools Check for a new ARK Server Tools version and upgrades it if needed" echo "uninstall-tools Uninstall the ARK Server Tools" echo "useconfig Sets the default instance for the commands that follow" + echo "list-instances Lists all available instances" echo "--help Show this help" echo "--version Show the version info of ARK Server Tools" echo @@ -1601,6 +1637,10 @@ while true; do defaultinstance="${args[0]}" continue ;; + list-instances) + doListAllInstances + exit + ;; --version) echo "Version: ${arkstVersion}" echo "Channel: ${arkstChannel}" @@ -1638,10 +1678,7 @@ while true; do # Handle all instances being requested if [[ "$allinstances" == "yes" ]]; then - instances=( ) - for varname in "${!configfile_@}"; do - instances+=( "${varname#configfile_}" ) - done + instances=( $(getAllInstanceNames) ) fi # Run the command for each instance requested From 94854f8d09c0336efb53a4e66bdabc8201069422 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 22 Nov 2015 00:04:18 +1000 Subject: [PATCH 43/71] Move check for ARK server exec to instance execution --- tools/arkmanager | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index a26c7b21..9a8d6a52 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -191,7 +191,7 @@ checkConfig() { # Environment configuration # arkserverexec - if [ ! -f "$arkserverroot/$arkserverexec" ] ; then + if [ -n "$arkserverroot" ] && [ ! -f "$arkserverroot/$arkserverexec" ] ; then echo -e "[" "$YELLOW" "WARN" "$NORMAL" "]" "\tYour ARK server exec could not be found." fi @@ -1516,7 +1516,7 @@ useConfig() { for varname in "${!configfile_@}"; do if [ "configfile_$1" == "$varname" ]; then source "${!varname}" - return + break fi done if [ -z "$arkserverroot" ]; then @@ -1686,6 +1686,7 @@ while true; do ( echo "Running command '${command}' for instance '${instance}'" useConfig "$instance" + checkConfig case "$command" in run) From 92acb88fd5c474c05c84bbfba90969bda10c4a5f Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 22 Nov 2015 18:33:46 +1000 Subject: [PATCH 44/71] Update systemd and upstart scripts with multi-instance support --- tools/arkmanager | 22 +++++++++++++--------- tools/install.sh | 3 +++ tools/systemd/arkmanager.init | 13 +++++++++++-- tools/upstart/arkmanager.conf | 6 ++++-- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 9a8d6a52..c672f1a0 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1496,14 +1496,18 @@ getAllInstanceNames(){ } doListAllInstances(){ - echo "The following instances are available:" - for n in $(getAllInstanceNames); do - ( - echo -n " @${n}: " - useConfig "$n" - echo "${arkserverroot}" - ) - done + if [ "$1" == "--brief" ]; then + getAllInstanceNames + else + echo "The following instances are available:" + for n in $(getAllInstanceNames); do + ( + echo -n " @${n}: " + useConfig "$n" + echo "${arkserverroot}" + ) + done + fi } useConfig() { @@ -1638,7 +1642,7 @@ while true; do continue ;; list-instances) - doListAllInstances + doListAllInstances "${options[@]}" exit ;; --version) diff --git a/tools/install.sh b/tools/install.sh index e2f526b1..3ac4df4e 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -210,6 +210,7 @@ else if [ -f /etc/systemd/system.conf ]; then # used by systemd mkdir -p "${INSTALL_ROOT}${LIBEXECDIR}" cp systemd/arkmanager.init "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init" + sed -i "s|^DAEMON=\"/usr/bin/|DAEMON=\"${BINDIR}/|" "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init" chmod +x "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init" cp systemd/arkmanager.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" sed -i "s|=/usr/libexec/arkmanager/|=${LIBEXECDIR}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" @@ -237,6 +238,7 @@ else if [ -f /etc/systemd/system.conf ]; then # used by systemd mkdir -p "${INSTALL_ROOT}${LIBEXECDIR}" cp systemd/arkmanager.init "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init" + sed -i "s|^DAEMON=\"/usr/bin/|DAEMON=\"${BINDIR}/|" "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init" chmod +x "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init" cp systemd/arkmanager.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" sed -i "s|=/usr/libexec/arkmanager/|=${LIBEXECDIR}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" @@ -270,6 +272,7 @@ else elif [ -f /etc/systemd/system.conf ]; then # used by systemd mkdir -p "${INSTALL_ROOT}${LIBEXECDIR}" cp systemd/arkmanager.init "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init" + sed -i "s|^DAEMON=\"/usr/bin/|DAEMON=\"${BINDIR}/|" "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init" chmod +x "${INSTALL_ROOT}${LIBEXECDIR}/arkmanager.init" cp systemd/arkmanager.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" sed -i "s|=/usr/libexec/arkmanager/|=${LIBEXECDIR}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" diff --git a/tools/systemd/arkmanager.init b/tools/systemd/arkmanager.init index be250290..fa760d2e 100755 --- a/tools/systemd/arkmanager.init +++ b/tools/systemd/arkmanager.init @@ -1,5 +1,14 @@ #!/bin/bash -for service in main $(grep -o '^configfile_[^=]*' /etc/arkmanager/arkmanager.cfg); do - systemctl start arkmanager@${service#configfile_} +DAEMON=/usr/bin/arkmanager + +for service in $(${DAEMON} list-instances --brief); do + case "$1" in + start) + systemctl start arkmanager@${service} + ;; + stop) + systemctl stop arkmanager@${service} + ;; + esac done diff --git a/tools/upstart/arkmanager.conf b/tools/upstart/arkmanager.conf index 688cbe81..5cc80081 100644 --- a/tools/upstart/arkmanager.conf +++ b/tools/upstart/arkmanager.conf @@ -1,8 +1,10 @@ start on runlevel [345] stop on runlevel [!345] +env DAEMON="/usr/bin/arkmanager" + script - for service in main $(grep -o '^configfile_[^=]*' /etc/arkmanager/arkmanager.cfg); do - start arkmanager-instance service=${service#configfile_} + for service in $(${DAEMON} list-instances --brief); do + start arkmanager-instance service=${service} done end script From 237fff6bc4e63cd0eb846713f3fea70b9535d08e Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 22 Nov 2015 19:40:25 +1000 Subject: [PATCH 45/71] Add multi-instance support to init scripts --- tools/lsb/arkdaemon | 93 ++++++++++++++++++++++++++++-------- tools/openrc/arkdaemon | 22 ++++----- tools/redhat/arkdaemon | 105 ++++++++++++++++++++++++++++++----------- 3 files changed, 160 insertions(+), 60 deletions(-) diff --git a/tools/lsb/arkdaemon b/tools/lsb/arkdaemon index 484d5d80..6390f59a 100755 --- a/tools/lsb/arkdaemon +++ b/tools/lsb/arkdaemon @@ -20,46 +20,99 @@ NAME="ShooterGameServer" LOGFILE="${logdir}/${NAME}.log" DAEMON="/usr/bin/arkmanager" +SVCNAME="${0##*/}" +INSTANCE="${SVCNAME#*.}" + +if [ "$INSTANCE" == "$SVCNAME" ]; then + INSTANCE="$2" +fi + set -e # If the daemon is not there, then exit. test -x $DAEMON || exit 5 +function start_instance(){ + local INSTANCE="$1" + PID="$(<"/var/run/arkmanager.${INSTANCE}.pid")" + if [ -n "$PID" ] && kill -0 "$PID" >/dev/null 2>&1; then + if grep " ${PID} .* ${DAEMON}" <(ps -ef) >/dev/null 2>&1; then + echo "$NAME @${INSTANCE} is already running" + return 0 + fi + fi + log_daemon_msg "Starting" "$NAME @${INSTANCE}" + ulimit -n 100000 + "${DAEMON}" run "@${INSTANCE}" & + PID="$!" + + sleep 5 + if kill -0 "$PID" >/dev/null 2>&1; then + echo "$PID" >"/var/run/arkmanager.${INSTANCE}.pid" + log_end_msg 0 + return 0 + else + log_end_msg 1 + return 1 + fi +} + +function start_all_instances(){ + local nosuccess=0 + local anyfailure=0 + for instance in $("${DAEMON}" list-instances --brief); do + if start_instance "$instance"; then + nosuccess=0 + else + anyfailure=1 + fi + done + + return $nosuccess +} + +function stop_instance(){ + local INSTANCE="$1" + log_daemon_msg "Stopping $NAME @${INSTANCE}: " + "${DAEMON}" stop "@${INSTANCE}" & + rm -f "/var/run/arkmanager.${INSTANCE}.pid" + log_end_msg 0 + return 0 +} + case "$1" in start) - log_daemon_msg "Starting" "$NAME" - ulimit -n 100000 - su -s /bin/sh -c "$DAEMON start --all" $steamcmd_user - sleep 5 - PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` - if [ -n "$PID" ]; then - echo "$PID" >/var/run/arkmanager.pid - log_end_msg 0 + if [ -n "$INSTANCE" ]; then + start_instance "$INSTANCE" + exit $? else - log_end_msg 1 + if start_all_instances; then + exit 0 + else + exit 1 + fi fi ;; stop) - log_daemon_msg "Stopping" "$NAME" - su -s /bin/sh -c "$DAEMON stop --all" $steamcmd_user - sleep 5 - PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` - if [ -n "$PID" ]; then - log_end_msg 1 + if [ -n "$INSTANCE" ]; then + stop_instance "$INSTANCE" + exit $? else - rm /var/run/arkmanager.pid - log_end_msg 0 + for instance in $("${DAEMON}" list-instances --brief); do + stop_instance "$instance" + done + exit $? fi ;; restart) - ulimit -n 100000 - su -s /bin/sh -c "$DAEMON restart --all" $steamcmd_user + "$0" stop + "$0" start ;; status) - su -s /bin/sh -c "$DAEMON status" $steamcmd_user + "$DAEMON" status "@${INSTANCE:-all}" ;; *) diff --git a/tools/openrc/arkdaemon b/tools/openrc/arkdaemon index 5aa93401..ac47eb1e 100644 --- a/tools/openrc/arkdaemon +++ b/tools/openrc/arkdaemon @@ -13,27 +13,25 @@ depend(){ } start(){ + INSTANCE="${RC_SVCNAME#*.}" ebegin "Starting ARK manager daemon" ulimit -n 100000 - su -s /bin/sh -c "$DAEMON start --all" $steamcmd_user - sleep 5 - PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` - if [ -n "$PID" ]; then - eend 0 + if [ "$INSTANCE" != "$RC_SVCNAME" ]; then + "$DAEMON" start "@${INSTANCE}" else - eend 1 + "$DAEMON" start "@all" fi + eend $? } stop(){ + INSTANCE="${RC_SVCNAME#*.}" ebegin "Stopping ARK manager daemon" - su -s /bin/sh -c "$DAEMON stop --all" $steamcmd_user - sleep 5 - PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` - if [ -n "$PID" ]; then - eend 0 + if [ "$INSTANCE" != "$RC_SVCNAME" ]; then + "$DAEMON" stop "@${INSTANCE}" else - eend 1 + "$DAEMON" stop "@all" fi + eend $? } diff --git a/tools/redhat/arkdaemon b/tools/redhat/arkdaemon index fa0ed1aa..48f05946 100755 --- a/tools/redhat/arkdaemon +++ b/tools/redhat/arkdaemon @@ -34,54 +34,103 @@ GREEN="\\033[1;32m" RED="\\033[1;31m" NORMAL="\\033[0;39m" +SVCNAME="${0##*/}" +INSTANCE="${SVCNAME#*.}" + +if [ "$INSTANCE" == "$SVCNAME" ]; then + INSTANCE="$2" +fi + set -e # If the daemon is not there, then exit. test -x $DAEMON || exit 5 +function start_instance(){ + local INSTANCE="$1" + PID="$(<"/var/run/arkmanager.${INSTANCE}.pid")" + if [ -n "$PID" ] && kill -0 "$PID" >/dev/null 2>&1; then + if grep " ${PID} .* ${DAEMON}" <(ps -ef) >/dev/null 2>&1; then + echo "$NAME @${INSTANCE} is already running" + return 0 + fi + fi + echo -n "Starting $NAME @${INSTANCE}: " + ulimit -n 100000 + "${DAEMON}" run "@${INSTANCE}" & + PID="$!" + + sleep 5 + if kill -0 "$PID" >/dev/null 2>&1; then + echo "$PID" >"/var/run/arkmanager.${INSTANCE}.pid" + touch "/var/lock/subsys/arkmanager.${INSTANCE}" + echo "[" "$GREEN" " OK " "$NORMAL" "]" + return 0 + else + echo "[" "$RED" " FAILED " "$NORMAL" "]" + return 1 + fi +} + +function start_all_instances(){ + local nosuccess=0 + local anyfailure=0 + for instance in $("${DAEMON}" list-instances --brief); do + if start_instance "$instance"; then + nosuccess=0 + else + anyfailure=1 + fi + done + + return $nosuccess +} + +function stop_instance(){ + local INSTANCE="$1" + echo -n "Stopping $NAME @${INSTANCE}: " + "${DAEMON}" stop "@${INSTANCE}" & + rm -f "/var/lock/subsys/arkmanager.${INSTANCE}" + rm -f "/var/run/arkmanager.${INSTANCE}.pid" + echo "[" "$GREEN" " OK " "$NORMAL" "]" + return 0 +} + case "$1" in start) - echo -n "Starting $NAME: " - ulimit -n 100000 - su -s /bin/sh -c "$DAEMON start --all" $steamcmd_user > /dev/null - sleep 5 - PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` - if [ -n "$PID" ]; then - echo "${PID}" >/var/run/arkmanager.pid - touch /var/lock/subsys/arkmanager - echo "[" "$GREEN" " OK " "$NORMAL" "]" - exit 0 + if [ -n "$INSTANCE" ]; then + start_instance "$INSTANCE" + exit $? else - echo "[" "$RED" " FAILED " "$NORMAL" "]" - exit 1 + if start_all_instances; then + touch /var/lock/subsys/arkmanager + exit 0 + else + exit 1 + fi fi ;; stop) - echo -n "Stopping $NAME: " - su -s /bin/sh -c "$DAEMON stop --all" $steamcmd_user > /dev/null - sleep 5 - PID=`ps -ef | grep $NAME | grep -v grep | awk '{print $2}'` - if [ -n "$PID" ]; then - echo "[" "$RED" " FAILED " "$NORMAL" "]" - exit 1 + if [ -n "$INSTANCE" ]; then + stop_instance "$INSTANCE" + exit $? else - echo "[" "$GREEN" " OK " "$NORMAL" "]" - rm -f /var/lock/subsys/arkmanager - rm -f /var/run/arkmanager.pid - exit 0 + for instance in $("${DAEMON}" list-instances --brief); do + stop_instance "$instance" + done + rm -f "/var/lock/subsys/arkmanager" + exit $? fi ;; restart) - echo -n "Restarting $NAME: " - ulimit -n 100000 - su -s /bin/sh -c "$DAEMON restart --all" $steamcmd_user > /dev/null - echo "OK" + "$0" stop + "$0" start ;; status) - su -s /bin/sh -c "$DAEMON status" $steamcmd_user + "$DAEMON" status "@${INSTANCE:-all}" exit 0 ;; From 566a518f100e5b51a74c0631553cdfa5ca1557a0 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 29 Nov 2015 06:02:15 +1000 Subject: [PATCH 46/71] Implement old backup removal by limiting backup size --- tools/arkmanager | 16 ++++++++++++++++ tools/arkmanager.cfg | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 294cd6a1..e6263fcf 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1427,6 +1427,22 @@ doBackup(){ echo -e "${NORMAL}\e[68G[ ${RED}FAILED${NORMAL} ]" fi echo -e "${NORMAL} Created Backup: ${GREEN} ${datestamp}.tar.bz2${NORMAL}" + + if [ -n "$arkMaxBackupSizeGB" ] && (( arkMaxBackupSizeGB >= 1 )); then + (( arkMaxBackupSizeMB = arkMaxBackupSizeGB * 1024 )) + fi + + if [ -n "$arkMaxBackupSizeMB" ] && (( arkMaxBackupSizeMB > 64 )); then + find "${arkbackupdir}" -type f -printf "%T@\t%s\t%p\n" | + sort -n -r | + cut -f2-3 | + (sz=0; while read fsz f; do + if (( sz / 1048576 > arkMaxBackupSizeMB )); then + rm "$f" + fi + (( sz += fsz )) + done) + fi } diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 96c8c05c..245d3f5b 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -17,7 +17,8 @@ arkbackupdir="/home/steam/ARK-Backups" # path to ba arkwarnminutes="60" # number of minutes to warn players when using update --warn arkautorestartfile="ShooterGame/Saved/.autorestart" # path to autorestart file arkBackupPreUpdate="false" # set this to true if you want to perform a backup before updating -arkTimeToKeepBackupFiles="10" #Set to Automatically Remove backups older than n days +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 #arkStagingDir="/home/steam/ARK-Staging" # Uncomment to enable updates to be fully downloaded before restarting the server (reduces downtime while updating) # Update warning messages From b89d6e3163dd9fe669f4fe88649830ab0cfcd3df Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Mon, 30 Nov 2015 07:09:58 +1000 Subject: [PATCH 47/71] Add note on typical size of compressed backup --- tools/arkmanager.cfg | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 245d3f5b..7b75a689 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -17,9 +17,12 @@ arkbackupdir="/home/steam/ARK-Backups" # path to ba arkwarnminutes="60" # number of minutes to warn players when using update --warn arkautorestartfile="ShooterGame/Saved/.autorestart" # path to autorestart file arkBackupPreUpdate="false" # set this to true if you want to perform a backup before updating +#arkStagingDir="/home/steam/ARK-Staging" # Uncomment to enable updates to be fully downloaded before restarting the server (reduces downtime while 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 -#arkStagingDir="/home/steam/ARK-Staging" # Uncomment to enable updates to be fully downloaded before restarting the server (reduces downtime while updating) # Update warning messages # Modify as desired, putting the %d replacement operator where the number belongs From 053d5a5979626f342a0205b59f5433df72705453 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 25 Dec 2015 09:35:29 +1000 Subject: [PATCH 48/71] Fix typo in stop/restart warn --- tools/arkmanager | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 7ff86465..d58e1094 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -682,10 +682,10 @@ doStartAll(){ # doStop() { if isTheServerRunning; then - if [ " $* " =~ " --warn " ]; then + if [[ " $* " =~ " --warn " ]]; then doWarn "$1" fi - if [ " $* " =~ " --saveworld " ]; then + if [[ " $* " =~ " --saveworld " ]]; then doSaveWorld fi tput sc From eeb42bcecdfc68bcc34d3f4bfba1abe259165009 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 26 Dec 2015 17:03:46 +1000 Subject: [PATCH 49/71] Warn when ServerAdminPassword is empty --- tools/arkmanager | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index d58e1094..d9cfcaa2 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -253,6 +253,14 @@ getQueryPort(){ # Execute RCON command # rconcmd() { + local adminpass="$(getAdminPassword)" + if [ -z "$adminpass" ]; then + echo "ServerAdminPassword is empty - unable to execute RCON command" + return 1 + elif [[ "$adminpass" =~ [?\177-\377] ]]; then + echo "ServerAdminPassword contains invalid characters" + return 1 + fi perl -MSocket -e ' sub sendpkt { my ($sock, $reqid, $reqtype, $body) = @_; @@ -263,7 +271,8 @@ rconcmd() { sub recvpkt { my ($sock) = @_; my $data = ""; - recv($sock, $data, 12, 0); + recv($sock, $data, 12, 0) or die "Error receiving response from server" + die "Empty response" if len($data) == 0; my ($pktlen, $resid, $restype) = unpack("VVV", $data); recv($sock, $data, $pktlen - 8, 0); return ($resid, $restype, substr($data, 0, $pktlen - 10)); @@ -289,7 +298,7 @@ rconcmd() { sendpkt($socket, 2, 2, $command); my ($resid, $restype, $rcvbody) = recvpkt($socket); print $rcvbody, "\n"; - ' "$(getRconPort)" "${ark_MultiHome:-127.0.0.1}" "$(getAdminPassword)" "$1" + ' "$(getRconPort)" "${ark_MultiHome:-127.0.0.1}" "$adminpass" "$1" } # From b0b36b9c5c5b115208c4cc0d1313bae513d80f4e Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 27 Dec 2015 21:05:11 +1000 Subject: [PATCH 50/71] Add missing semicolon fixes eeb42bc --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index d9cfcaa2..d0bc8522 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -271,7 +271,7 @@ rconcmd() { sub recvpkt { my ($sock) = @_; my $data = ""; - recv($sock, $data, 12, 0) or die "Error receiving response from server" + recv($sock, $data, 12, 0) or die "Error receiving response from server"; die "Empty response" if len($data) == 0; my ($pktlen, $resid, $restype) = unpack("VVV", $data); recv($sock, $data, $pktlen - 8, 0); From 2b58694e12dbabcbd68d0512d9489de2b7eb7003 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Mon, 28 Dec 2015 06:00:31 +1000 Subject: [PATCH 51/71] Print the last error when errors occur --- tools/arkmanager | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index d0bc8522..d7ca2754 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -265,13 +265,13 @@ rconcmd() { sub sendpkt { my ($sock, $reqid, $reqtype, $body) = @_; my $packet = pack("VVV", length($body) + 10, $reqid, $reqtype) . $body . "\0\0"; - send($sock, $packet, 0) or die "Error sending command to server"; + send($sock, $packet, 0) or die "Error sending command to server: $!"; } sub recvpkt { my ($sock) = @_; my $data = ""; - recv($sock, $data, 12, 0) or die "Error receiving response from server"; + recv($sock, $data, 12, 0) or die "Error receiving response from server: $!"; die "Empty response" if len($data) == 0; my ($pktlen, $resid, $restype) = unpack("VVV", $data); recv($sock, $data, $pktlen - 8, 0); @@ -293,7 +293,7 @@ rconcmd() { socket(my $socket, PF_INET, SOCK_STREAM, 0); setsockopt($socket, SOL_SOCKET, SO_RCVTIMEO, pack("i4", 30, 0, 0, 0)); my $sockaddr = pack_sockaddr_in($port, inet_aton($ipaddr)); - connect($socket, $sockaddr) or die "Error connecting to server"; + connect($socket, $sockaddr) or die "Error connecting to server: $!"; auth($socket, $password); sendpkt($socket, 2, 2, $command); my ($resid, $restype, $rcvbody) = recvpkt($socket); @@ -1225,26 +1225,26 @@ doExtractMod(){ printf "%10d %s " "`stat -c '%s' "$modsrcdir/$f"`" "${f%.z}" perl -M'Compress::Raw::Zlib' -e ' my $sig; - read(STDIN, $sig, 8) or die "Unable to read compressed file"; + read(STDIN, $sig, 8) or die "Unable to read compressed file: $!"; if ($sig != "\xC1\x83\x2A\x9E\x00\x00\x00\x00"){ die "Bad file magic"; } my $data; - read(STDIN, $data, 24) or die "Unable to read compressed file"; + read(STDIN, $data, 24) or die "Unable to read compressed file: $!"; my ($chunksizelo, $chunksizehi, $comprtotlo, $comprtothi, $uncomtotlo, $uncomtothi) = unpack("(LLLLLL)<", $data); my @chunks = (); my $comprused = 0; while ($comprused < $comprtotlo) { - read(STDIN, $data, 16) or die "Unable to read compressed file"; + read(STDIN, $data, 16) or die "Unable to read compressed file: $!"; my ($comprsizelo, $comprsizehi, $uncomsizelo, $uncomsizehi) = unpack("(LLLL)<", $data); push @chunks, $comprsizelo; $comprused += $comprsizelo; } foreach my $comprsize (@chunks) { - read(STDIN, $data, $comprsize) or die "File read failed"; + read(STDIN, $data, $comprsize) or die "File read failed: $!"; my ($inflate, $status) = new Compress::Raw::Zlib::Inflate(); my $output; $status = $inflate->inflate($data, $output, 1); From 9d45d9d1cc0afec8a599aff83bcca298ff5e8704 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Mon, 28 Dec 2015 10:21:39 +1000 Subject: [PATCH 52/71] Remove die on recv --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index d7ca2754..5a8ca5f8 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -271,7 +271,7 @@ rconcmd() { sub recvpkt { my ($sock) = @_; my $data = ""; - recv($sock, $data, 12, 0) or die "Error receiving response from server: $!"; + recv($sock, $data, 12, 0); die "Empty response" if len($data) == 0; my ($pktlen, $resid, $restype) = unpack("VVV", $data); recv($sock, $data, $pktlen - 8, 0); From 3c1690f0186863026595c80107f54c4ec9f1cf20 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Mon, 28 Dec 2015 21:02:41 +1000 Subject: [PATCH 53/71] Fix typo in RCON handling --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 5a8ca5f8..7bb8aeb6 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -272,7 +272,7 @@ rconcmd() { my ($sock) = @_; my $data = ""; recv($sock, $data, 12, 0); - die "Empty response" if len($data) == 0; + die "Empty response" if length($data) == 0; my ($pktlen, $resid, $restype) = unpack("VVV", $data); recv($sock, $data, $pktlen - 8, 0); return ($resid, $restype, substr($data, 0, $pktlen - 10)); From b1a4189a9c0c476ca4ca05fd392001c7f09f84a2 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 22 Jan 2016 18:37:01 +1000 Subject: [PATCH 54/71] Change message after server is started --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 7bb8aeb6..27b4cd6c 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -667,7 +667,7 @@ doStart() { doRun >"$logdir/$arkserverLog" 2>&1 & # output of this command is logged echo "`timestamp`: start" >> "$logdir/$arkmanagerLog" tput rc; tput ed; - echo "The server is now up" + echo "The server is now running, and should be up within 10 minutes" fi } From 4ca8617bc9f5e30415e51c6777b0b2013b109f0f Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 22 Jan 2016 18:43:42 +1000 Subject: [PATCH 55/71] Add option to automatically update on startup --- tools/arkmanager | 8 +++++++- tools/arkmanager.cfg | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 7bb8aeb6..32568f67 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -661,6 +661,12 @@ doStart() { if isTheServerRunning; then echo "The server is already running" else + if [ "$arkAutoUpdateOnStart" == "true" ]; then + if ! [[ " $* " =~ " --noautoupdate " ]]; then + echo "Updating server" + doUpdate --update-mods + fi + fi tput sc echo "The server is starting..." @@ -1075,7 +1081,7 @@ doUpdate() { # we restart the server only if it was started before the update if [ $serverWasAlive -eq 1 ]; then - doStart + doStart --noautoupdate fi else echo "Your server is already up to date! The most recent version is ${bnumber}." diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 9d8533a1..fbee5771 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -15,6 +15,7 @@ arkserverexec="ShooterGame/Binaries/Linux/ShooterGameServer" # name of AR arkbackupdir="/home/steam/ARK-Backups" # path to backup directory arkwarnminutes="60" # number of minutes to warn players when using update --warn arkautorestartfile="ShooterGame/Saved/.autorestart" # path to autorestart file +arkAutoUpdateOnStart="false" # set this to true if you want to always update before startup arkBackupPreUpdate="false" # set this to true if you want to perform a backup before updating #arkStagingDir="/home/steam/ARK-Staging" # Uncomment to enable updates to be fully downloaded before restarting the server (reduces downtime while updating) From 49a2b029bc4fafdf4059ef2d0e34518fc1e7c2e4 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 22 Jan 2016 18:51:32 +1000 Subject: [PATCH 56/71] Add `--noautoupdate` option to start and restart --- tools/arkmanager | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 32568f67..e5875f82 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1728,7 +1728,7 @@ while true; do doRun ;; start) - doStart + doStart "${options[@]}" ;; stop) doStop shutdown "${options[@]}" @@ -1785,7 +1785,7 @@ while true; do for instance in "${instances[@]}"; do ( useConfig "$instance" - doStart + doStart "${options[@]}" echo "`timestamp`: start" >> "$logdir/$arkmanagerLog" echo "`timestamp`: restart" >> "$logdir/$arkmanagerLog" ) From 326d753b4036f062f2207bf4fc2152f969eccc6e Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 22 Jan 2016 19:09:43 +1000 Subject: [PATCH 57/71] Warn when the SavedArks directory is not writable --- tools/arkmanager | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index 7bb8aeb6..6567ef25 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -195,6 +195,14 @@ checkConfig() { echo -e "[" "$YELLOW" "WARN" "$NORMAL" "]" "\tYour ARK server exec could not be found." fi + # SavedArks directory + if [ -n "$arkserverroot" ]; then + local savedarksdir="${arkserverroot}/ShooterGame/Saved/${ark_AltSaveDirectoryName:-SavedArks}" + if [ ! -w "${savedarksdir}" ]; then + echo -e "[" "$RED" "ERROR" "$NORMAL" "]" "\tThe ARK SavedArks directory is not writable, and saveworld will fail" + fi + fi + # Service configuration # logdir if [ ! -w "$logdir" ] ; then From d37176adbbd7ce4dfed923c7631c718166c0f589 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 28 Jan 2016 18:00:44 +1000 Subject: [PATCH 58/71] Warn when a mod is requested but not installed --- tools/arkmanager | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index 83a84891..dc6089fd 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -203,6 +203,15 @@ checkConfig() { fi fi + # Warn if any mods are requested but not installed + if [ -n "$arkserverroot" -a -a -d "${arkserverroot}/ShooterGame/Content/Mods" ]; then + for modid in $(getModIds); do + if [ ! -f "${arkserverroot}/ShooterGame/Content/Mods/${modid}/mod.info" ]; then + echo -e "[" "$RED" "ERROR" "$NORMAL" "]" "\tMod ${modid} is requested but not installed. Run 'arkmanager installmod ${modid}' to install this mod." + fi + done + fi + # Service configuration # logdir if [ ! -w "$logdir" ] ; then From 1d3827a87620f1dd20a51abba34192a93f573230 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 28 Jan 2016 18:05:50 +1000 Subject: [PATCH 59/71] Remove unused 'servicename' variable --- tools/arkmanager.cfg | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 9d8533a1..ed26f0d8 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -53,7 +53,6 @@ ark_MaxPlayers="70" #arkopt_StructureDestructionTag=DestroySwampSnowStructures # config Service -servicename="arkserv" # Name of the service (don't change if you don't know what are you doing) logdir="/var/log/arktools" # Logs path (default /var/log/arktools) # steamdb specific From 58458a852d1ad2c504cddacbcc84f2d69cca9f73 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 29 Jan 2016 21:37:46 +1000 Subject: [PATCH 60/71] Fix typo in non-installed mod check Fixes: d37176a Warn when a mod is requested but not installed --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index cfc84450..68242d09 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -204,7 +204,7 @@ checkConfig() { fi # Warn if any mods are requested but not installed - if [ -n "$arkserverroot" -a -a -d "${arkserverroot}/ShooterGame/Content/Mods" ]; then + if [ -n "$arkserverroot" -a -d "${arkserverroot}/ShooterGame/Content/Mods" ]; then for modid in $(getModIds); do if [ ! -f "${arkserverroot}/ShooterGame/Content/Mods/${modid}/mod.info" ]; then echo -e "[" "$RED" "ERROR" "$NORMAL" "]" "\tMod ${modid} is requested but not installed. Run 'arkmanager installmod ${modid}' to install this mod." From 425e4f07f94a8763cfdc5c464c5ff97ee067d87e Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 29 Jan 2016 22:54:25 +1000 Subject: [PATCH 61/71] Fix typo in staging directory based file removal Fixes: 74fe4c9 Remove files removed by Steam update --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 68242d09..1e3af374 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1068,7 +1068,7 @@ doUpdate() { find Engine ShooterGame linux64 -depth -print | grep -v '^ShooterGame/\(Saved\|Content/Mods\)' | while read f; do - if [ ! -e "staging/${f}" ]; then + if [ ! -e "${arkStagingDir}/${f}" ]; then if [ -f "$f" ]; then rm "${f}" else From fbd75687da15d41cabaeea3e3376f5fc35eea38a Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Tue, 2 Feb 2016 04:02:21 +1000 Subject: [PATCH 62/71] Have systemd (and upstart) run the script as the user --- tools/install.sh | 6 +++--- tools/systemd/arkmanager@.service | 1 + tools/upstart/arkmanager-instance.conf | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index 3ac4df4e..cb724f69 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -215,7 +215,7 @@ else cp systemd/arkmanager.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" sed -i "s|=/usr/libexec/arkmanager/|=${LIBEXECDIR}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" cp systemd/arkmanager@.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager@.service" - sed -i "s|=/usr/bin/|=${BINDIR}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager@.service" + sed -i "s|=/usr/bin/|=${BINDIR}/|;s|=steam$|=${steamcmd_user}|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager@.service" if [ -z "${INSTALL_ROOT}" ]; then systemctl daemon-reload systemctl enable arkmanager.service @@ -243,7 +243,7 @@ else cp systemd/arkmanager.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" sed -i "s|=/usr/libexec/arkmanager/|=${LIBEXECDIR}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" cp systemd/arkmanager@.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager@.service" - sed -i "s|=/usr/bin/|=${BINDIR}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager@.service" + sed -i "s|=/usr/bin/|=${BINDIR}/|;s|=steam$|=${steamcmd_user}|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager@.service" if [ -z "${INSTALL_ROOT}" ]; then systemctl daemon-reload systemctl enable arkmanager.service @@ -277,7 +277,7 @@ else cp systemd/arkmanager.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" sed -i "s|=/usr/libexec/arkmanager/|=${LIBEXECDIR}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager.service" cp systemd/arkmanager@.service "${INSTALL_ROOT}/etc/systemd/system/arkmanager@.service" - sed -i "s|=/usr/bin/|=${BINDIR}/|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager@.service" + sed -i "s|=/usr/bin/|=${BINDIR}/|;s|=steam$|=${steamcmd_user}|" "${INSTALL_ROOT}/etc/systemd/system/arkmanager@.service" if [ -z "${INSTALL_ROOT}" ]; then systemctl daemon-reload systemctl enable arkmanager.service diff --git a/tools/systemd/arkmanager@.service b/tools/systemd/arkmanager@.service index 49b722c7..4c92d0fe 100644 --- a/tools/systemd/arkmanager@.service +++ b/tools/systemd/arkmanager@.service @@ -2,5 +2,6 @@ Description=Daemon to start an ark server instance [Service] +User=steam ExecStart=/usr/bin/arkmanager useconfig %i run Type=simple diff --git a/tools/upstart/arkmanager-instance.conf b/tools/upstart/arkmanager-instance.conf index 0b219a48..4f203bf2 100644 --- a/tools/upstart/arkmanager-instance.conf +++ b/tools/upstart/arkmanager-instance.conf @@ -2,6 +2,8 @@ description "ARK Server Tools service" instance $service +setuid steam + env DAEMON="/usr/bin/arkmanager" exec "$DAEMON" useconfig $service run From 9c35974678957ef2eda15765d0a44ae7e0cf263a Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Wed, 3 Feb 2016 20:31:37 +1000 Subject: [PATCH 63/71] Improve mod update behaviour --- tools/arkmanager | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 40b0b29f..6de6de36 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -352,6 +352,7 @@ doBroadcastWithEcho(){ # function runSteamCMD(){ "$steamcmdroot/$steamcmdexec" +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} "$@" +quit + return $? } # @@ -1129,17 +1130,26 @@ doDownloadMod(){ local moddldir="$steamcmdroot/steamapps/workshop/downloads/$mod_appid/$modid" local dlsize=0 cd "$steamcmdroot" + rm "$steamcmdroot/workshop/appworkshop_${mod_appid}.acf" 2>/dev/null while true; do echo "Downloading mod $modid" runSteamCMD +workshop_download_item $mod_appid $modid - echo - echo "Checking mod $modid" - if [ ! -d "$moddldir" ]; then break; fi - local newsize="`du -s "$moddldir/.." | cut -f1`" - if [ $newsize -eq $dlsize ]; then break; fi - dlsize=$newsize - echo "Mod $modid not fully downloaded - retrying" + result=$? + if [ $result -eq 0 ]; then + break + else + echo + echo "Checking mod $modid" + if [ ! -d "$moddldir" ]; then break; fi + local newsize="`du -s "$moddldir/.." | cut -f1`" + if [ $newsize -eq $dlsize ]; then + echo "Mod $modid update not progressing - aborting" + return 1 + fi + dlsize=$newsize + echo "Mod $modid not fully downloaded - retrying" + fi done if [ -f "$modsrcdir/mod.info" ]; then From 1862ccd15f1e38aa7de24a042170722672562d4e Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Wed, 3 Feb 2016 21:18:58 +1000 Subject: [PATCH 64/71] Add spinner and verbose support --- tools/arkmanager | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 6de6de36..a7b67385 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -352,7 +352,28 @@ doBroadcastWithEcho(){ # function runSteamCMD(){ "$steamcmdroot/$steamcmdexec" +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} "$@" +quit - return $? +} + +function runSteamCMDspinner(){ + if [ -n "$verbose" ]; then + echo + runSteamCMD "$@" + return $? + else + runSteamCMD "$@" >/dev/null 2>&1 & + local scpid=$! + local pos=0 + local spinner=( '-' '/' '|' '\' ) + echo -n ' ... ' + while kill -0 $scpid 2>/dev/null; do + printf "\b%c" "${spinner[$pos]}" + (( pos = (pos + 1) % 4 )) + sleep 0.5 + done + echo -ne '\b \b' + wait $scpid + return $? + fi } # @@ -769,7 +790,7 @@ doStopAll(){ # install / update / download update # runSteamCMDAppUpdate(){ - runSteamCMD +force_install_dir "$1" +app_update $appid $2 + runSteamCMDspinner +force_install_dir "$1" +app_update $appid $2 } # @@ -946,13 +967,13 @@ doUpdate() { fi done - echo "$$" >"${arkserverroot}/.ark-update.lock.$$" + echo "$$" >"${arkserverroot}/.ark-update.lock.$$" 2>/dev/null while true; do - if ! ln "${arkserverroot}/.ark-update.lock.$$" "${arkserverroot}/.ark-update.lock"; then + if ! ln "${arkserverroot}/.ark-update.lock.$$" "${arkserverroot}/.ark-update.lock" 2>/dev/null; then local lockpid="$(<"${arkserverroot}/.ark-update.lock")" - if [ -n "$lockpid" ] && [ "$lockpid" != "$$" ] && kill -0 "$lockpid"; then + if [ -n "$lockpid" ] && [ "$lockpid" != "$$" ] && kill -0 "$lockpid" 2>/dev/null; then echo "Update already in progress (PID: $lockpid)" - rm -f "${arkserverroot}/.ark-update.lock.$$" + rm -f "${arkserverroot}/.ark-update.lock.$$" 2>/dev/null return 1 fi rm -f "${arkserverroot}/.ark-update.lock" @@ -994,7 +1015,7 @@ doUpdate() { rm -rf "$arkStagingDir/ShooterGame/Saved/"* fi - echo "Downloading ARK update" + echo -n "Downloading ARK update" cd "$steamcmdroot" runSteamCMDAppUpdate "$arkStagingDir" $validate if [ -d "${arkStagingDir}/steamapps/downloading/${appid}" ]; then @@ -1078,7 +1099,7 @@ doUpdate() { fi done else - echo "Performing ARK update" + echo -n "Performing ARK update" cd "$steamcmdroot" runSteamCMDAppUpdate "$arkserverroot" $validate fi @@ -1133,8 +1154,8 @@ doDownloadMod(){ rm "$steamcmdroot/workshop/appworkshop_${mod_appid}.acf" 2>/dev/null while true; do - echo "Downloading mod $modid" - runSteamCMD +workshop_download_item $mod_appid $modid + echo -n "Downloading mod $modid" + runSteamCMDspinner +workshop_download_item $mod_appid $modid result=$? if [ $result -eq 0 ]; then break @@ -1664,6 +1685,9 @@ while true; do --args) nrarg=$# ;; + --verbose) + verbose=1 + ;; --*) options+=( "$1" ) ;; From 40bd3e80a9e35962d1585ff69c0aa6cc038efe2d Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 6 Feb 2016 01:43:16 +1000 Subject: [PATCH 65/71] Remove files that have been removed in mods --- tools/arkmanager | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index a7b67385..229bf048 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1266,6 +1266,18 @@ doExtractMod(){ find "$modsrcdir" -type d -printf "$moddestdir/%P\0" | xargs -0 -r mkdir -p + find "$moddestdir" -type f ! -name '.*' -printf "%P\n" | while read f; do + if [ \( ! -f "$modsrcdir/$f" \) -a \( ! -f "$modsrcdir/${f}.z" \) ]; then + rm "$moddestdir/$f" + fi + done + + find "$moddestdir" -depth -type d -printf "%P\n" | while read d; do + if [ ! -d "$modsrcdir/$d" ]; then + rmdir "$moddestdir/$d" + fi + done + find "$modsrcdir" -type f ! \( -name '*.z' -or -name '*.z.uncompressed_size' \) -printf "%P\n" | while read f; do if [ \( ! -f "$moddestdir/$f" \) -o "$modsrcdir/$f" -nt "$moddestdir/$f" ]; then printf "%10d %s " "`stat -c '%s' "$modsrcdir/$f"`" "$f" From 30ac0c3a220f512f9d5042f1101e9122fd328013 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 6 Feb 2016 03:29:28 +1000 Subject: [PATCH 66/71] Fix the path to appworkshop_appid.acf Fixes: 9c35974 Improve mod update behaviour --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 229bf048..19b8c18d 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1151,7 +1151,7 @@ doDownloadMod(){ local moddldir="$steamcmdroot/steamapps/workshop/downloads/$mod_appid/$modid" local dlsize=0 cd "$steamcmdroot" - rm "$steamcmdroot/workshop/appworkshop_${mod_appid}.acf" 2>/dev/null + rm "$steamcmdroot/steamapps/workshop/appworkshop_${mod_appid}.acf" 2>/dev/null while true; do echo -n "Downloading mod $modid" From 21fb357f4107ab13e15fa58583911224ef146a19 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 6 Feb 2016 04:07:33 +1000 Subject: [PATCH 67/71] Warn of known issues when mod_branch=Linux --- tools/arkmanager | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 229bf048..450f7ce9 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -212,6 +212,11 @@ checkConfig() { done fi + # Warn if mod_branch=Linux + if [ "$mod_branch" == "Linux" -a -z "$nowarnmodbranch" ]; then + echo -e "[" "$YELLOW" "WARN" "$NORMAL" "]" "\tmod_branch is set to Linux. Linux mods are known to cause the server to crash. It is suggested you set mod_branch to Windows." + fi + # Service configuration # logdir if [ ! -w "$logdir" ] ; then @@ -1198,7 +1203,7 @@ isModUpdateNeeded(){ local modid=$1 local modsrcdir="$steamcmdroot/steamapps/workshop/content/$mod_appid/$modid" local moddestdir="$arkserverroot/ShooterGame/Content/Mods/$modid" - local modbranch="${mod_branch:-Linux}" + local modbranch="${mod_branch:-Windows}" for varname in "${!mod_branch_@}"; do if [ "mod_branch_$modid" == "$varname" ]; then From a8e95f9011bdc96df4b898e9c6ef9c60eb79f685 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Tue, 9 Feb 2016 07:06:05 +1000 Subject: [PATCH 68/71] Fix mod updating re-downloading mod Give up on trying to prevent steamcmd from updating every other workshop item it has downloaded. Instead, give it a certain number of retries, and check if the app's workshop downloads directory exists. --- tools/arkmanager | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 2fcdd9d6..295ea5c2 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1153,10 +1153,9 @@ getModIds(){ doDownloadMod(){ local modid=$1 local modsrcdir="$steamcmdroot/steamapps/workshop/content/$mod_appid/$modid" - local moddldir="$steamcmdroot/steamapps/workshop/downloads/$mod_appid/$modid" - local dlsize=0 + local moddldir="$steamcmdroot/steamapps/workshop/downloads/$mod_appid" cd "$steamcmdroot" - rm "$steamcmdroot/steamapps/workshop/appworkshop_${mod_appid}.acf" 2>/dev/null + retries=10 while true; do echo -n "Downloading mod $modid" @@ -1166,14 +1165,14 @@ doDownloadMod(){ break else echo - echo "Checking mod $modid" - if [ ! -d "$moddldir" ]; then break; fi - local newsize="`du -s "$moddldir/.." | cut -f1`" - if [ $newsize -eq $dlsize ]; then - echo "Mod $modid update not progressing - aborting" - return 1 + if [ ! -d "$moddldir" ]; then + echo "Mod $modid download failed" + break + fi + (( retries = retries - 1 )) + if (( retries <= 0 )); then + echo "Retries exhausted" fi - dlsize=$newsize echo "Mod $modid not fully downloaded - retrying" fi done From c1a1dc7a1a5c0b5374e2d9e43d7b70e8f169f70b Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Tue, 9 Feb 2016 22:06:16 +1000 Subject: [PATCH 69/71] Add dots progress output --- tools/arkmanager | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 295ea5c2..8c4467b5 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -146,6 +146,7 @@ export TERM=${TERM:-dumb} arkmanagerLog="arkmanager.log" # here are logged the actions performed by arkmanager arkserverLog="arkserver.log" # here is logged the output of ShooterGameServer +progressDisplayType="${progressDisplayType:-spinner}" appid="${appid:-376030}" mod_appid="${mod_appid:-346110}" arkautorestartfile="${arkautorestartfile:-ShooterGame/Saved/.autorestart}" @@ -368,11 +369,14 @@ function runSteamCMDspinner(){ runSteamCMD "$@" >/dev/null 2>&1 & local scpid=$! local pos=0 - local spinner=( '-' '/' '|' '\' ) + local spinner=( '\b-' '\b/' '\b|' '\b\\' ) + if [ "$progressDisplayType" == "dots" ]; then + spinner=( '.' ) + fi echo -n ' ... ' while kill -0 $scpid 2>/dev/null; do - printf "\b%c" "${spinner[$pos]}" - (( pos = (pos + 1) % 4 )) + echo -ne "${spinner[$pos]}" + (( pos = (pos + 1) % ${#spinner[*]} )) sleep 0.5 done echo -ne '\b \b' @@ -1704,6 +1708,12 @@ while true; do --verbose) verbose=1 ;; + --dots) + progressDisplayType=dots + ;; + --spinner) + progressDisplayType=spinner + ;; --*) options+=( "$1" ) ;; From 65c9233bc6055b6b1f280257f8809447542e1d3b Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Tue, 9 Feb 2016 22:13:27 +1000 Subject: [PATCH 70/71] Default to displaying dots when stdout is not a terminal --- tools/arkmanager | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 8c4467b5..a1be1f49 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -146,7 +146,6 @@ export TERM=${TERM:-dumb} arkmanagerLog="arkmanager.log" # here are logged the actions performed by arkmanager arkserverLog="arkserver.log" # here is logged the output of ShooterGameServer -progressDisplayType="${progressDisplayType:-spinner}" appid="${appid:-376030}" mod_appid="${mod_appid:-346110}" arkautorestartfile="${arkautorestartfile:-ShooterGame/Saved/.autorestart}" @@ -159,6 +158,7 @@ else install_datadir="${install_datadir:-${install_bindir%/*}/share/arkmanager}" fi + #--------------------- # functions #--------------------- @@ -366,6 +366,13 @@ function runSteamCMDspinner(){ runSteamCMD "$@" return $? else + if [ -z "$progressDisplayType" ]; then + if stty <&1 >/dev/null 2>&1; then + progressDisplayType=spinner + else + progressDisplayType=dots + fi + fi runSteamCMD "$@" >/dev/null 2>&1 & local scpid=$! local pos=0 From cbcf73ff687abf0361d42c907c9fae7e8974ed28 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Tue, 16 Feb 2016 13:47:06 +1000 Subject: [PATCH 71/71] Add uninstallmod and reinstallmod --- tools/arkmanager | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index a1be1f49..cc753602 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1382,6 +1382,17 @@ doInstallMod(){ fi } +# +# Removes mod from mods directory +# +doUninstallMod(){ + local modid=$1 + local moddir="$arkserverroot/ShooterGame/Content/Mods/$modid" + if [ -d "${moddir}" ]; then + rm -rf "${moddir}" + fi +} + # # Copies server state to a backup directory # @@ -1659,6 +1670,8 @@ showUsage() { echo "checkupdate Check for a new ARK server version" echo "install Install the ARK server files from steamcmd" echo "installmod Installs a mod from the Steam workshop" + echo "uninstallmod Removes the mod from the Mods directory" + echo "reinstallmod Removes and re-installs a mod in the Mods directory" echo "restart Stops the server and then starts it" echo "run Runs the server without daemonizing" echo "start Starts the server" @@ -1697,6 +1710,8 @@ while true; do # get the number of arguments for commands that take arguments case "$command" in installmod) nrarg=1; ;; + uninstallmod) nrarg=1; ;; + reinstallmod) nrarg=1; ;; broadcast) nrarg=1; ;; rconcmd) nrarg=1; ;; useconfig) nrarg=1; ;; @@ -1833,6 +1848,13 @@ while true; do installmod) doInstallMod "${args[@]}" ;; + uninstallmod) + doUninstallMod "${args[@]}" + ;; + reinstallmod) + doUninstallMod "${args[@]}" + doInstallMod "${args[@]}" + ;; backup) doBackup ;;