Skip to content

Commit

Permalink
Fix a bug with Rust and move start-server
Browse files Browse the repository at this point in the history
  • Loading branch information
patrix87 committed Sep 17, 2021
1 parent 239e39c commit 0d3397b
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 59 deletions.
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -265,6 +266,4 @@ catch {

Write-ServerMsg "Script successfully completed."

Stop-Transcript

Start-Sleep -Seconds 5
Stop-Transcript
19 changes: 12 additions & 7 deletions templates/7daystodie.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)"

Expand All @@ -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")
Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings")
20 changes: 12 additions & 8 deletions templates/insurgencysandstorm.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings")
22 changes: 13 additions & 9 deletions templates/killingfloor2.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings")
20 changes: 12 additions & 8 deletions templates/pixark.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings")
20 changes: 13 additions & 7 deletions templates/projectzomboid.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings")
17 changes: 10 additions & 7 deletions templates/rust.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings")
20 changes: 12 additions & 8 deletions templates/valheim.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Export-ModuleMember -Function Start-ServerPrep -Variable @("Server","Backups","Warnings")

0 comments on commit 0d3397b

Please sign in to comment.