From 3c585e6567e5931fcc62b10ca4eda9a6e0ce97fb Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 12 Oct 2022 01:58:50 +0200 Subject: [PATCH 1/2] cmd/dockerd: use golang.org/x/sys Service.SetRecoveryActions() This is the equivalent of the local implementation. Signed-off-by: Sebastiaan van Stijn --- cmd/dockerd/service_windows.go | 36 +++++++--------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/cmd/dockerd/service_windows.go b/cmd/dockerd/service_windows.go index 866f81c749..0841a7f6aa 100644 --- a/cmd/dockerd/service_windows.go +++ b/cmd/dockerd/service_windows.go @@ -10,7 +10,6 @@ import ( "os/exec" "path/filepath" "time" - "unsafe" "github.com/sirupsen/logrus" "github.com/spf13/pflag" @@ -188,35 +187,14 @@ func registerService() error { } defer s.Close() - // See http://stackoverflow.com/questions/35151052/how-do-i-configure-failure-actions-of-a-windows-service-written-in-go - const ( - scActionNone = 0 - scActionRestart = 1 - scActionReboot = 2 - scActionRunCommand = 3 - - serviceConfigFailureActions = 2 + err = s.SetRecoveryActions( + []mgr.RecoveryAction{ + {Type: mgr.ServiceRestart, Delay: 60 * time.Second}, + {Type: mgr.ServiceRestart, Delay: 60 * time.Second}, + {Type: mgr.NoAction}, + }, + uint32(24*time.Hour/time.Second), ) - - type serviceFailureActions struct { - ResetPeriod uint32 - RebootMsg *uint16 - Command *uint16 - ActionsCount uint32 - Actions uintptr - } - - type scAction struct { - Type uint32 - Delay uint32 - } - t := []scAction{ - {Type: scActionRestart, Delay: uint32(60 * time.Second / time.Millisecond)}, - {Type: scActionRestart, Delay: uint32(60 * time.Second / time.Millisecond)}, - {Type: scActionNone}, - } - lpInfo := serviceFailureActions{ResetPeriod: uint32(24 * time.Hour / time.Second), ActionsCount: uint32(3), Actions: uintptr(unsafe.Pointer(&t[0]))} - err = windows.ChangeServiceConfig2(s.Handle, serviceConfigFailureActions, (*byte)(unsafe.Pointer(&lpInfo))) if err != nil { return err } From 624daf8d9e4bd164eb7cf5ce6640098277fad712 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 12 Oct 2022 02:01:33 +0200 Subject: [PATCH 2/2] Change restart delay for Windows service to 15s Previously we waited for 60 seconds after the service faults to restart it. However, there isn't much benefit to waiting this long. We expect 15 seconds to be a more reasonable delay. Co-Authored-by: Kevin Parsons Signed-off-by: Sebastiaan van Stijn --- cmd/dockerd/service_windows.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/dockerd/service_windows.go b/cmd/dockerd/service_windows.go index 0841a7f6aa..e82ec1826c 100644 --- a/cmd/dockerd/service_windows.go +++ b/cmd/dockerd/service_windows.go @@ -189,8 +189,8 @@ func registerService() error { err = s.SetRecoveryActions( []mgr.RecoveryAction{ - {Type: mgr.ServiceRestart, Delay: 60 * time.Second}, - {Type: mgr.ServiceRestart, Delay: 60 * time.Second}, + {Type: mgr.ServiceRestart, Delay: 15 * time.Second}, + {Type: mgr.ServiceRestart, Delay: 15 * time.Second}, {Type: mgr.NoAction}, }, uint32(24*time.Hour/time.Second),