2016-03-18 14:53:27 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2017-09-22 09:52:41 -04:00
|
|
|
"context"
|
2016-04-01 20:02:38 -04:00
|
|
|
|
2016-03-18 14:53:27 -04:00
|
|
|
"github.com/docker/docker/container"
|
|
|
|
"github.com/docker/docker/libcontainerd"
|
2017-09-22 09:52:41 -04:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/sirupsen/logrus"
|
2016-03-18 14:53:27 -04:00
|
|
|
)
|
|
|
|
|
2017-09-22 09:52:41 -04: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 16:34:07 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-08-01 13:00:38 -04:00
|
|
|
// Turn on servicing
|
|
|
|
spec.Windows.Servicing = true
|
2016-10-04 15:30:07 -04:00
|
|
|
|
2017-09-22 09:52:41 -04:00
|
|
|
copts, err := daemon.getLibcontainerdCreateOptions(c)
|
2016-10-04 15:30:07 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-09-22 09:52:41 -04: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 16:34:07 -04:00
|
|
|
}
|
2016-04-01 20:02:38 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|