2018-02-05 21:05:59 +00:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2016-03-18 18:53:27 +00:00
|
|
|
|
|
|
|
import (
|
2017-09-22 13:52:41 +00:00
|
|
|
"context"
|
2016-04-02 00:02:38 +00:00
|
|
|
|
2016-03-18 18:53:27 +00:00
|
|
|
"github.com/docker/docker/container"
|
|
|
|
"github.com/docker/docker/libcontainerd"
|
2017-09-22 13:52:41 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/sirupsen/logrus"
|
2016-03-18 18:53:27 +00:00
|
|
|
)
|
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
// postRunProcessing starts a servicing container if required
|
|
|
|
func (daemon *Daemon) postRunProcessing(c *container.Container, ei libcontainerd.EventInfo) error {
|
|
|
|
if ei.ExitCode == 0 && ei.UpdatePending {
|
|
|
|
spec, err := daemon.createSpec(c)
|
2016-04-13 20:34:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-08-01 17:00:38 +00:00
|
|
|
// Turn on servicing
|
|
|
|
spec.Windows.Servicing = true
|
2016-10-04 19:30:07 +00:00
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
copts, err := daemon.getLibcontainerdCreateOptions(c)
|
2016-10-04 19:30:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
// Create a new servicing container, which will start, complete the
|
|
|
|
// update, and merge back the results if it succeeded, all as part of
|
|
|
|
// the below function call.
|
|
|
|
ctx := context.Background()
|
|
|
|
svcID := c.ID + "_servicing"
|
|
|
|
logger := logrus.WithField("container", svcID)
|
|
|
|
if err := daemon.containerd.Create(ctx, svcID, spec, copts); err != nil {
|
|
|
|
c.SetExitCode(-1)
|
|
|
|
return errors.Wrap(err, "post-run update servicing failed")
|
|
|
|
}
|
|
|
|
_, err = daemon.containerd.Start(ctx, svcID, "", false, nil)
|
|
|
|
if err != nil {
|
|
|
|
logger.WithError(err).Warn("failed to run servicing container")
|
|
|
|
if err := daemon.containerd.Delete(ctx, svcID); err != nil {
|
|
|
|
logger.WithError(err).Warn("failed to delete servicing container")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if _, _, err := daemon.containerd.DeleteTask(ctx, svcID); err != nil {
|
|
|
|
logger.WithError(err).Warn("failed to delete servicing container task")
|
|
|
|
}
|
|
|
|
if err := daemon.containerd.Delete(ctx, svcID); err != nil {
|
|
|
|
logger.WithError(err).Warn("failed to delete servicing container")
|
|
|
|
}
|
2016-04-13 20:34:07 +00:00
|
|
|
}
|
2016-04-02 00:02:38 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|