Skip to content

Commit

Permalink
Merge branch '1.6-dev' into 1.6-dev-rc
Browse files Browse the repository at this point in the history
  • Loading branch information
klightspeed committed Sep 8, 2016
2 parents c7dd01d + 658d044 commit 2f50b01
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 39 deletions.
21 changes: 16 additions & 5 deletions README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,21 @@ instances.
Installs all mods specified in the instance config into the
`ShooterGame/Content/Mods` directory

`installmod <modnum>`::
Installs the specified mod into the `ShooterGame/Content/Mods`
`uninstallmods`::
Deletes all mods from the `ShooterGame/Content/Mods` directory

`installmod <modnum>[,<modnum>[,...]]`::
Installs the specified mods into the `ShooterGame/Content/Mods`
directory

`uninstallmod <modnum>`::
Deletes the specified mod from the `ShooterGame/Content/Mods`
`uninstallmod <modnum>[,<modnum>[,...]]`::
Deletes the specified mods from the `ShooterGame/Content/Mods`
directory

`reinstallmod <modnum>`::
`removemod <modnum>[,<modnum>[,...]]`::
Deletes the specified mods from the SteamCMD workshop directory

`reinstallmod <modnum>[,<modnum>[,...]]`::
Runs the `uninstallmod` command followed by the `installmod`
command

