Merge pull request #7512 from thaJeztah/use_SetRecoveryActions
cmd/containerd: use golang.org/x/sys Service.SetRecoveryActions()
This commit is contained in:
commit
8b804c4f81
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user