Alliedassault           
FAQ Calendar
Go Back   Alliedassault > Lounge > Tech Questions & Problems
Reload this Page Server restart / log archive scripts for Windows MOH:AA
Tech Questions & Problems Ask our resident experts about any military shooter game server administration and other technical issues.

Reply
 
Thread Tools Display Modes
Server restart / log archive scripts for Windows MOH:AA
Old
  (#1)
Shockwave is Offline
Junior Member
 
Posts: 8
Join Date: Nov 2002
Location: Rochester, NY
 Send a message via ICQ to Shockwave  
Default Server restart / log archive scripts for Windows MOH:AA - 12-18-2002, 01:53 PM

Automatically restarting a game server when it dies and preserving the log data it generates for statistics programs are two common issues facing server administrators. I have spent some time tinkering with scripts for Windows so here's what I have been able to piece together.

Here is a batch file you can use to automatically restart your game server:

[code:c728a]@echo off

REM This batch file will automatically restart the game server and archive its logs.

echo Starting game server...
:LOOP

REM
REM Edit to reflect the startup program and options you require
REM
START /w "MOHAA_server.exe" +set dedicated 1 +set cheats 0 +set ui_console 1 +set g_gametype 2 +set sv_maxclients 24 +set developer 2 +map dm/mohdm1 +exec server.cfg

REM
REM Execute the batch file to archive the game log
REM
echo Archiving log file...
call log.bat

REM
REM Pause for 10 seconds before restarting to allow the user to abort
REM
echo Type Ctrl-C in the next 10 seconds to exit...
type nul | choice.com /n /cy /ty,10 >nul
echo Restarting server...
goto LOOP[/code:c728a]

Cut and paste this code into a file named restart.bat in your MOHAA directory. You can then make it easy to execute by creating a shortcut that points to it. Be sure to modify the START line to reflect the parameters you use on your command line currently.

As you can see in the code sample above, there is a line that links to another batch file:

[code:c728a]call log.bat[/code:c728a]

This batch file should be executed only if you care about saving your game server log files. If you don't want to keep them, just remove this section:

[code:c728a]REM
REM Execute the batch file to archive the game log
REM
echo Archiving log file...
call log.bat[/code:c728a]

If you want to archive your log files, then the above script is fine the way it is. You just need to create the batch file that does the archiving. It's called log.bat and it employs some trickery in order to get unique file names each time the game server log is archived. This is because of limitations of DOS batch files themselves. Here is the code:

[code:c728a]@echo off

REM This batch file creates copies of a log file named "qconsole.log" using
REM an incrementing counter file for the creation of unique filenames. All
REM processing takes place in the directory where this script resides.

REM add another "X" to the counter file
echo X >> counter.txt

REM Count the number of lines in the counter file and save the result in a
REM temporary file
type counter.txt | find /c "X" > temp.txt

REM Run compare function to generate output containing the number of lines
REM that are different between a null file and our temporary file and pipe
REM it through the date command looking for the line from the output that
REM contains the number of different lines. Save that line to a temporary
REM batch file.
fc temp.txt nul /lb1 /n | date | find "1:" > temp.bat

REM Since the first word on the only line in our temporary batch file is the
REM word "Enter" because of how the date command output is formatted, we can
REM use that to our advantage. Create a batch file called "enter.bat" which
REM will be called when we execute temp.bat and use it to assign the 5th
REM command line argument as a part of a unique filename. The 5th command
REM line argument will be the line count from the counter file.

REM Generate the command to create an archived copy of the current game log
echo copy main\qconsole.log main\arch%%5.log > enter.bat

REM execute batch file to archive log data
call temp.bat

REM Add current game log data to the end of the statistics log
echo Adding data to statistics log...
type main\qconsole.log >> main\stats.log

REM remove all temporary files
del temp.txt > nul
del temp.bat > nul
del enter.bat > nul

REM indicate processing is complete
echo:
echo Log file archive complete
echo:[/code:c728a]

Cut and paste this code into a file named log.bat in your MOHAA directory. This script assumes that you are using the default log name of qconsole.log and the default log directory MOHAA\main. If you have altered either of these values for your server, you'll have to adjust the script accordingly. The script will create a file called counter.txt in your MOHAA directory. It is used to keep track of the next sequence number to use when creating a log archive. If you delete or rename this file, the archive logic will start over again with number 1. Game server log archives will be created with the following naming convention:

arch1.log
arch2.log
arch3.log
...


The log archive script not only makes a copy of the game server log using a unique name but it also adds the data to a file called stats.log in the MOHAA\main directory. If you are using a statistics program, you can simply point it at this file to get all of your raw data because each time the server is restarted, its log data is added to the end of this file. Because the script also keeps a copy of each game server log, you can build an unlimited number of custom statistics files by combining only the archives of the log files you want to analyze. This can be handy if you want to show weekly or monthly statistics in addition to a grand total.

With these two scripts you can make your job of managing your Windows game server a little easier. Enjoy!
  
Reply With Quote
Old
  (#2)
oop is Offline
Junior Member
 
Posts: 5
Join Date: Aug 2002
 Send a message via ICQ to oop  
Default 12-18-2002, 03:16 PM

I use a similar type script. But I add it as a PreService executable on FireDaemon so basically whenever the server starts/restarts, the existing qconsole.log gets renamed to something like qconsole-Tue-12-17-2002-9h00pm.log

renameConsole.bat:

@echo off
for /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set weekday=%%a& set month=%%b& set day=%%c& set year=%%d)
for /f "tokens=1-2 delims=: " %%d in ('time /t') do (set hour=%%d& set minutes=%%e)
ren qconsole.log "qconsole-%weekday%-%month%-%day%-%year%-%hour%h%minutes%m.log"
  
Reply With Quote
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.12 by ScriptzBin
Copyright ©2000 - 2025, vBulletin Solutions Inc.
vBulletin Skin developed by: vBStyles.com
© 1998 - 2007 by Rudedog Productions | All trademarks used are properties of their respective owners. All rights reserved.