-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
379 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function Get-Lock { | ||
[CmdletBinding()] | ||
[OutputType([boolean])] | ||
param ( | ||
) | ||
if ((Test-Path -Path ".\servers\$($Server.UID).LOCK" -PathType "Leaf" -ErrorAction SilentlyContinue)) { | ||
return $true | ||
} | ||
return $false | ||
} | ||
Export-ModuleMember -Function Get-Lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
function Lock-Process { | ||
[CmdletBinding()] | ||
[OutputType([boolean])] | ||
param ( | ||
) | ||
try { | ||
$null = New-Item -Path ".\servers\" -Name "$($Server.UID).LOCK" -ItemType "file" -Force -ErrorAction SilentlyContinue | ||
Write-ScriptMsg "Process Locked." | ||
} | ||
catch { | ||
return $false | ||
} | ||
return $true | ||
} | ||
Export-ModuleMember -Function Lock-Process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function Unlock-Process { | ||
[CmdletBinding()] | ||
[OutputType([boolean])] | ||
param ( | ||
) | ||
try { | ||
#Delete the LOCK file based on the Server UID. | ||
$null = Remove-Item -Path ".\servers\$($Server.UID).LOCK" -Confirm:$false -ErrorAction SilentlyContinue | ||
Write-ScriptMsg "Process Unlocked." | ||
} | ||
catch { | ||
return $false | ||
} | ||
return $true | ||
} | ||
Export-ModuleMember -Function Unlock-Process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function Get-TaskConfig { | ||
Write-ScriptMsg "Getting Tasks Schedule..." | ||
$NextAlive = Get-IniValue -file ".\servers\$($Server.UID).INI" -key "NextAlive" | ||
$NextUpdate = Get-IniValue -file ".\servers\$($Server.UID).INI" -key "NextUpdate" | ||
$NextRestart = Get-IniValue -file ".\servers\$($Server.UID).INI" -key "NextRestart" | ||
return { | ||
NextAlive: $NextAlive, | ||
NextUpdate: $NextUpdate, | ||
NextRestart: $NextRestart | ||
} | ||
} | ||
Export-ModuleMember -Function Get-TaskConfig |
14 changes: 7 additions & 7 deletions
14
functions/util/Register-UpdateTask.psm1 → functions/util/Register-Task.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
function Register-UpdateTask { | ||
$action = New-ScheduledTaskAction -Execute "Powershell.exe" -Argument "-WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -File $scriptpath -ServerCfg `"$ServerCfg`" -UpdateCheck" -WorkingDirectory $dir | ||
$trigger = New-ScheduledTaskTrigger -Daily -At 12am -RandomDelay (New-TimeSpan -Minutes $Global.UpdateCheckFrequency) | ||
function Register-Task { | ||
$action = New-ScheduledTaskAction -Execute "Powershell.exe" -Argument "-WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -File $scriptpath -ServerCfg `"$ServerCfg`" -Task" -WorkingDirectory $dir | ||
$trigger = New-ScheduledTaskTrigger -Daily -At 12am -RandomDelay (New-TimeSpan -Minutes $Global.TaskCheckFrequency) | ||
$settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 10) | ||
$description = "Check if updates are available for $($server.Name)" | ||
$title = "UpdateCheck-$($server.Name)" | ||
$description = "Run Tasks for $($server.UID)" | ||
$title = "Tasks-$($server.UID)" | ||
$task = New-ScheduledTask -Description $description -Action $action -Trigger $trigger -Settings $settings | ||
$RegisteredTask = Register-ScheduledTask $title -InputObject $task | ||
$RegisteredTask.Triggers.Repetition.Duration = "P1D" #Repeat for a duration of one day | ||
$RegisteredTask.Triggers.Repetition.Interval = "PT$($Global.UpdateCheckFrequency)M" #Repeat every 30 minutes, use PT1H for every hour | ||
$RegisteredTask.Triggers.Repetition.Interval = "PT$($Global.TaskCheckFrequency)M" #Repeat every X minutes, use PT1H for every hour | ||
$null = Set-ScheduledTask $RegisteredTask | ||
} | ||
Export-ModuleMember -Function Register-UpdateTask | ||
Export-ModuleMember -Function Register-Task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function Register-TaskConfig { | ||
Write-ScriptMsg "Registering Tasks Schedule..." | ||
try { | ||
$null = New-Item -Path ".\servers\" -Name "$($Server.UID).INI" -ItemType "file" -Force -ErrorAction SilentlyContinue | ||
Write-ScriptMsg "Tasks Schedule Registered." | ||
} | ||
catch { | ||
return $null | ||
} | ||
Update-TaskConfig -Alive -Update -Restart | ||
return $true | ||
} | ||
Export-ModuleMember -Function Register-TaskConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function Remove-TaskConfig { | ||
[CmdletBinding()] | ||
[OutputType([boolean])] | ||
param ( | ||
) | ||
try { | ||
#Delete the INI file based on the Server UID. | ||
$null = Remove-Item -Path ".\servers\$($Server.UID).INI" -Confirm:$false -ErrorAction SilentlyContinue | ||
Write-ScriptMsg "Task Config Removed." | ||
} | ||
catch { | ||
return $false | ||
} | ||
return $true | ||
} | ||
Export-ModuleMember -Function Remove-TaskConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function Unregister-UpdateTask { | ||
$title = "Tasks-$($server.UID)" | ||
$null = Unregister-ScheduledTask -TaskName $title -Confirm:$false -ErrorAction SilentlyContinue | ||
Remove-TaskConfig | ||
} | ||
Export-ModuleMember -Function Unregister-UpdateTask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
function Update-TaskConfig { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory=$false)] | ||
[switch]$Alive, | ||
[Parameter(Mandatory=$false)] | ||
[switch]$Update, | ||
[Parameter(Mandatory=$false)] | ||
[string]$Restart | ||
) | ||
|
||
Write-ScriptMsg "Updating Tasks Schedule..." | ||
|
||
if($Alive){ | ||
$NextAlive = (Get-Date).AddMinutes($Global.AliveCheckFrequency) | ||
Set-IniValue -file ".\servers\$($Server.UID).INI" -key "NextAlive" -value $NextAlive | ||
} | ||
|
||
if($Update){ | ||
$NextUpdate = (Get-Date).AddMinutes($Global.UpdateCheckFrequency) | ||
Set-IniValue -file ".\servers\$($Server.UID).INI" -key "NextUpdate" -value $NextUpdate | ||
} | ||
|
||
if($Restart){ | ||
$NextRestart = (Get-Date -Hour $Server.AutoRestartTime[0] -Minute $Server.AutoRestartTime[1] -Second $Server.AutoRestartTime[2]).AddDays(1) | ||
Set-IniValue -file ".\servers\$($Server.UID).INI" -key "NextRestart" -value $NextRestart | ||
} | ||
} | ||
Export-ModuleMember -Function Update-TaskConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.