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

Add ForceServiceCleanup switch to Update-Service.ps1.

Using this option will shut down the service independent of its state,
remove the status XML file (will be re-created by the service during
the next start) and (re-) starts the service no matter if it was running
before.
parent cbbddfa5
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,8 @@
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)][string] $UpdaterSettings
[Parameter(Mandatory=$True)][string] $UpdaterSettings,
[Parameter(Mandatory=$False)][switch] $ForceServiceCleanup
)
......@@ -94,11 +95,13 @@ 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
if (-Not $ForceServiceCleanup){
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..."
......@@ -392,6 +395,13 @@ function Update-ServiceBinaries {
Log-Error "Creating [$($MarkerFile)] FAILED:`n> $($_.Exception.Message)"
Return $False
}
if (-Not $ForceServiceCleanup) {
Return $True
}
Log-Debug "<ForceServiceCleanup> removing status file [$($StatusXml)]"
Remove-Item -Force $StatusXml
Return $True
}
......@@ -643,8 +653,8 @@ try {
if ($ServiceRunningBefore) {
Log-Debug "$($UpdSummary) Trying to start the service again..."
if ($ServiceRunningBefore -Or $ForceServiceCleanup) {
Log-Debug "$($UpdSummary) Trying to start the service..."
Start-MyService
} else {
Log-Debug "$($UpdSummary) Leaving the service stopped, as before."
......
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