Last active
January 11, 2021 20:33
-
-
Save korzhyk/d3091fe5974d32b2d0abeb2aad10e815 to your computer and use it in GitHub Desktop.
DayZ Standalone server startup script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
[HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error Reporting] | |
"DontShowUI"=dword:00000001 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
cls | |
:: Configuration section | |
set basePath=%~dp0 | |
set watch=DayZ Server | |
set args=-adminlog -netlog -freezecheck -cpuCount=2 -port=2302 | |
set ConfigPath=%basePath%\serverDZ.cfg | |
set BattleEyePath=%basePath%\battleye | |
set ProfilesPath=%basePath%\profiles | |
title %watch% Watchdog at %basePath% | |
Pushd "%basePath%" | |
:watchdog | |
echo (%time%) %watch% starting. | |
start "%watch%" /wait "DayZServer_x64.exe" -config="%ConfigPath%" -profiles="%ProfilesPath%" -BEpath="%BattleEyePath%" %args% | |
echo (%time%) %watch% closed or crashed, restarting. | |
ping 127.0.0.1 -n 4 > nul | |
goto watchdog |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$regItem = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 223350" | |
$Name = $regItem.DisplayName | |
$RootPath = $regItem.InstallLocation | |
$Executable = "$RootPath\DayZServer_x64.exe" | |
$ConfigFile = 'serverDZ.cfg' | |
$LogFile = "$RootPath\serverDZCustom.log" | |
$Arguments = "-adminlog -netlog -freezecheck -cpuCount=2 -port=2302 -config=$RootPath\$ConfigFile -profiles=$RootPath\profiles -BEpath=$RootPath\battleye" | |
$WatchDogInterval = 5 | |
$host.ui.RawUI.WindowTitle = "$name Watchdog" | |
function Write-Log { | |
Param( | |
$Message, | |
$Path = $LogFile | |
) | |
function TS {Get-Date -Format 'hh:mm:ss'} | |
Write-Host "[$(TS)] ${Name}: $Message" # | Tee-Object -FilePath $Path -Append | Write-Verbose | |
} | |
function Start-Server { | |
Param( | |
$Executable, | |
$Arguments | |
) | |
Write-Log "starting - $Executable $Arguments" | |
$Running = Start-Process -FilePath $Executable -ArgumentList $Arguments -PassThru | |
Write-Log "running with PID: $($Running.Id)" | |
return $Running | |
} | |
function Kill-Server { | |
Param($ServerProcess) | |
if ($ServerProcess) { | |
$ServerProcess.kill() | |
Write-Log "status = killed" | |
} | |
} | |
While (1) { | |
if ($ServerProcess) { | |
# Update server proc | |
$ServerProcess = Get-Process -Id $ServerProcess.Id -ErrorAction SilentlyContinue | |
} | |
if (-not $ServerProcess) { | |
Write-Log "status = not running: start" | |
$ServerProcess = Start-Server | |
} elseif (-not ($ServerProcess.MainWindowHandle -and $ServerProcess.Responding)) { | |
Write-Log "status = not responding: kill & restart" | |
Kill-Server $ServerProcess | |
$ServerProcess = Start-Server | |
} else { | |
#Write-Log "status = Running" | |
} | |
Start-Sleep $WatchDogInterval | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment