• 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 auto restart batch with backup

kingkong

Grizzled Veteran
Jun 26, 2009
442
17
after many lost logs due to crashes/batch restarts, I decided to add a backup function to the nice batch script I've been using, originated from ButchCassidy of TWB found here over at the RO forums. it's been tested for a while and seems pretty sound, though I have added a bunch of features to it since then, and my server has been oddly stable recently.

all functions should work fine with any nt5+ windows os. the idea behind the way I have organised it is, that it should work with any conventional kf-ucc install, no additional config required. only thing you may need to edit is the command line, same like you would for the default kf_server_launcher.bat. simply paste it into KFserver.bat or somesuch, drop into the kf system directory and you're set. then create shortcuts to it elsewhere or edit the log locations further to your preference.

what it does:

- check for ucc.exe (make sure it's run in proper dir)
- create a new .\logs dir in system for all batch logs if one does not exist
- log each start/restart
- backup current log on each start/restart in yymmdd-hhmmss format
- auto restart on exit/error

caveats:

- this is not a rotation script, I considered that but there are situations where your ucc might loop on restart (ie. busted mutators, bad maps/configs, etc.) which would then erase your logs again.
- since there is no rotation you will have to watch out for the log bloat, ie. problem maps/mutators that generate a ton of warnings/errors (eg. kf-asylum), and reclaim space if it gets out of hand. it's done this way so that you will always have a chance to inspect them, and provide info if you need help.
- all variables point to relative locations, so if you want to run it elsewhere you will of course need to modify it accordingly

command line section in red, adjust it to your needs if you have custom settings that need to be run on start.

Code:
@echo off

:: batch title and logs

title=Killing Floor Server
set "_runStat="
set _servBat=KFserver
set _servLog=.\logs\%_servBat%.bat.log
set _gameLog=.\logs\%_servBat%.log

:: server command line

set _gameCmd=[COLOR=Red]ucc server kf-westlondon.rom?game=KFmod.KFGameType?VACSecured=true?MaxPlayers=6[/COLOR]
set _gameCmd=%_gameCmd% -log=%_gameLog%

echo ::
echo :: This batch will autorun %_servBat%.
echo :: -to restart %_servBat%, end the ucc server task.
echo :: -to shut down %_servBat%, ctrl-c or close this window.
echo ::

if exist ucc.exe (echo :: %_servBat% initializing...) else (echo :: ucc server not found! & echo :: This batch is to be run in the KF system directory. & goto:eof) 

:: log server start/create batch log

echo ::
echo :: Output logged to %_servLog%
if exist %_servLog% (echo ::%_servBat% Start:: >>%_servLog%) else (md logs & echo ::%_servBat% Start:: >%_servLog%)
echo %_gameCmd% >>%_servLog%

:: start/restart server

:start

:: backup last server log

echo ::
echo :: Backup %_gameLog:.\logs\=%...
set _logTime=%_servBat%-%DATE:/=-%_%TIME:~0,2%.%TIME:~3,2%.log
set _logTime=%_logTime: =0%
if exist %_gameLog% (ren %_gameLog% %_logTime% & echo :: %_logTime% & echo :: Backup complete.) else (echo :: No log to backup.)
echo ::

:: log batch restart

if defined _runStat (echo :: Restart %_servBat%)
echo :: %date%
echo :: %time: =0%
echo ::
if defined _runStat (echo :Restart %_servBat%: >>%_servLog%)
if exist .\logs\%_logTime% (echo %_logTime% >>%_servLog%) else (echo No log to backup. >>%_servLog%)
echo %date% >>%_servLog%
echo %time: =0% >>%_servLog%
set "_logTime="

:: run the server

call %_gameCmd%
set _runStat=1

:: restart on exit/error

goto start
::
 
Last edited:
Your date & time stamps for the log file come out as the following on my Server 2003 box (UK locale)

Code:
KFserver-1/01-140200.log

Which as you probably already spotted won't create a valid filename for the log file.

I've modified that line in the command script to the following:

Code:
set _logTime=%_servBat%-%DATE:/=-%_%TIME:~0,2%.%TIME:~3,2%.log

which outputs something akin to

Code:
KFserver-11-01-2011_14.01.log

and should work fine regardless of system locale.

Also I don't like that it stamps the current time & date on the log file when it creates a new one rather than the time & date when the log file began but I'll look at that some other time. Otherwise this is a very useful script & thanks for posting it :)
 
  • Like
Reactions: kingkong
Upvote 0
Your date & time stamps for the log file come out as the following on my Server 2003 box (UK locale)

Code:
KFserver-1/01-140200.log
Which as you probably already spotted won't create a valid filename for the log file.

I've modified that line in the command script to the following:

Code:
set _logTime=%_servBat%-%DATE:/=-%_%TIME:~0,2%.%TIME:~3,2%.log
which outputs something akin to

Code:
KFserver-11-01-2011_14.01.log
and should work fine regardless of system locale.

Also I don't like that it stamps the current time & date on the log file when it creates a new one rather than the time & date when the log file began but I'll look at that some other time. Otherwise this is a very useful script & thanks for posting it :)

thanks good catch, totally forgot about localisation here.

use of the file creation time was intentional, I prefer to record the system operation itself rather than actual log time.
 
Upvote 0
Hello everyone I'm a little confused to implement this script rather very utile.Moi I add the script in KF_Server_Launcher.bat but apparently must miss something because my srv does not restart by itself
@echo off :: batch title and logs title=Killing Floor Server set "_runStat=" set _servBat=KFserver set _servLog=.\logs\%_servBat%.bat.log set _gameLog=.\logs\%_servBat%.log :: server command line set _gameCmd=[COLOR=Red said:
ucc server kf-westlondon.rom?game=KFmod.KFGameType?VACSecured=true?MaxPlayers=6[/COLOR]
set _gameCmd=%_gameCmd% -log=%_gameLog%

echo ::
echo :: This batch will autorun %_servBat%.
echo :: -to restart %_servBat%, end the ucc server task.
echo :: -to shut down %_servBat%, ctrl-c or close this window.
echo ::

if exist ucc.exe (echo :: %_servBat% initializing...) else (echo :: ucc server not found! & echo :: This batch is to be run in the KF system directory. & goto:eof)

:: log server start/create batch log

echo ::
echo :: Output logged to %_servLog%
if exist %_servLog% (echo ::%_servBat% Start:: >>%_servLog%) else (md logs & echo ::%_servBat% Start:: >%_servLog%)
echo %_gameCmd% >>%_servLog%

:: start/restart server

:start

:: backup last server log

echo ::
echo :: Backup %_gameLog:.\logs\=%...
set _logTime=%_servBat%-%DATE:/=-%_%TIME:~0,2%.%TIME:~3,2%.log
set _logTime=%_logTime: =0%
if exist %_gameLog% (ren %_gameLog% %_logTime% & echo :: %_logTime% & echo :: Backup complete.) else (echo :: No log to backup.)
echo ::

:: log batch restart

if defined _runStat (echo :: Restart %_servBat%)
echo :: %date%
echo :: %time: =0%
echo ::
if defined _runStat (echo :Restart %_servBat%: >>%_servLog%)
if exist .\logs\%_logTime% (echo %_logTime% >>%_servLog%) else (echo No log to backup. >>%_servLog%)
echo %date% >>%_servLog%
echo %time: =0% >>%_servLog%
set "_logTime="

:: run the server

call %_gameCmd%
set _runStat=1

:: restart on exit/error

goto start
::
 
Upvote 0
My server right now don't exit it just freezes saying this

serverfreeze.PNG


i looked at the .bat file and under the ucc line it has pause so i removed that and it still pauses/freezes doing the above.
 
Last edited:
Upvote 0
Wow, this actually works! Thanks - I do have one question - when the server doesn't crash, the UCC.log file can get pretty big if it's been going on 24/7 since you last started it - how do you truncate or at least cut off the bloat lines out to save space and quicker reading of the file as it takes longer to open a larger file than it is to open a smaller one?

For example when I opened the UCC.log from my dedicated server, I see a bunch of these:
Code:
 Log: STEAMAUTH : Sending updated server details - Western Australia |Whitelisted/Greylisted maps and modes| The Friendly Fire (TFF - SS) 0 | 6

Which pretty much covers the entire file, almost. Perhaps a way to truncate that down to maybe
Code:
 Log: STEAMAUTH : Sending updated server details - Western Australia |Whitelisted/Greylisted maps and modes| The Friendly Fire (TFF - SS) 0 | 6
. . . x1000 times (or however many copies of this exact same line repeats itself after this first one)

.
.
.
 Log: Game class is 'KFGameType'
.

.

.
Log: STEAMAUTH : Sending updated server details - Western Australia |Whitelisted/Greylisted maps and modes| The Friendly Fire (TFF - SS) 0 | 6  
. . . x236 times (or however many copies of this exact same line repeats itself after this first one)

For example.
 
Last edited:
Upvote 0