mirror of
https://github.com/eliasstepanik/ark-ac-server-tools.git
synced 2026-01-24 23:38:28 +00:00
Merge pull request #169 from klightspeed/1.4-dev#autorestart
Add server auto-restart
This commit is contained in:
commit
be45bdfad8
@ -44,6 +44,7 @@ arkserverLog="arkserver.log" # here is logged the output of ShooterGameServer
|
|||||||
|
|
||||||
appid="${appid:-376030}"
|
appid="${appid:-376030}"
|
||||||
mod_appid="${mod_appid:-346110}"
|
mod_appid="${mod_appid:-346110}"
|
||||||
|
arkautorestartfile="${arkautorestartfile:-ShooterGame/Saved/.autorestart}"
|
||||||
|
|
||||||
# Script version
|
# Script version
|
||||||
arkstVersion="1.3"
|
arkstVersion="1.3"
|
||||||
@ -338,8 +339,61 @@ doRun() {
|
|||||||
echo "`timestamp`: start"
|
echo "`timestamp`: start"
|
||||||
# set max open files limit before we start the server
|
# set max open files limit before we start the server
|
||||||
ulimit -n $maxOpenFiles
|
ulimit -n $maxOpenFiles
|
||||||
"$arkserverroot/$arkserverexec" "$arkserveropts" "${arkextraopts[@]}"
|
|
||||||
echo "`timestamp`: exited with status $?"
|
serverpid=0
|
||||||
|
restartserver=1
|
||||||
|
|
||||||
|
# Shutdown the server when we are terminated
|
||||||
|
shutdown_server(){
|
||||||
|
restartserver=0
|
||||||
|
rm "$arkserverroot/$arkautorestartfile"
|
||||||
|
if [ "$serverpid" -ne 0 ]; then
|
||||||
|
kill -INT $serverpid
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
trap shutdown_server INT TERM
|
||||||
|
|
||||||
|
# Auto-restart loop
|
||||||
|
while [ $restartserver -ne 0 ]; do
|
||||||
|
# Put the server process into the background so we can monitor it
|
||||||
|
"$arkserverroot/$arkserverexec" "$arkserveropts" "${arkextraopts[@]}" &
|
||||||
|
# Grab the server PID
|
||||||
|
serverpid=$!
|
||||||
|
# Disable auto-restart so we don't get caught in a restart loop
|
||||||
|
rm "$arkserverroot/$arkautorestartfile"
|
||||||
|
restartserver=0
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
# Grab the current server PID
|
||||||
|
local pid="`getServerPid`"
|
||||||
|
if [ "$pid" == "$serverpid" ]; then
|
||||||
|
# Check if the server has fully started
|
||||||
|
if ! isTheServerUp; then
|
||||||
|
# Enable auto-restart if the server is up
|
||||||
|
echo "`timestamp`: server is up"
|
||||||
|
touch "$arkserverroot/$arkautorestartfile"
|
||||||
|
restartserver=1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ "$pid" != "" ]; then
|
||||||
|
# Another instance must be running - disable autorestart
|
||||||
|
restartserver=0
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
|
||||||
|
# Wait on the now-dead process to reap it and get its return status
|
||||||
|
wait $serverpid
|
||||||
|
echo "`timestamp`: exited with status $?"
|
||||||
|
|
||||||
|
# doStop will remove the autorestart file
|
||||||
|
if [ "$restartserver" -ne 0 -a -f "$arkserverroot/$arkautorestartfile" ]; then
|
||||||
|
echo "`timestamp`: restarting server"
|
||||||
|
fi
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -396,6 +450,7 @@ doStop() {
|
|||||||
if isTheServerRunning; then
|
if isTheServerRunning; then
|
||||||
tput rc
|
tput rc
|
||||||
echo "Killing server..."
|
echo "Killing server..."
|
||||||
|
rm "$arkserverroot/$arkautorestartfile"
|
||||||
kill -KILL $PID
|
kill -KILL $PID
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@ arkserverroot="/home/steam/ARK" # path of yo
|
|||||||
arkserverexec="ShooterGame/Binaries/Linux/ShooterGameServer" # name of ARK server executable
|
arkserverexec="ShooterGame/Binaries/Linux/ShooterGameServer" # name of ARK server executable
|
||||||
arkbackupdir="/home/steam/ARK-Backups" # path to backup directory
|
arkbackupdir="/home/steam/ARK-Backups" # path to backup directory
|
||||||
arkwarnminutes="60" # number of minutes to warn players when using update --warn
|
arkwarnminutes="60" # number of minutes to warn players when using update --warn
|
||||||
|
arkautorestartfile="ShooterGame/Saved/.autorestart" # path to autorestart file
|
||||||
|
|
||||||
# Update warning messages
|
# Update warning messages
|
||||||
# Modify as desired, putting the %d replacement operator where the number belongs
|
# Modify as desired, putting the %d replacement operator where the number belongs
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user