From 634bf0dd31e7c72a1a45fb71e7b103ac423e5473 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 12 Oct 2022 01:31:30 +0200 Subject: [PATCH] cmd/containerd: use golang.org/x/sys Service.SetRecoveryActions() This is the equivalent of the local implementation. Signed-off-by: Sebastiaan van Stijn --- cmd/containerd/command/service_windows.go | 39 ++++------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/cmd/containerd/command/service_windows.go b/cmd/containerd/command/service_windows.go index e36bac5ba..1c7e7602e 100644 --- a/cmd/containerd/command/service_windows.go +++ b/cmd/containerd/command/service_windows.go @@ -22,7 +22,6 @@ import ( "os" "path/filepath" "time" - "unsafe" "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/services/server" @@ -155,38 +154,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 - - serviceConfigFailureActions = 2 + return s.SetRecoveryActions( + []mgr.RecoveryAction{ + {Type: mgr.ServiceRestart, Delay: 15 * time.Second}, + {Type: mgr.ServiceRestart, Delay: 15 * 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(15 * time.Second / time.Millisecond)}, - {Type: scActionRestart, Delay: uint32(15 * 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 - } - - return nil } func unregisterService() error {