Skip to content

Commit

Permalink
Improve Update Task
Browse files Browse the repository at this point in the history
  • Loading branch information
patrix87 committed Nov 4, 2021
1 parent f184197 commit 2a5f34e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
19 changes: 19 additions & 0 deletions functions/server/Get-ServerProcess.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function Get-ServerProcess {
if ($Server.UsePID){
#Get the PID from the .PID market file.
$ServerPID = Get-PID
#If it returned 0, it failed to get a PID
if ($null -ne $ServerPID) {
$ServerProcess = Get-Process -ID $ServerPID -ErrorAction SilentlyContinue
}
} else {
# Find the process by name.
$ServerProcess = Get-Process -Name $Server.ProcessName -ErrorAction SilentlyContinue
}
#Check if the process was found.
if (-not ($null -eq $ServerProcess)) {
return $ServerProcess
}
return $false
}
Export-ModuleMember -Function Get-ServerProcess
7 changes: 7 additions & 0 deletions functions/server/Request-Update.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
function Request-Update {
$ServerProcess = Get-ServerProcess
if (-not ($ServerProcess)){
Exit-WithError -ErrorMsg "Server is not active."
}
if (-not ($Server.AutoUpdates)){
Exit-WithError -ErrorMsg "AutoUpdates are disabled."
}
#Create server directory if not found.
if (-not (Test-Path -Path $Server.Path -ErrorAction SilentlyContinue)){
$null = New-Item -ItemType "directory" -Path $Server.Path -ErrorAction SilentlyContinue
Expand Down
14 changes: 2 additions & 12 deletions functions/server/Stop-Server.psm1
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
function Stop-Server {
if ($Server.UsePID){
#Get the PID from the .PID market file.
$ServerPID = Get-PID
#If it returned 0, it failed to get a PID
if ($null -ne $ServerPID) {
$ServerProcess = Get-Process -ID $ServerPID -ErrorAction SilentlyContinue
}
} else {
# Find the process by name.
$ServerProcess = Get-Process -Name $Server.ProcessName -ErrorAction SilentlyContinue
}
$ServerProcess = Get-ServerProcess
#Check if the process was found.
if ($null -eq $ServerProcess) {
if (-not ($ServerProcess)) {
Write-ServerMsg "Server is not running."
} else {
#Check if it's the right server via RCON if possible.
Expand Down
2 changes: 1 addition & 1 deletion main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Read-Config
#---------------------------------------------------------
# Checking if updates are available.
#---------------------------------------------------------
if ($UpdateCheck -and $server.AutoUpdates) {
if ($UpdateCheck) {
Write-ScriptMsg "Checking on steamCMD if updates are avaiable for $($Server.Name)..."
if (-not (Request-Update)){
Write-ScriptMsg "No updates are available for $($Server.Name)"
Expand Down

0 comments on commit 2a5f34e

Please sign in to comment.