Merge pull request #203 from klightspeed/1.4-dev#fixautorestart

Fix autorestart
This commit is contained in:
Fez Vrasta 2015-09-28 12:48:51 +02:00
commit 7992274860

View File

@ -461,22 +461,28 @@ doRun() {
"$arkserverroot/$arkserverexec" "$arkserveropts" "${arkextraopts[@]}" & "$arkserverroot/$arkserverexec" "$arkserveropts" "${arkextraopts[@]}" &
# Grab the server PID # Grab the server PID
serverpid=$! serverpid=$!
echo "`timestamp`: Server PID: $serverpid"
# Disable auto-restart so we don't get caught in a restart loop # Disable auto-restart so we don't get caught in a restart loop
rm "$arkserverroot/$arkautorestartfile" rm -f "$arkserverroot/$arkautorestartfile"
restartserver=0 restartserver=0
sleep 5
while true; do while true; do
# Grab the current server PID # Grab the current server PID
local pid="`getServerPid`" local pid="`getServerPID`"
if [ "$pid" == "$serverpid" ]; then if [ "$pid" == "$serverpid" ]; then
# Check if the server has fully started if [ "$restartserver" -eq 0 ]; then
if ! isTheServerUp; then # Check if the server has fully started
# Enable auto-restart if the server is up if ! isTheServerUp; then
echo "`timestamp`: server is up" # Enable auto-restart if the server is up
touch "$arkserverroot/$arkautorestartfile" echo "`timestamp`: server is up"
restartserver=1 touch "$arkserverroot/$arkautorestartfile"
restartserver=1
fi
fi fi
else else
echo "`timestamp`: Bad PID '$pid'; expected '$serverpid'"
if [ "$pid" != "" ]; then if [ "$pid" != "" ]; then
# Another instance must be running - disable autorestart # Another instance must be running - disable autorestart
restartserver=0 restartserver=0
@ -491,7 +497,11 @@ doRun() {
echo "`timestamp`: exited with status $?" echo "`timestamp`: exited with status $?"
# doStop will remove the autorestart file # doStop will remove the autorestart file
if [ "$restartserver" -ne 0 -a -f "$arkserverroot/$arkautorestartfile" ]; then if [ ! -f "$arkserverroot/$arkautorestartfile" ]; then
restartserver=0
fi
if [ "$restartserver" -ne 0 ]; then
echo "`timestamp`: restarting server" echo "`timestamp`: restarting server"
fi fi
done done
@ -537,11 +547,12 @@ doStop() {
tput sc tput sc
echo "Stopping server..." echo "Stopping server..."
echo "`timestamp`: stopping" >> "$logdir/$arkmanagerLog" echo "`timestamp`: stopping" >> "$logdir/$arkmanagerLog"
rm -f "$arkserverroot/$arkautorestartfile"
# kill the server with the PID # kill the server with the PID
PID=`getServerPID` PID=`getServerPID`
kill -INT $PID kill -INT $PID
for (( i = 0; i < 10; i++ )); do for (( i = 0; i < 20; i++ )); do
sleep 1 sleep 1
if ! isTheServerRunning; then if ! isTheServerRunning; then
break break
@ -551,7 +562,6 @@ 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