Remove restartmanager from libcontainerd
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com> Upstream-commit: 606a245d8548e98e889df1b9cf511b5953a309b9 Component: engine
This commit is contained in:
@ -138,13 +138,8 @@ func (clnt *client) Create(containerID string, checkpoint string, checkpointDir
|
||||
clnt.lock(containerID)
|
||||
defer clnt.unlock(containerID)
|
||||
|
||||
if ctr, err := clnt.getContainer(containerID); err == nil {
|
||||
if ctr.restarting {
|
||||
ctr.restartManager.Cancel()
|
||||
ctr.clean()
|
||||
} else {
|
||||
return fmt.Errorf("Container %s is already active", containerID)
|
||||
}
|
||||
if _, err := clnt.getContainer(containerID); err == nil {
|
||||
return fmt.Errorf("Container %s is already active", containerID)
|
||||
}
|
||||
|
||||
uid, gid, err := getRootIDs(specs.Spec(spec))
|
||||
|
||||
@ -1,12 +1,5 @@
|
||||
package libcontainerd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/restartmanager"
|
||||
)
|
||||
|
||||
const (
|
||||
// InitFriendlyName is the name given in the lookup map of processes
|
||||
// for the first process started in a container.
|
||||
@ -16,25 +9,5 @@ const (
|
||||
|
||||
type containerCommon struct {
|
||||
process
|
||||
restartManager restartmanager.RestartManager
|
||||
restarting bool
|
||||
processes map[string]*process
|
||||
startedAt time.Time
|
||||
}
|
||||
|
||||
// WithRestartManager sets the restartmanager to be used with the container.
|
||||
func WithRestartManager(rm restartmanager.RestartManager) CreateOption {
|
||||
return restartManager{rm}
|
||||
}
|
||||
|
||||
type restartManager struct {
|
||||
rm restartmanager.RestartManager
|
||||
}
|
||||
|
||||
func (rm restartManager) Apply(p interface{}) error {
|
||||
if pr, ok := p.(*container); ok {
|
||||
pr.restartManager = rm.rm
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("WithRestartManager option not supported for this client")
|
||||
processes map[string]*process
|
||||
}
|
||||
|
||||
@ -7,12 +7,10 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
containerd "github.com/docker/containerd/api/grpc/types"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/docker/docker/restartmanager"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
@ -137,7 +135,6 @@ func (ctr *container) start(checkpoint string, checkpointDir string) error {
|
||||
ctr.closeFifos(iopipe)
|
||||
return err
|
||||
}
|
||||
ctr.startedAt = time.Now()
|
||||
ctr.systemPid = systemPid(resp.Container)
|
||||
close(createChan)
|
||||
|
||||
@ -164,7 +161,6 @@ func (ctr *container) handleEvent(e *containerd.Event) error {
|
||||
defer ctr.client.unlock(ctr.containerID)
|
||||
switch e.Type {
|
||||
case StateExit, StatePause, StateResume, StateOOM:
|
||||
var waitRestart chan error
|
||||
st := StateInfo{
|
||||
CommonStateInfo: CommonStateInfo{
|
||||
State: e.Type,
|
||||
@ -179,20 +175,8 @@ func (ctr *container) handleEvent(e *containerd.Event) error {
|
||||
st.ProcessID = e.Pid
|
||||
st.State = StateExitProcess
|
||||
}
|
||||
if st.State == StateExit && ctr.restartManager != nil {
|
||||
restart, wait, err := ctr.restartManager.ShouldRestart(e.Status, false, time.Since(ctr.startedAt))
|
||||
if err != nil {
|
||||
logrus.Warnf("libcontainerd: container %s %v", ctr.containerID, err)
|
||||
} else if restart {
|
||||
st.State = StateRestart
|
||||
ctr.restarting = true
|
||||
ctr.client.deleteContainer(e.Id)
|
||||
waitRestart = wait
|
||||
}
|
||||
}
|
||||
|
||||
// Remove process from list if we have exited
|
||||
// We need to do so here in case the Message Handler decides to restart it.
|
||||
switch st.State {
|
||||
case StateExit:
|
||||
ctr.clean()
|
||||
@ -204,32 +188,6 @@ func (ctr *container) handleEvent(e *containerd.Event) error {
|
||||
if err := ctr.client.backend.StateChanged(e.Id, st); err != nil {
|
||||
logrus.Errorf("libcontainerd: backend.StateChanged(): %v", err)
|
||||
}
|
||||
if st.State == StateRestart {
|
||||
go func() {
|
||||
err := <-waitRestart
|
||||
ctr.client.lock(ctr.containerID)
|
||||
defer ctr.client.unlock(ctr.containerID)
|
||||
ctr.restarting = false
|
||||
if err == nil {
|
||||
if err = ctr.start("", ""); err != nil {
|
||||
logrus.Errorf("libcontainerd: error restarting %v", err)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
st.State = StateExit
|
||||
ctr.clean()
|
||||
ctr.client.q.append(e.Id, func() {
|
||||
if err := ctr.client.backend.StateChanged(e.Id, st); err != nil {
|
||||
logrus.Errorf("libcontainerd: %v", err)
|
||||
}
|
||||
})
|
||||
if err != restartmanager.ErrRestartCanceled {
|
||||
logrus.Errorf("libcontainerd: %v", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
if e.Type == StatePause || e.Type == StateResume {
|
||||
ctr.pauseMonitor.handle(e.Type)
|
||||
}
|
||||
|
||||
@ -91,7 +91,6 @@ func (ctr *container) start() error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
ctr.startedAt = time.Now()
|
||||
|
||||
pid := newProcess.Pid()
|
||||
|
||||
@ -194,7 +193,6 @@ func (ctr *container) waitProcessExitCode(process *process) int {
|
||||
// equivalent to (in the linux containerd world) where events come in for
|
||||
// state change notifications from containerd.
|
||||
func (ctr *container) waitExit(process *process, isFirstProcessToStart bool) error {
|
||||
var waitRestart chan error
|
||||
logrus.Debugln("libcontainerd: waitExit() on pid", process.systemPid)
|
||||
|
||||
exitCode := ctr.waitProcessExitCode(process)
|
||||
@ -234,20 +232,7 @@ func (ctr *container) waitExit(process *process, isFirstProcessToStart bool) err
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
||||
if !ctr.manualStopRequested && ctr.restartManager != nil {
|
||||
restart, wait, err := ctr.restartManager.ShouldRestart(uint32(exitCode), false, time.Since(ctr.startedAt))
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
} else if restart {
|
||||
si.State = StateRestart
|
||||
ctr.restarting = true
|
||||
ctr.client.deleteContainer(ctr.containerID)
|
||||
waitRestart = wait
|
||||
}
|
||||
}
|
||||
|
||||
// Remove process from list if we have exited
|
||||
// We need to do so here in case the Message Handler decides to restart it.
|
||||
if si.State == StateExit {
|
||||
ctr.client.deleteContainer(ctr.containerID)
|
||||
}
|
||||
@ -268,24 +253,6 @@ func (ctr *container) waitExit(process *process, isFirstProcessToStart bool) err
|
||||
|
||||
logrus.Debugf("libcontainerd: waitExit() completed OK, %+v", si)
|
||||
|
||||
if si.State == StateRestart {
|
||||
go func() {
|
||||
err := <-waitRestart
|
||||
ctr.restarting = false
|
||||
if err == nil {
|
||||
if err = ctr.client.Create(ctr.containerID, "", "", ctr.ociSpec, ctr.options...); err != nil {
|
||||
logrus.Errorf("libcontainerd: error restarting %v", err)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
si.State = StateExit
|
||||
if err := ctr.client.backend.StateChanged(ctr.containerID, si); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -13,7 +13,6 @@ const (
|
||||
StatePause = "pause"
|
||||
StateResume = "resume"
|
||||
StateExit = "exit"
|
||||
StateRestart = "restart"
|
||||
StateRestore = "restore"
|
||||
StateStartProcess = "start-process"
|
||||
StateExitProcess = "exit-process"
|
||||
|
||||
Reference in New Issue
Block a user