0

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
}
asked Jul 25, 2022 at 11:21
2
  • 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? Commented 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)" Commented Jul 25, 2022 at 11:48

1 Answer 1

0

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
}
answered Jul 26, 2022 at 7:33
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.