cmd/containerd: use golang.org/x/sys Service.SetRecoveryActions()
This is the equivalent of the local implementation. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
		| @@ -22,7 +22,6 @@ import ( | |||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 	"time" | 	"time" | ||||||
| 	"unsafe" |  | ||||||
|  |  | ||||||
| 	"github.com/containerd/containerd/errdefs" | 	"github.com/containerd/containerd/errdefs" | ||||||
| 	"github.com/containerd/containerd/services/server" | 	"github.com/containerd/containerd/services/server" | ||||||
| @@ -155,38 +154,14 @@ func registerService() error { | |||||||
| 	} | 	} | ||||||
| 	defer s.Close() | 	defer s.Close() | ||||||
|  |  | ||||||
| 	// See http://stackoverflow.com/questions/35151052/how-do-i-configure-failure-actions-of-a-windows-service-written-in-go | 	return s.SetRecoveryActions( | ||||||
| 	const ( | 		[]mgr.RecoveryAction{ | ||||||
| 		scActionNone    = 0 | 			{Type: mgr.ServiceRestart, Delay: 15 * time.Second}, | ||||||
| 		scActionRestart = 1 | 			{Type: mgr.ServiceRestart, Delay: 15 * time.Second}, | ||||||
|  | 			{Type: mgr.NoAction}, | ||||||
| 		serviceConfigFailureActions = 2 | 		}, | ||||||
|  | 		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 { | func unregisterService() error { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Sebastiaan van Stijn
					Sebastiaan van Stijn