Skip to content
Snippets Groups Projects
Commit b97a16d1 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Prevent shutdown if the service is busy.

Refers to #13
parent c46fcbd9
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,28 @@ function Ensure-ServiceRunning([string]$ServiceName) {
}
function ServiceIsBusy {
$StatusXml = "$($InstallationPath)\status.xml"
try {
[xml]$XML = Get-Content $StatusXml -ErrorAction Stop
if ($XML.ServiceStatus.TransferInProgress) {
Return $True
} else {
Write-Verbose "Service is idle, shutdown possible."
Return $False
}
}
catch {
$ex = $_.Exception.Message
$msg = "Trying to read the service status from [$($StatusXml)] failed! "
$msg += "The reported error message was:`n$($ex)"
Send-MailReport -Subject "Error parsing status of $($ServiceName)!" `
-Body $msg
Exit
}
}
function Exit-IfDirMissing([string]$DirName, [string]$Desc) {
if (Test-Path -PathType Container $DirName) {
Return
......@@ -75,6 +97,12 @@ function Stop-MyService([string]$Message) {
Log-Info "$($Message) (Service already in state 'Stopped')"
Return
}
if (ServiceIsBusy) {
$msg = "*DENYING* to stop the service $($ServiceName) as it is "
$msg += "currently busy.`nShutdown reason was '$($Message)'."
Log-Info $msg
Exit
}
try {
Log-Info "$($Message) Attempting service $($ServiceName) shutdown..."
Stop-Service "$($ServiceName)" -ErrorAction Stop
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment