Skip to content

Commit 1c993ba

Browse files
authored
Improves service recover by adjustable restart time interval argument (#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)
1 parent ed0770e commit 1c993ba

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1717

1818
### Enhancements
1919

20+
* [#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)
2021
* [#772](https://github.com/Icinga/icinga-powershell-framework/pull/772) Adds new Metric over Time handling
2122

2223
## 1.13.0 Beta-2 (2024-09-19)

lib/core/windows/Enable-IcingaServiceRecovery.psm1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
function Enable-IcingaServiceRecovery()
22
{
3+
param (
4+
[int]$IntervalInSeconds = 120
5+
);
6+
7+
# The interval in milliseconds to restart actions to happen for the service
8+
$IntervalInMilliseconds = $IntervalInSeconds * 1000;
9+
310
if ($null -ne (Get-Service 'icinga2' -ErrorAction SilentlyContinue)) {
4-
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'failure icinga2 reset=0 actions=restart/0/restart/0/restart/0';
11+
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments ([string]::Format('failure icinga2 reset=0 actions=restart/{0}/restart/{0}/restart/{0}', $IntervalInMilliseconds));
512

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

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

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

0 commit comments

Comments
 (0)