From 10c9add973d79bec575c137fe431758033a19877 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Wed, 6 May 2020 11:36:15 +0200 Subject: [PATCH] Fixes custom daemon example for restart_error counter --- doc/developerguide/10-Custom-Daemons.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/developerguide/10-Custom-Daemons.md b/doc/developerguide/10-Custom-Daemons.md index e9e71df..05883f3 100644 --- a/doc/developerguide/10-Custom-Daemons.md +++ b/doc/developerguide/10-Custom-Daemons.md @@ -296,7 +296,13 @@ function Start-IcingaAgentServiceTest() if ($ServiceState.Status -ne 'Running') { try { # Try to restart the service - Restart-Service 'icinga2'; + Restart-Service 'icinga2' -ErrorAction Stop; + + Add-IcingaHashtableItem ` + -Hashtable $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.ServiceState ` + -Key 'restart_error' ` + -Value 0 ` + -Override | Out-Null; } catch { # Add an error counter in case we failed $RestartErrors += 1; @@ -378,7 +384,13 @@ function Start-IcingaAgentServiceTest() if ($ServiceState.Status -ne 'Running') { try { # Try to restart the service - Restart-Service 'icinga2'; + Restart-Service 'icinga2' -ErrorAction Stop; + + Add-IcingaHashtableItem ` + -Hashtable $IcingaDaemonData.BackgroundDaemon.TestIcingaAgentService.ServiceState ` + -Key 'restart_error' ` + -Value 0 ` + -Override | Out-Null; } catch { # Add an error counter in case we failed $RestartErrors += 1;