2022-05-12 10:24:11 -04:00
function Enable-IcingaServiceRecovery ( )
{
2025-01-29 09:45:01 -05:00
param (
[ int ] $IntervalInSeconds = 120
) ;
# The interval in milliseconds to restart actions to happen for the service
$IntervalInMilliseconds = $IntervalInSeconds * 1000 ;
2022-08-23 10:37:18 -04:00
if ( $null -ne ( Get-Service 'icinga2' -ErrorAction SilentlyContinue ) ) {
2025-01-29 09:45:01 -05:00
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments ( [ string ] :: Format ( 'failure icinga2 reset=0 actions=restart/{0}/restart/{0}/restart/{0}' , $IntervalInMilliseconds ) ) ;
2022-05-12 10:24:11 -04:00
if ( $ServiceStatus . ExitCode -ne 0 ) {
Write-IcingaConsoleError -Message 'Failed to enable recover settings for service "icinga2": {0} {1}' -Objects $ServiceStatus . Message , $ServiceStatus . Error ;
} else {
Write-IcingaConsoleNotice -Message 'Successfully enabled service recovery for service "icinga2"' ;
}
}
2022-08-23 10:37:18 -04:00
if ( $null -ne ( Get-Service 'icingapowershell' -ErrorAction SilentlyContinue ) ) {
2025-01-29 09:45:01 -05:00
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments ( [ string ] :: Format ( 'failure icingapowershell reset=0 actions=restart/{0}/restart/{0}/restart/{0}' , $IntervalInMilliseconds ) ) ;
2022-05-12 10:24:11 -04:00
if ( $ServiceStatus . ExitCode -ne 0 ) {
Write-IcingaConsoleError -Message 'Failed to enable recover settings for service "icingapowershell": {0} {1}' -Objects $ServiceStatus . Message , $ServiceStatus . Error ;
} else {
Write-IcingaConsoleNotice -Message 'Successfully enabled service recovery for service "icingapowershell"' ;
}
}
}