From 0d3397bbfae7cc19c0e78dc3d0d402db1b434b1b Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Fri, 17 Sep 2021 16:09:37 -0400 Subject: [PATCH] Fix a bug with Rust and move start-server --- ...figs here => #Place your config.psm1 here} | 0 ...> #Copy and Edit run.cmd for each servers} | 0 main.ps1 | 9 ++++---- templates/7daystodie.psm1 | 19 ++++++++++------ templates/insurgencysandstorm.psm1 | 20 ++++++++++------- templates/killingfloor2.psm1 | 22 +++++++++++-------- templates/pixark.psm1 | 20 ++++++++++------- templates/projectzomboid.psm1 | 20 +++++++++++------ templates/rust.psm1 | 17 ++++++++------ templates/valheim.psm1 | 20 ++++++++++------- 10 files changed, 88 insertions(+), 59 deletions(-) rename configs/{Place your configs here => #Place your config.psm1 here} (100%) rename launchers/{Copy and Edit run dot cmd => #Copy and Edit run.cmd for each servers} (100%) diff --git a/configs/Place your configs here b/configs/#Place your config.psm1 here similarity index 100% rename from configs/Place your configs here rename to configs/#Place your config.psm1 here diff --git a/launchers/Copy and Edit run dot cmd b/launchers/#Copy and Edit run.cmd for each servers similarity index 100% rename from launchers/Copy and Edit run dot cmd rename to launchers/#Copy and Edit run.cmd for each servers diff --git a/main.ps1 b/main.ps1 index 59bedb1..e7fd6e2 100644 --- a/main.ps1 +++ b/main.ps1 @@ -228,9 +228,10 @@ if (-not ($FreshInstall)) { #Try to start the server, then if it's stable, set the priority and affinity then register the PID. Exit with Error if it fails. try { Write-ScriptMsg "Starting Server..." - $App = Start-Server + Start-ServerPrep + $App = Start-Process -FilePath $Server.Launcher -WorkingDirectory $Server.WorkingDirectory -ArgumentList $Server.ArgumentList -PassThru #Wait to see if the server is stable. - Start-Sleep -Seconds 10 + Start-Sleep -Seconds $Server.StartupWaitTime if (-not ($App) -or $App.HasExited){ Exit-WithError "Server Failed to launch." } else { @@ -265,6 +266,4 @@ catch { Write-ServerMsg "Script successfully completed." -Stop-Transcript - -Start-Sleep -Seconds 5 \ No newline at end of file +Stop-Transcript \ No newline at end of file diff --git a/templates/7daystodie.psm1 b/templates/7daystodie.psm1 index 1e6cc92..44438fd 100644 --- a/templates/7daystodie.psm1 +++ b/templates/7daystodie.psm1 @@ -86,6 +86,9 @@ $ServerDetails = @{ #Should the server validate install after installation or update *(recommended) Validate = $true + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 } #Create the object $Server = New-Object -TypeName PsObject -Property $ServerDetails @@ -173,13 +176,18 @@ foreach($Argument in $Arguments){ $ArgumentList = $CleanedArguments -join "" #Server Launcher -$Launcher = $Server.Exec +$Launcher = $(Resolve-Path -Path $Server.Exec) +$WorkingDirectory = $(Resolve-Path -Path $Server.Path) + +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory #--------------------------------------------------------- -# Launch Function +# Function that runs just before the server starts. #--------------------------------------------------------- -function Start-Server { +function Start-ServerPrep { Write-ScriptMsg "Port Forward : 26900 in TCP and 26900 to 26903 in UDP to $($Global.InternalIP)" @@ -191,10 +199,7 @@ function Start-Server { If(-not (Test-Path -Path $Server.ConfigFile -PathType "leaf")){ Copy-Item -Path "$($Server.Path)\serverconfig.xml" -Destination $Server.ConfigFile -Force } - #Start Server - $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - return $App } -Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/insurgencysandstorm.psm1 b/templates/insurgencysandstorm.psm1 index 66c099f..93e275f 100644 --- a/templates/insurgencysandstorm.psm1 +++ b/templates/insurgencysandstorm.psm1 @@ -128,6 +128,9 @@ $ServerDetails = @{ #Should the server validate install after installation or update *(recommended) Validate = $true + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 } #Create the object $Server = New-Object -TypeName PsObject -Property $ServerDetails @@ -231,20 +234,21 @@ if ($Server.EnableRcon){ $ArgumentList = $CleanedArguments -join "" #Server Launcher -$Launcher = $Server.Exec +$Launcher = $(Resolve-Path -Path $Server.Exec) +$WorkingDirectory = $(Resolve-Path -Path $Server.Path) + +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory #--------------------------------------------------------- -# Launch Function +# Function that runs just before the server starts. #--------------------------------------------------------- -function Start-Server { +function Start-ServerPrep { Write-ScriptMsg "Port Forward : $($server.Port) and $($server.QueryPort) in TCP and UDP to $($Global.InternalIP)" - #Start Server - $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - - return $App } -Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/killingfloor2.psm1 b/templates/killingfloor2.psm1 index 6cf71a6..350ee92 100644 --- a/templates/killingfloor2.psm1 +++ b/templates/killingfloor2.psm1 @@ -107,7 +107,10 @@ $ServerDetails = @{ AppAffinity = 15 #Should the server validate install after installation or update *(recommended) - Validate = $false + Validate = $true + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 } #Create the object $Server = New-Object -TypeName PsObject -Property $ServerDetails @@ -198,21 +201,22 @@ foreach($Argument in $Arguments){ $ArgumentList = $CleanedArguments -join "" #Server Launcher -$Launcher = $Server.Exec +$Launcher = $(Resolve-Path -Path $Server.Exec) +$WorkingDirectory = $(Resolve-Path -Path $Server.Path) + +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory #--------------------------------------------------------- -# Launch Function +# Function that runs just before the server starts. #--------------------------------------------------------- -function Start-Server { +function Start-ServerPrep { Write-ScriptMsg "Port Forward : $($server.Port), $($server.QueryPort), 20560, 123 in UDP and $($server.WebAdminPort) in TCP to $($Global.InternalIP)" Write-ScriptMsg "Once Webadmin enabled, go to http://$($Global.InternalIP):$($server.WebAdminPort) to administer this server." - #Start Server - $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - - return $App } -Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/pixark.psm1 b/templates/pixark.psm1 index 4733a61..3710fe9 100644 --- a/templates/pixark.psm1 +++ b/templates/pixark.psm1 @@ -136,6 +136,9 @@ $ServerDetails = @{ #Should the server validate install after installation or update *(recommended) Validate = $true + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 } #Create the object $Server = New-Object -TypeName PsObject -Property $ServerDetails @@ -239,20 +242,21 @@ foreach($Argument in $Arguments){ $ArgumentList = $CleanedArguments -join "" #Server Launcher -$Launcher = $Server.Exec +$Launcher = $(Resolve-Path -Path $Server.Exec) +$WorkingDirectory = $(Resolve-Path -Path $Server.Path) + +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory #--------------------------------------------------------- -# Launch Function +# Function that runs just before the server starts. #--------------------------------------------------------- -function Start-Server { +function Start-ServerPrep { Write-ScriptMsg "Port Forward : $($server.Port), $($server.QueryPort) And $($server.CubePort) in TCP and UDP to $($Global.InternalIP)" - #Start Server - $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - - return $App } -Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/projectzomboid.psm1 b/templates/projectzomboid.psm1 index bedb5de..cc5a095 100644 --- a/templates/projectzomboid.psm1 +++ b/templates/projectzomboid.psm1 @@ -107,6 +107,9 @@ $ServerDetails = @{ #Should the server validate install after installation or update *(recommended) Validate = $true + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 } #Create the object $Server = New-Object -TypeName PsObject -Property $ServerDetails @@ -208,19 +211,22 @@ foreach($Argument in $Arguments){ $ArgumentList = $CleanedArguments -join "" -$Launcher = "$($Server.Path)\jre64\bin\java.exe" +#Server Launcher +$Launcher = $(Resolve-Path -Path $Server.Exec) +$WorkingDirectory = $(Resolve-Path -Path $Server.Path) + +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory #--------------------------------------------------------- -# Launch Function +# Function that runs just before the server starts. #--------------------------------------------------------- -function Start-Server { +function Start-ServerPrep { Write-ScriptMsg "Port Forward : 16261, 8766 and 8767 in TCP and UDP to $($Global.InternalIP)" - $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - - return $App } -Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/rust.psm1 b/templates/rust.psm1 index a474fe9..341c8ca 100644 --- a/templates/rust.psm1 +++ b/templates/rust.psm1 @@ -139,6 +139,9 @@ $ServerDetails = @{ #Should the server validate install after installation or update *(recommended) Validate = $false + + #How long should it wait to check if the server is stable + StartupWaitTime = 0 } #Create the object $Server = New-Object -TypeName PsObject -Property $ServerDetails @@ -251,18 +254,18 @@ $ArgumentList = $CleanedArguments -join "" $Launcher = $(Resolve-Path -Path $Server.Exec) $WorkingDirectory = $(Resolve-Path -Path $Server.Path) +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory + #--------------------------------------------------------- -# Launch Function +# Function that runs just before the server starts. #--------------------------------------------------------- -function Start-Server { +function Start-ServerPrep { Write-ScriptMsg "Port Forward : $($server.Port), $($server.ManagementPort), $($Server.Port + 69) in TCP and UDP to $($Global.InternalIP)" - #Start Server - $App = Start-Process -FilePath "$Launcher" -WorkingDirectory "$WorkingDirectory" -ArgumentList "$ArgumentList" -PassThru - - return $App } -Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file diff --git a/templates/valheim.psm1 b/templates/valheim.psm1 index dcace6c..8d85048 100644 --- a/templates/valheim.psm1 +++ b/templates/valheim.psm1 @@ -88,6 +88,9 @@ $ServerDetails = @{ #Should the server validate install after installation or update *(recommended) Validate = $true + + #How long should it wait to check if the server is stable + StartupWaitTime = 10 } #Create the object $Server = New-Object -TypeName PsObject -Property $ServerDetails @@ -176,20 +179,21 @@ foreach($Argument in $Arguments){ $ArgumentList = $CleanedArguments -join "" #Server Launcher -$Launcher = $Server.Exec +$Launcher = $(Resolve-Path -Path $Server.Exec) +$WorkingDirectory = $(Resolve-Path -Path $Server.Path) + +Add-Member -InputObject $Server -Name "ArgumentList" -Type NoteProperty -Value $ArgumentList +Add-Member -InputObject $Server -Name "Launcher" -Type NoteProperty -Value $Launcher +Add-Member -InputObject $Server -Name "WorkingDirectory" -Type NoteProperty -Value $WorkingDirectory #--------------------------------------------------------- -# Launch Function +# Function that runs just before the server starts. #--------------------------------------------------------- -function Start-Server { +function Start-ServerPrep { Write-ScriptMsg "Port Forward : $($server.Port) in TCP and UDP to $($Global.InternalIP)" - #Start Server - $App = Start-Process -FilePath $Launcher -WorkingDirectory $Server.Path -ArgumentList $ArgumentList -PassThru - - return $App } -Export-ModuleMember -Function Start-Server -Variable @("Server","Backups","Warnings") \ No newline at end of file +Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings") \ No newline at end of file