From 25b538bb0332883e268827b256ad40c2d74fa3d6 Mon Sep 17 00:00:00 2001 From: Andreas Ohlund Date: Wed, 12 Mar 2025 09:10:27 +0100 Subject: [PATCH] Configure windows services to keep trying to restart --- .../Services/ServiceRecoveryHelper.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ServiceControlInstaller.Engine/Services/ServiceRecoveryHelper.cs b/src/ServiceControlInstaller.Engine/Services/ServiceRecoveryHelper.cs index fface96256..4fab1b06c7 100644 --- a/src/ServiceControlInstaller.Engine/Services/ServiceRecoveryHelper.cs +++ b/src/ServiceControlInstaller.Engine/Services/ServiceRecoveryHelper.cs @@ -80,8 +80,7 @@ public static void SetRecoveryOptions(string serviceName) void SetRestartOnFailure(string serviceName) { - const int actionCount = 2; - const uint delay = 60000; + const int actionCount = 3; var service = IntPtr.Zero; var failureActionsPtr = IntPtr.Zero; @@ -95,18 +94,27 @@ void SetRestartOnFailure(string serviceName) var action1 = new SC_ACTION { Type = SC_ACTION_TYPE.SC_ACTION_RESTART, - Delay = delay + Delay = 10000 }; Marshal.StructureToPtr(action1, actionPtr, false); var action2 = new SC_ACTION { - Type = SC_ACTION_TYPE.SC_ACTION_NONE, - Delay = delay + Type = SC_ACTION_TYPE.SC_ACTION_RESTART, + Delay = 30000 }; + Marshal.StructureToPtr(action2, (IntPtr)((long)actionPtr + Marshal.SizeOf(typeof(SC_ACTION))), false); + var action3 = new SC_ACTION + { + Type = SC_ACTION_TYPE.SC_ACTION_RESTART, + Delay = 60000 + }; + + Marshal.StructureToPtr(action3, (IntPtr)((long)actionPtr + (Marshal.SizeOf(typeof(SC_ACTION)) * 2)), false); + var failureActions = new SERVICE_FAILURE_ACTIONS { dwResetPeriod = 0,