Restart server if necessary after update check

This commit is contained in:
Ben Peddell 2016-08-31 16:27:48 +10:00
parent e0ab6c98ef
commit a46ef5ad23

View File

@ -881,12 +881,14 @@ doStart() {
local updatepid="$(<"${arkserverroot}/.ark-update.lock")" local updatepid="$(<"${arkserverroot}/.ark-update.lock")"
if kill -0 "$updatepid" >/dev/null 2>&1; then if kill -0 "$updatepid" >/dev/null 2>&1; then
echo "An update is currently in progress. Start aborted" echo "An update is currently in progress. Start aborted"
echo "`timestamp`: Start aborted due to running update - pid: $updatepid" >>"$logdir/$arkserverLog"
return 1 return 1
fi fi
fi fi
if isTheServerRunning; then if isTheServerRunning; then
echo "The server is already running" echo "The server is already running"
echo "`timestamp`: Start aborted due to server already running"
else else
if [ "$arkAutoUpdateOnStart" == "true" ]; then if [ "$arkAutoUpdateOnStart" == "true" ]; then
if ! [[ " $* " =~ " --noautoupdate " ]]; then if ! [[ " $* " =~ " --noautoupdate " ]]; then
@ -969,7 +971,7 @@ doStop() {
fi fi
tput sc tput sc
echo "Stopping server..." echo "Stopping server..."
echo "`timestamp`: stopping" >> "$logdir/$arkmanagerLog" echo "`timestamp`: stopping; reason: $stopreason" >> "$logdir/$arkmanagerLog"
rm -f "$arkserverroot/$arkautorestartfile" rm -f "$arkserverroot/$arkautorestartfile"
# kill the server with the PID # kill the server with the PID
PID=`getServerPID` PID=`getServerPID`
@ -1364,6 +1366,12 @@ doUpdate() {
esac esac
done 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 echo "$$" >"${arkserverroot}/.ark-update.lock.$$" 2>/dev/null
while true; do while true; do
if ! ln "${arkserverroot}/.ark-update.lock.$$" "${arkserverroot}/.ark-update.lock" 2>/dev/null; then if ! ln "${arkserverroot}/.ark-update.lock.$$" "${arkserverroot}/.ark-update.lock" 2>/dev/null; then
@ -1380,6 +1388,8 @@ doUpdate() {
done done
rm -f "${arkserverroot}/.ark-update.lock.$$" rm -f "${arkserverroot}/.ark-update.lock.$$"
echo "`timestamp`: checking for update; PID: $$"
if [ -n "$modupdate" ]; then if [ -n "$modupdate" ]; then
if [ -z "$nodownload" ]; then if [ -z "$nodownload" ]; then
if ! doDownloadAllMods; then if ! doDownloadAllMods; then
@ -1461,12 +1471,6 @@ doUpdate() {
fi fi
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 if [ -n "$saveworld" ]; then
echo "Saving world" echo "Saving world"
doSaveWorld doSaveWorld
@ -1525,20 +1529,21 @@ doUpdate() {
fi fi
done done
fi fi
rm -f "${arkserverroot}/.ark-update.lock"
# we restart the server only if it was started before the update
if [ $serverWasAlive -eq 1 ] || [ -f "${arkserverroot}/.startAfterUpdate" ]; then
rm -f "${arkserverroot}/.startAfterUpdate"
rm -f "${arkserverroot}/.ark-update.lock"
doStart --noautoupdate
fi
else else
echo "Your server is already up to date! The most recent version is ${bnumber}." echo "Your server is already up to date! The most recent version is ${bnumber}."
echo "`timestamp`: No update needed." >> "$logdir/update.log" echo "`timestamp`: No update needed." >> "$logdir/update.log"
fi; fi;
rm -f "${arkserverroot}/.ark-update.lock" rm -f "${arkserverroot}/.ark-update.lock"
if ! isTheServerRunning; then
# we restart the server only if it was started before the update
if [ $serverWasAlive -eq 1 ] || [ -f "${arkserverroot}/.startAfterUpdate" ]; then
rm -f "${arkserverroot}/.startAfterUpdate"
rm -f "${arkserverroot}/.ark-update.lock"
doStart --noautoupdate
fi
fi
} }
# #
@ -2642,10 +2647,9 @@ main(){
sleep 1 sleep 1
for instance in "${instances[@]}"; do for instance in "${instances[@]}"; do
( (
echo "`timestamp`: restart" >> "$logdir/$arkmanagerLog"
useConfig "$instance" useConfig "$instance"
doStart "${options[@]}" doStart "${options[@]}"
echo "`timestamp`: start" >> "$logdir/$arkmanagerLog"
echo "`timestamp`: restart" >> "$logdir/$arkmanagerLog"
) )
done done
fi fi