Skip to content

Commit

Permalink
Improves service recover by adjustable restart time interval argument (
Browse files Browse the repository at this point in the history
…#775)

Adds argument `-IntervalInSeconds` for `Enable-IcingaServiceRecovery` to allow setting a custom time interval for the service to restart, while setting the default to 120 seconds (2 minutes)
  • Loading branch information
LordHepipud authored Jan 29, 2025
1 parent ed0770e commit 1c993ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/100-General/10-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic

### Enhancements

* [#766](https://github.com/Icinga/icinga-powershell-framework/issues/766) Adds argument `-IntervalInSeconds` for `Enable-IcingaServiceRecovery` to allow setting a custom time interval for the service to restart, while setting the default to 120 seconds (2 minutes)
* [#772](https://github.com/Icinga/icinga-powershell-framework/pull/772) Adds new Metric over Time handling

## 1.13.0 Beta-2 (2024-09-19)
Expand Down
11 changes: 9 additions & 2 deletions lib/core/windows/Enable-IcingaServiceRecovery.psm1
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
function Enable-IcingaServiceRecovery()
{
param (
[int]$IntervalInSeconds = 120
);

# The interval in milliseconds to restart actions to happen for the service
$IntervalInMilliseconds = $IntervalInSeconds * 1000;

if ($null -ne (Get-Service 'icinga2' -ErrorAction SilentlyContinue)) {
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'failure icinga2 reset=0 actions=restart/0/restart/0/restart/0';
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments ([string]::Format('failure icinga2 reset=0 actions=restart/{0}/restart/{0}/restart/{0}', $IntervalInMilliseconds));

if ($ServiceStatus.ExitCode -ne 0) {
Write-IcingaConsoleError -Message 'Failed to enable recover settings for service "icinga2": {0} {1}' -Objects $ServiceStatus.Message, $ServiceStatus.Error;
Expand All @@ -11,7 +18,7 @@ function Enable-IcingaServiceRecovery()
}

if ($null -ne (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue)) {
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'failure icingapowershell reset=0 actions=restart/0/restart/0/restart/0';
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments ([string]::Format('failure icingapowershell reset=0 actions=restart/{0}/restart/{0}/restart/{0}', $IntervalInMilliseconds));

if ($ServiceStatus.ExitCode -ne 0) {
Write-IcingaConsoleError -Message 'Failed to enable recover settings for service "icingapowershell": {0} {1}' -Objects $ServiceStatus.Message, $ServiceStatus.Error;
Expand Down

0 comments on commit 1c993ba

Please sign in to comment.