I'm trying to run Core Keeper Dedicated Server, everything seems fine, but from time to time CoreKeeperServer.exe crashes. So main Powershell script what launches it not tracking is it crashed or not. How do i need to modify this script, so it constantly (every 1-5 seconds or so) monitored if process still running or not, and start it again if it is? Also i want to keep "press q to exit" functionality what already included in stock script.
Stock script:
# Feel free to change these (see README), but keep in mind that changes to this file might be overwritten on update
$CoreKeeperArguments = @("-batchmode", "-logfile", "CoreKeeperServerLog.txt") + $args
$script:ckpid = $null
function Quit-CoreKeeperServer {
if ($script:ckpid -ne $null) {
taskkill /pid $ckpid.Id
Wait-Process -InputObject $ckpid
Write-Host "Stopped CoreKeeperServer.exe"
}
}
try {
if (Test-Path -Path "GameID.txt") {
Remove-Item -Path "GameID.txt"
}
$script:ckpid = Start-Process -PassThru -FilePath %0\..\CoreKeeperServer.exe -ArgumentList $CoreKeeperArguments
Write-Host "Started CoreKeeperServer.exe"
# Wait for GameID
while (!(Test-Path -Path "GameID.txt")) {
Start-Sleep -Milliseconds 100
}
Write-Host -NoNewline "Game ID: "
Get-Content "GameID.txt"
Write-Host "Press q to quit, DON'T close the window or the server process will just keep running"
While ($KeyInfo.VirtualKeyCode -eq $Null -or $KeyInfo.VirtualKeyCode -ne 81) {
$KeyInfo = $Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown")
}
}
finally {
Quit-CoreKeeperServer
pause
}
-
How do you know when the server has crashed? Does it write an error to log/console or is there an API that (won't) answer on crash?vonPryz– vonPryz2022年07月25日 11:38:41 +00:00Commented Jul 25, 2022 at 11:38
-
@vonPryz 1. All players was disconnected 2. pid of process do not exists any more. 3. on q key pressed script errors out "pid does not exist(in short)"Petr– Petr2022年07月25日 11:48:03 +00:00Commented Jul 25, 2022 at 11:48
1 Answer 1
Solved problem like this:
# Feel free to change these (see README), but keep in mind that changes to this file might be overwritten on update
$CoreKeeperArguments = @("-batchmode", "-logfile", "CoreKeeperServerLog.txt") + $args
$script:ckpid = $null
function Quit-CoreKeeperServer {
if ($script:ckpid -ne $null) {
taskkill /pid $ckpid.Id
Wait-Process -InputObject $ckpid
Write-Host "Stopped CoreKeeperServer.exe"
}
}
try {
if (Test-Path -Path "GameID.txt") {
Remove-Item -Path "GameID.txt"
}
$script:ckpid = Start-Process -PassThru -FilePath %0\..\CoreKeeperServer.exe -ArgumentList $CoreKeeperArguments
Write-Host "Started CoreKeeperServer.exe"
# Wait for GameID
while (!(Test-Path -Path "GameID.txt")) {
Start-Sleep -Milliseconds 100
}
Write-Host -NoNewline "Game ID: "
Get-Content "GameID.txt"
Write-Host "Server is runnig. Press CTRL + C to stop."
While ($true) {
if (-not (Get-Process -Id $ckpid.Id -ErrorAction SilentlyContinue)) {
Write-Host "Server is died restarting..."
Get-Date
$script:ckpid = Start-Process -PassThru -FilePath %0\..\CoreKeeperServer.exe -ArgumentList $CoreKeeperArguments
Write-Host "Started CoreKeeperServer.exe"
Write-Host -NoNewline "Game ID: "
Get-Content "GameID.txt"
Write-Host "Server is runnig. Press CTRL + C to stop."
sleep 1
}
}
}
finally {
Quit-CoreKeeperServer
pause
}
Sign up to request clarification or add additional context in comments.
1 Comment
T. Nielsen
Answering ones own questions totally all-right imo, but perhaps not just code dump, i mean sharing is caring so good on You for that, but give a few lines in the beginning to explain what the problem was, instead of just giving a solution with a lot of extra bits that were not what solved Your issue.
lang-bash