• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Server Tool to automatically restart the server after crash? (Windows / Linux)

Nagel

Member
May 19, 2009
22
0
Hi, I'm running pretty much custom maps and my server occasionally crashes. Wondered if someone knows a tool I can use to automatically restart the server after it crashed. I think a solution for linux is provided in the linux server thread, but since the server isn't even starting on my Linux box, I'd also like to know a tool for windows :)
 
Hi, I'm running pretty much custom maps and my server occasionally crashes. Wondered if someone knows a tool I can use to automatically restart the server after it crashed. I think a solution for linux is provided in the linux server thread, but since the server isn't even starting on my Linux box, I'd also like to know a tool for windows :)

This thread will help you, windows ver.:)
[url]http://forums.tripwireinteractive.com/showthread.php?t=10154[/URL]

Edit your bat file.


@echo off
title KF Public server
echo Look at the top of the window.
echo.
cd c:\KFServer
set GameText===== KF Public server ====
set GameCmd=C:\KFServer\system\ucc server KF-BioticsLab.rom?game=KFmod.KFGameType?VACSecured=true -log=ServerLog.log
echo %GameText%
echo.
echo This is the %GameText% Auto Runner
echo To Restart the server close the corresponding Game
echo To Shut down the server close this window.
echo.
set LogFile="%homepath%\Desktop\Logs\%GameText%.log"
echo Output is logged to %LogFile%
echo.
echo This is the command line: >>%LogFile%
echo %GameCmd% >>%LogFile%
:start
echo ReStarting %GameText%
date/t
time/t
echo ReStarting %GameText% >>%LogFile%
date/t >>%LogFile%
time/t >>%LogFile%
call %GameCmd%
goto start


This is one example, good luck.
 
  • Like
Reactions: Nagel
Upvote 0
For a more permenant solution you might look towards FireDaemon
Or a similar tool that will allow you to run your server as a windows service

FireDaemon is pretty damn simple and easy to use I must say, been using it for quite some time now.

I have 3 KF servers setup as services that automatically start and are set to hidden so I never see them.

FD just links to the bat file, any changes I make in there.
 
Upvote 0
I use ServerDoc for all my servers. Works great, and offers plenty of customization.


Damn we were posting at the same time.


I dont' use FireDaemon but the reason i dont like it is because I also run alot of hlds servers and serverdoc will also query servers and restart the server if it frove but not crashed were atleast in the past FireDaemon would not do that.
 
Upvote 0
With linux you can run a script with cron every X minutes/hours that checks if the screen process is running and if not execute the startscript of your server.
This script checks for a screen with the name "kf.one" and executes the startscript "kfstart" If you have other names you have to change it to your needs:


With linux you can run a script with cron every X minutes/hours that checks if the screen process is running and if not execute the startscript of your server.
This script checks for a screen with the name "kf.one" and executes the startscript "kfstart" If you have other names you have to change it to your needs:

Code:
#!/bin/sh
#clear
if[[ `screen -ls |grep kf.one ]]
then 
echo
else
/home/kfserver/kfstart restart
fi
 
Last edited:
Upvote 0
I have it works fine on the windows 7

Code:
@echo off
cls
echo Protecting srcds from crashes...
title log
:srcds
echo (%time%) KF server started.
start /wait ucc server KF-BioticsLab.rom?game=KFmod.KFGameType?VACSecured=true?MaxPlayers=15?AdminName=xxxx?AdminPassword=yyyy
echo (%time%) WARNING: srcds closed or crashed, restarting....
goto srcds
 
Upvote 0
With linux you can run a script with cron every X minutes/hours that checks if the screen process is running and if not execute the startscript of your server.
This script checks for a screen with the name "kf.one" and executes the startscript "kfstart" If you have other names you have to change it to your needs:


With linux you can run a script with cron every X minutes/hours that checks if the screen process is running and if not execute the startscript of your server.
This script checks for a screen with the name "kf.one" and executes the startscript "kfstart" If you have other names you have to change it to your needs:

Code:
#!/bin/sh
#clear
if[[ `screen -ls |grep kf.one ]]
then 
echo
else
/home/kfserver/kfstart restart
fi

I get the following error when I try to run the script. Any ideas?
Code:
./watch_KF1.sh: line 3: unexpected EOF while looking for matching ``'
./watch_KF1.sh: line 9: syntax error: unexpected end of file

my script:
Code:
#!/bin/sh
#clear
if[[ `screen -ls |grep KF1 ]]
then
echo
else
/AHZ-KF1.sh restart
fi
 
Upvote 0
With linux you can run a script with cron every X minutes/hours that checks if the screen process is running and if not execute the startscript of your server.
This script checks for a screen with the name "kf.one" and executes the startscript "kfstart" If you have other names you have to change it to your needs:


With linux you can run a script with cron every X minutes/hours that checks if the screen process is running and if not execute the startscript of your server.
This script checks for a screen with the name "kf.one" and executes the startscript "kfstart" If you have other names you have to change it to your needs:

Code:
#!/bin/sh
#clear
if[[ `screen -ls |grep kf.one ]]
then 
echo
else
/home/kfserver/kfstart restart
fi

another way is to do this in your startup script:
Code:
#!/bin/sh

# this allows you to exit w/ ^C. Preventing a near-infinite loop.
trap "echo 1>&2 caught SIGINT, exiting; exit 1" SIGINT

. $HOME/etc/kfdsrc # Grab all vars

cd "$DP_KFDS_SYSDIR"

server_args=${DP_KFDS_STARTING_MAP}${DP_KFDS_STARTING_ARGS}${DP_KFDS_EXTRA_ARGS}
echo "ucc-bin server ${server_args}"
./ucc-bin server ${server_args} &
sleep 5 # ick.  i hate fixed timers

# `findprog' is my 20 yro utility for finding process IDs.
# Use whatever is available to you.
# I do this to see if the command is running.
ucc_pid=$(findprog "$UCC_BIN_REAL") || {
    echo 1>&2 cannot find "$UCC_BIN_REAL's" PID
    exit 1
}

# This makes your server run at a very high priority.
sudo renice -19 $ucc_pid

# This waits for all background jobs to stop.
wait

# We're done, for whatever reason except ^C.  See trap

# Go on, do it again! How can you have your pudding if you don't eat yer meat?
exec <start-up-script>
It doesn't need a cron job and restarts immediately after the crash.
 
Upvote 0
Thanks for sharing d-bags-abound. A few things about your script immediately leap out at me:

You should use a loop instead of execing the script itself again, the reason being you are spawning a new process without freeing the current one (or a simple & at the end of the exec line would solve that) and also implicitly piping the I/O through an increasing tree of processes.

Consequence: Memory, process table and pipe consumption increase over time until the server can't take any more and crashes.

Have a look at your process tree after the script has been running for a while and you'll see this!

This becomes a real problem if the game server is consistently failing to start e.g. due to a misconfiguration. Your script won't detect this condition and continue restarting and spawning processes, effectively becoming a Linear Fork Bomb!

Finally running at -19 priority is unnecessary, will actually decrease overall performance by preempting the various helper processes that optimize I/O and scheduling in the background and can be actively bad for your system (there are several vital kernel irq daemons and other crucial system services that run at this priority out of necessity) - in summary the minimum niceness for a userland server process should be -5 and no less on most distros *

I've taken a different spin on the bash auto-restart script here that mitigates the fork bombing issue:
http://forums.tripwireinteractive.com/showthread.php?t=35610

Hope you find these comments helpful :)

* Unless you have set the affinity such that it runs realtime exclusive on a dedicated core separate from the system processes but doing such things requires a custom kernel with realtime scheduling and tick frequency, vastly complicates your setup adding many sources of problems and tbh gives negligible performance gains since the linux kernel scheduler does an excellent job nowadays if left to its own devices and so I don't know why I even mentioned it ;)
 
Last edited:
Upvote 0
I get the following error when I try to run the script. Any ideas?
Code:
./watch_KF1.sh: line 3: unexpected EOF while looking for matching ``'
./watch_KF1.sh: line 9: syntax error: unexpected end of file
my script:
Code:
#!/bin/sh
#clear
if[[ `screen -ls |grep KF1 ]]
then
echo
else
/AHZ-KF1.sh restart
fi

A `is missing sry for that. Try this:
Code:
#!/bin/sh
#clear
if[[ `screen -ls |grep KF1` ]]
then
echo
else
/AHZ-KF1.sh restart
fi
 
Upvote 0
Upvote 0