Expand Down Expand Up @@ -396,6 +402,11 @@ The following options can be overridden on a per-instance basis:
`arkMaxBackupSizeMB`::
Limits the size of the stored backups
`arkPriorityBoost`::
Attempts to boost the priority of the ARK server.
Negative values give a higher priority, and positive values give a lower priority.
Requires `sudo` and `renice`
`msgWarnUpdateMinutes`::
`msgWarnUpdateSeconds`::
`msgWarnRestartMinutes`::
Expand Down
3 changes: 2 additions & 1 deletion netinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function doInstallFromRelease(){
echo "Latest release is ${tagname}"
echo "Getting commit for latest release..."
local commit="$(curl -s "https://api.github.com/repos/FezVrasta/ark-server-tools/git/refs/tags/${tagname}" | sed -n 's/^ *"sha": "\(.*\)",.*/\1/p')"
doUpgradeToolsFromCommit "$commit"
doInstallFromCommit "$commit"
else
echo "Unable to get latest release"
fi
Expand All @@ -82,6 +82,7 @@ function doInstallFromBranch(){
echo "Channel ${channel} not found - trying master"
doInstallFromBranch master
else
echo "Channel ${channel} not found - trying latest stable release"
doInstallFromRelease
fi
fi
Expand Down
146 changes: 113 additions & 33 deletions tools/arkmanager
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ declare -A modsrcdirs
# timestamp
#
timestamp() {
date +%T
date +"%Y-%m-%d %H:%M:%S"
}

#
Expand Down Expand Up @@ -728,7 +728,22 @@ doRun() {
exit 1
fi
echo "$$" >"${arkserverroot}/${arkmanagerpidfile}"
# $$ returns the main process, $BASHPID returns the current process
echo "$BASHPID" >"${arkserverroot}/${arkmanagerpidfile}"
if [ -f "${arkserverroot}/.ark-update.lock" ]; then
local updatepid="$(<"${arkserverroot}/.ark-update.lock")"
if kill -0 "$updatepid" >/dev/null 2>&1; then
echo "An update is currently in progress. Start aborted"
return 1
fi
fi
if [ " $* " = *" --wait "* ]; then
# This requires bash 4+
# $$ returns the main process, $BASHPID returns the current process
kill -STOP $BASHPID # wait for caller to renice us
fi
arkserveropts="$serverMap"
Expand Down Expand Up @@ -932,13 +947,25 @@ doRun() {
# start function
#
doStart() {
touch "${arkserverroot}/.startAfterUpdate"
if [ -f "${arkserverroot}/.ark-update.lock" ]; then
local updatepid="$(<"${arkserverroot}/.ark-update.lock")"
if kill -0 "$updatepid" >/dev/null 2>&1; then
echo "An update is currently in progress. Start aborted"
echo "`timestamp`: Start aborted due to running update - pid: $updatepid" >>"$logdir/$arkserverLog"
return 1
fi
fi
if isTheServerRunning; then
echo "The server is already running"
echo "`timestamp`: Start aborted due to server already running"
else
if [ "$arkAutoUpdateOnStart" == "true" ]; then
if ! [[ " $* " =~ " --noautoupdate " ]]; then
echo "Updating server"
doUpdate --update-mods
doUpdate --update-mods --no-autostart
fi
fi
Expand All @@ -948,7 +975,20 @@ doStart() {
tput sc
echo "The server is starting..."
doRun </dev/null >>"$logdir/$arkserverLog" 2>&1 & # output of this command is logged
local pid=$!
if [ -n "$arkPriorityBoost" ]; then
doRun --wait </dev/null >>"$logdir/$arkserverLog" 2>&1 & # output of this command is logged
local pid="$!"
# Wait for monitor process to suspend itself
wait
echo "Boosting priority of ark server"
sudo renice -n "$arkPriorityBoost" "$pid"
kill -CONT "$pid"
else
doRun </dev/null >>"$logdir/$arkserverLog" 2>&1 & # output of this command is logged
fi
echo "`timestamp`: start" >> "$logdir/$arkmanagerLog"
tput rc; tput ed;
echo "The server is now running, and should be up within 10 minutes"
Expand All @@ -974,6 +1014,10 @@ doStartAll(){
# stop the ARK server
#
doStop() {
if [ "$1" != "update" ]; then
rm -f "${arkserverroot}/.startAfterUpdate"
fi
if isTheServerRunning; then
local stopreason="$1"
local dowarn=
Expand All @@ -999,7 +1043,7 @@ doStop() {
fi
tput sc
echo "Stopping server..."
echo "`timestamp`: stopping" >> "$logdir/$arkmanagerLog"
echo "`timestamp`: stopping; reason: $stopreason" >> "$logdir/$arkmanagerLog"
rm -f "$arkserverroot/$arkautorestartfile"
# kill the server with the PID
PID=`getServerPID`
Expand Down Expand Up @@ -1366,12 +1410,14 @@ doWarn(){
#
doUpdate() {
local appupdate=
local bgupdate=
local updatetype=normal
local validate=
local modupdate=
local saveworld=
local downloadonly=
local nodownload=
local noautostart=
for arg in "$@"; do
case "$arg" in
Expand All @@ -1384,6 +1430,7 @@ doUpdate() {
--saveworld) saveworld=1; ;;
--update-mods) modupdate=1; ;;
--backup) arkBackupPreUpdate=true; ;;
--no-autostart) noautostart=1; ;;
--stagingdir=*) arkStagingDir="${arg#--stagingdir=}"; ;;
--downloadonly) downloadonly=1; ;;
--no-download) nodownload=1; ;;
Expand All @@ -1394,6 +1441,12 @@ doUpdate() {
esac
done
# check if the server was alive before the update so we can launch it back after the update
serverWasAlive=0
if isTheServerRunning ;then
serverWasAlive=1
fi
echo "$$" >"${arkserverroot}/.ark-update.lock.$$" 2>/dev/null
while true; do
if ! ln "${arkserverroot}/.ark-update.lock.$$" "${arkserverroot}/.ark-update.lock" 2>/dev/null; then
Expand All @@ -1410,6 +1463,8 @@ doUpdate() {
done
rm -f "${arkserverroot}/.ark-update.lock.$$"
echo "`timestamp`: checking for update; PID: $$"
if [ -n "$modupdate" ]; then
if [ -z "$nodownload" ]; then
if ! doDownloadAllMods; then
Expand Down Expand Up @@ -1461,6 +1516,11 @@ doUpdate() {
fi
fi
if [[ -f "$arkserverroot/$arkautorestartfile" && "$arkserverroot/$arkautorestartfile" -ot "${arkserverroot}/steamapps/appmanifest_${appid}.acf" ]]; then
echo "Server was updated while it was running"
bgupdate=1
fi
if [ -n "$downloadonly" ]; then
if [ -n "$appupdate" -a -n "$arkStagingDir" -a "$arkStagingDir" != "$arkserverroot" ]; then
echo "Server update downloaded"
Expand All @@ -1469,7 +1529,7 @@ doUpdate() {
echo "Mod update downloaded"
fi
echo "Not applying update - download-only enabled"
elif [ -n "$appupdate" -o -n "$modupdate" ]; then
elif [ -n "$appupdate" -o -n "$modupdate" -o -n "$bgupdate" ]; then
arkversion="$(<"$arkserverroot/version.txt")"
if isTheServerRunning; then
if [ "$updatetype" == "safe" ]; then
Expand All @@ -1491,12 +1551,6 @@ doUpdate() {
fi
fi
# check if the server was alive before the update so we can launch it back after the update
serverWasAlive=0
if isTheServerRunning ;then
serverWasAlive=1
fi
if [ -n "$saveworld" ]; then
echo "Saving world"
doSaveWorld
Expand Down Expand Up @@ -1555,17 +1609,23 @@ doUpdate() {
fi
done
fi
# we restart the server only if it was started before the update
if [ $serverWasAlive -eq 1 ]; then
doStart --noautoupdate
fi
else
echo "Your server is already up to date! The most recent version is ${bnumber}."
echo "`timestamp`: No update needed." >> "$logdir/update.log"
fi;
rm -f "${arkserverroot}/.ark-update.lock"
if ! isTheServerRunning; then
# we restart the server only if it was started before the update
if [ -z "$noautostart" ]; then
if [ $serverWasAlive -eq 1 ] || [ -f "${arkserverroot}/.startAfterUpdate" ]; then
rm -f "${arkserverroot}/.startAfterUpdate"
rm -f "${arkserverroot}/.ark-update.lock"
doStart --noautoupdate
fi
fi
fi
}
#
Expand Down Expand Up @@ -1883,16 +1943,17 @@ doExtractMod(){
# Downloads mod and installs it into mods directory
#
doInstallMod(){
local modid=$1
if [ -f "$steamcmdroot/steamapps/workshop/appworkshop_${mod_appid}.acf" ]; then
sed -i "/^\\t\\t\"${modid}\"/,/^\\t\\t}/d" "$steamcmdroot/steamapps/workshop/appworkshop_${mod_appid}.acf"
fi
local modid
for modid in "${1//,/ }"; do
if [ -f "$steamcmdroot/steamapps/workshop/appworkshop_${mod_appid}.acf" ]; then
sed -i "/^\\t\\t\"${modid}\"/,/^\\t\\t}/d" "$steamcmdroot/steamapps/workshop/appworkshop_${mod_appid}.acf"
fi
if doDownloadMod $modid; then
doExtractMod $modid
echo "Mod $modid installed"
fi
if doDownloadMod $modid; then
doExtractMod $modid
echo "Mod $modid installed"
fi
done
}
#
Expand All @@ -1904,15 +1965,32 @@ doInstallAllMods(){
done
}
#
# Removes all mods from the mods directory
#
doUninstallAllMods(){
for modid in $(getModIds); do
if [[ "$modid" != "111111111" && "$modid" != "TheCenter" ]]; then
doUninstallMod "$modid"
fi
done
}
#
# Removes mod from mods directory
#
doUninstallMod(){
local modid=$1
local moddir="$arkserverroot/ShooterGame/Content/Mods/$modid"
if [ -d "${moddir}" ]; then
rm -rf "${moddir}"
fi
local modid
for modid in "${1//,/ }"; do
local moddir="$arkserverroot/ShooterGame/Content/Mods/$modid"
local modfile="$arkserverroot/ShooterGame/Content/Mods/${modid}.mod"
if [ -d "${moddir}" ]; then
rm -rf "${moddir}"
fi
if [ -f "${modfile}" ]; then
rm -f "$modfile"
fi
done
}
#
Expand Down Expand Up @@ -2621,6 +2699,9 @@ main(){
installmods)
doInstallAllMods
;;
uninstallmods)
doUninstallAllMods
;;
uninstallmod)
doUninstallMod "${args[@]}"
;;
Expand Down Expand Up @@ -2672,10 +2753,9 @@ main(){
sleep 1
for instance in "${instances[@]}"; do
(
echo "`timestamp`: restart" >> "$logdir/$arkmanagerLog"
useConfig "$instance"
doStart "${options[@]}"
echo "`timestamp`: start" >> "$logdir/$arkmanagerLog"
echo "`timestamp`: restart" >> "$logdir/$arkmanagerLog"
)
done
fi
Expand Down

0 comments on commit 2f50b01

Please sign in to comment.