Last active
January 12, 2016 23:20
-
-
Save twobob/7e3d0f564f1aa1a53d5d to your computer and use it in GitHub Desktop.
Restart Zero Process Time ArkServer, with fail counts
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
$ProcessName = "ShooterGameServer" | |
$batPath = "C:\YOUR-PATH\ArkRun.bat" | |
$CountOfFailures = 0 | |
$MaximumCountOfFailures = 60 | |
$interval = 3 | |
$LastTextWasAZero = 0 # false | |
$StartSleepInterval = 500 | |
function Start-Server | |
{ | |
Stop-Process -Force -processname *ShooterGameServer* | |
Start-Sleep -s 10 | |
Start-Process $batPath -LoadUserProfile True | |
Write-Host "Waiting $StartSleepInterval seconds for startup" | |
Start-Sleep -s $StartSleepInterval | |
Write-Host "Resuming Testing Operations" | |
} | |
function Pause-A-While{Start-Sleep -s $interval} | |
Write-Host "Beginning Testing Operations" | |
Write-Host "USING: $MaximumCountOfFailures max failures at $interval per test" | |
While(1) | |
{ | |
# SO IF IT ISNT STARTED AT ALL ? START IT... | |
if (! (ps | ? {$_.processname -eq $ProcessName})) | |
{Start-Server} | |
$cpuutil=(get-wmiobject Win32_PerfFormattedData_PerfProc_Process | where {$_.Name -eq"ShooterGameServer"}).PercentProcessorTime | |
#Write-Host $cpuutil | |
if ($LastTextWasAZero -and ($cpuutil -ge 1) ) | |
{ | |
$CountOfFailures = 0 | |
$LastTextWasAZero = 0 | |
Pause-A-While | |
continue | |
} | |
If ($cpuutil -le 0) | |
{ | |
$CountOfFailures += 1 | |
Write-Host "FailureCount: " $CountOfFailures $(((get-date).ToUniversalTime()).ToString("hh:mm:ss dd/MM/yyyy")) | |
$LastTextWasAZero = 1 | |
If ($CountOfFailures -le $MaximumCountOfFailures) | |
{Pause-A-While | |
continue} | |
Write-Host "Total FailureCount: " $CountOfFailures | |
$CountOfFailures = 0 | |
Write-Host "Restarting Server Since we failed the CPU count $MaximumCountOfFailures times" | |
Start-Server | |
} | |
Else | |
{ | |
Pause-A-While | |
} | |
} | |
{Exit} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment