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"
|
"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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user