-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathRestart-IcingaService.psm1
More file actions
45 lines (40 loc) · 1.24 KB
/
Restart-IcingaService.psm1
File metadata and controls
45 lines (40 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<#
.SYNOPSIS
Wrapper for Restart-Service which catches errors and prints proper output messages
.DESCRIPTION
Restarts a service if it is installed and prints console messages if a restart
was triggered or the service is not installed
.FUNCTIONALITY
Wrapper for restart service which catches errors and prints proper output messages
.EXAMPLE
PS>Restart-IcingaService -Service 'icinga2';
.PARAMETER Service
The name of the service to be restarted
.INPUTS
System.String
.OUTPUTS
Null
.LINK
https://github.com/Icinga/icinga-powershell-framework
#>
function Restart-IcingaService()
{
param (
$Service,
[switch]$Force = $FALSE
);
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
return;
}
$Result = Invoke-IcingaWindowsScheduledTask -JobType 'RestartWindowsService' -ObjectName $Service;
if ($Result.Success -eq $FALSE) {
Write-IcingaConsoleError $Result.ErrMsg;
} else {
Write-IcingaConsoleNotice $Result.Message;
}
if ($Service -eq 'icinga2') {
$Global:Icinga.Protected.IcingaServiceState = $Result.Status;
} elseif ($Service -eq 'icingapowershell') {
$Global:Icinga.Protected.IfWServiceState = $Result.Status;
}
}