Jump to content

Recommended Posts

Posted (edited)

I made a simple restarter program, made for a WoW emulator known as MangOS.

It might be of some use for someone :)

Restarter application:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.1.4 (beta)
 Author:         R.Westerhof (www.drakkaa.nl)

 Script Function:
    Restarts a MangOs server
    With logging and a inifile

#ce ----------------------------------------------------------------------------



$x=0
$y=0
$crashnumber_m=-1
$crashnumber_r=-1
$backupmade=1

$time=IniRead ( "restart.ini", "Config", "Time", "320" )
$mangos_ini=IniRead ( "restart.ini", "Config", "MangOS", "mangosd.exe" )
$realmd_ini=IniRead ( "restart.ini", "Config", "Realmd", "realmd.exe" )
$mangos_path=IniRead ( "restart.ini", "Config", "Path", "c:\mangos\" )
$logging_enabled=IniRead ( "restart.ini", "Logging", "LogEnabled", "1" )
$log_filename=IniRead ( "restart.ini", "Logging", "LogName", "restartlog.txt" )
$save_number=IniRead ( "restart.ini", "AccountSave", "save_number", "1" )
$starttime=IniRead ( "restart.ini", "Config", "StartTime", "320" )



Sleep($starttime*1000)

$time=$time*1000

If $logging_enabled=1 Then
        FileWriteLine ( $log_filename, @CRLF )
    FileWriteLine ( $log_filename, TimeStamp() & " - MangOs restarter Started"  )
endif

;MainLoop

While 1
    
Sleep($time)
;wich errors window to check, and enter away.
IF WinExists ( "Microsoft Windows") Then
Send ("{Enter}")
Sleep(3000)
EndIf
IF WinExists ( "mangosd.exe - Toepassingsfout") Then
Send ("{Enter}")
Sleep(3000)
EndIf
IF WinExists ( "mangosd.exe - Application Error") Then
Send ("{Enter}")
Sleep(3000)
EndIf
IF WinExists ( "Microsoft Visual C++ Runtime Library") Then
Send ("{Enter}")
Sleep(3000)
EndIf
IF WinExists ( "mysqld-nt.exe - Application Error") Then
Send ("{Enter}")
Sleep(3000)
EndIf

;check if its time for backup
If @HOUR = 13 or @HOUR=1 Then
    $backupmade=0
EndIf
If $backupmade = 0 Then
    If @HOUR = 14 or @HOUR=2 Then
    BackupDB()
    $backupmade=1
EndIf
EndIf

;check if the server process1 exists
If ProcessExists($mangos_ini) = 0 then
    If $logging_enabled=1 Then
        $crashnumber_m+=1
        If $crashnumber_m > 0 then
            FileWriteLine ( $log_filename, TimeStamp() & " - " & $mangos_ini & " - process missing from memory. " & "Restart (" & $crashnumber_m & ")" )
        EndIf
  endif  
    Run($mangos_path & $mangos_ini)
Endif

;check if the server process2 exists
If ProcessExists($realmd_ini) = 0 then
    If $logging_enabled=1 Then
        $crashnumber_r+=1
        If $crashnumber_r > 0 Then
            FileWriteLine ( $log_filename, TimeStamp() & " - " & $realmd_ini & " - process missing from memory. " & "Restart (" & $crashnumber_r & ")" )    
        EndIf
    EndIf
     Run($mangos_path & $realmd_ini) 
endif     

Wend

;Timestamp for logging
Func TimeStamp()
    $far=@MON & "-" & @MDAY & "-" & @YEAR & " / " & @HOUR & ":" & @MIN & ":" & @SEC
Return $far
Endfunc

;backup the database and copy the files to the backup directory
 Func BackupDB()
     If $backupmade=1 Then
         return 0
     Else
         
       run("backup.bat")
     Sleep(300000)
;copy the freshly made MySQL backup files to @scriptdir \ backup dir
     Filecopy( @ScriptDir & "\" & "realmd_backup.sql", @ScriptDir & "\backup\" & "realmd_backup" & @YEAR & @MON & @MDAY & ".sql", 9)
     Filecopy( @ScriptDir & "\" & "characters_backup.sql", @ScriptDir & "\backup\" & "characters_backup" & @YEAR & @MON & @MDAY & ".sql", 9)
 EndIf
 
EndFunc

The restart.ini file:

[Config]
;howmany seconds much restarter wait to begin opening the server processes.
StartTime=60

;every how many seconds does restarter check server memory for server processes, or errors.
Time=10

;MangOS .exe name (case sensitive.)
MangOS=mangosd.exe

;RealmD .exe name (case sensitive.)
Realmd=realmd.exe

;The path of mangos, include the last \   e.g. : c:\mangos\ (case sencitive.)
Path=c:\mangos\

[Logging]

;are crashlogs enabled 1 for yes and 0 for no.
LogEnabled=1

;the filename of the crashlog.
LogName=restartlog.txt


;========== server restarter and config by www.drakkaa.nl==========

The MySql commandline backup.bat (makes a complete backup of the MangOS mysql database.)

@ECHO OFF

SET DBUSER=root
SET DBPASS=1234
SET MDBNAME=mangos
SET RDBNAME=realmd
SET CHRDBNM=characters
SET SCRIPTDEV=scriptdev2
SET MYPATH="C:\Program Files\MySQL\MySQL Server 6.0\bin\mysqldump.exe"

ECHO EXPORTING FULL BACKUP...
ECHO.
ECHO EXPORTING REALMD DB...
%MYPATH% --user=%DBUSER% --password=%DBPASS% --opt %RDBNAME% > realmd_backup.sql
ECHO EXPORTING MANGOS DB...
%MYPATH% --user=%DBUSER% --password=%DBPASS% --opt %MDBNAME% > mangos_backup.sql
ECHO EXPORTING SCRIPTDEV2 DB...
%MYPATH% --user=%DBUSER% --password=%DBPASS% --opt %SCRIPTDEV% > scriptdev2_backup.sql
ECHO EXPORTING CHARACTERS DB...
%MYPATH% --user=%DBUSER% --password=%DBPASS% --opt %CHRDBNM% > characters_backup.sql
ECHO.
ECHO COMPLETED
ECHO.

Edit: Forgot to add some checks for when the MySQL backups should be made.

Edited by WhiteCrow

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...