@@ -17,7 +17,6 @@ import (
1717
1818 "github.com/Sirupsen/logrus"
1919 "github.com/docker/docker/daemon/exec"
20- "github.com/docker/docker/daemon/execdriver"
2120 "github.com/docker/docker/daemon/logger"
2221 "github.com/docker/docker/daemon/logger/jsonfilelog"
2322 "github.com/docker/docker/daemon/network"
@@ -27,6 +26,7 @@ import (
2726 "github.com/docker/docker/pkg/promise"
2827 "github.com/docker/docker/pkg/signal"
2928 "github.com/docker/docker/pkg/symlink"
29+ "github.com/docker/docker/restartmanager"
3030 "github.com/docker/docker/runconfig"
3131 runconfigopts "github.com/docker/docker/runconfig/opts"
3232 "github.com/docker/docker/volume"
@@ -74,13 +74,12 @@ type CommonContainer struct {
7474 HasBeenManuallyStopped bool // used for unless-stopped restart policy
7575 MountPoints map [string ]* volume.MountPoint
7676 HostConfig * containertypes.HostConfig `json:"-"` // do not serialize the host config in the json, otherwise we'll make the container unportable
77- Command * execdriver.Command `json:"-"`
78- monitor * containerMonitor
79- ExecCommands * exec.Store `json:"-"`
77+ ExecCommands * exec.Store `json:"-"`
8078 // logDriver for closing
81- LogDriver logger.Logger `json:"-"`
82- LogCopier * logger.Copier `json:"-"`
83- attachContext * attachContext
79+ LogDriver logger.Logger `json:"-"`
80+ LogCopier * logger.Copier `json:"-"`
81+ restartManager restartmanager.RestartManager
82+ attachContext * attachContext
8483}
8584
8685// NewBaseContainer creates a new container with its
@@ -276,19 +275,9 @@ func (container *Container) GetRootResourcePath(path string) (string, error) {
276275// ExitOnNext signals to the monitor that it should not restart the container
277276// after we send the kill signal.
278277func (container * Container ) ExitOnNext () {
279- container .monitor .ExitOnNext ()
280- }
281-
282- // Resize changes the TTY of the process running inside the container
283- // to the given height and width. The container must be running.
284- func (container * Container ) Resize (h , w int ) error {
285- if container .Command .ProcessConfig .Terminal == nil {
286- return fmt .Errorf ("Container %s does not have a terminal ready" , container .ID )
287- }
288- if err := container .Command .ProcessConfig .Terminal .Resize (h , w ); err != nil {
289- return err
278+ if container .restartManager != nil {
279+ container .restartManager .Cancel ()
290280 }
291- return nil
292281}
293282
294283// HostConfigPath returns the path to the container's JSON hostconfig
@@ -897,19 +886,33 @@ func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epC
897886
898887// UpdateMonitor updates monitor configure for running container
899888func (container * Container ) UpdateMonitor (restartPolicy containertypes.RestartPolicy ) {
900- monitor := container .monitor
901- // No need to update monitor if container hasn't got one
902- // monitor will be generated correctly according to container
903- if monitor == nil {
904- return
889+ type policySetter interface {
890+ SetPolicy (containertypes.RestartPolicy )
891+ }
892+
893+ if rm , ok := container .RestartManager (false ).(policySetter ); ok {
894+ rm .SetPolicy (restartPolicy )
895+ }
896+ }
897+
898+ // FullHostname returns hostname and optional domain appended to it.
899+ func (container * Container ) FullHostname () string {
900+ fullHostname := container .Config .Hostname
901+ if container .Config .Domainname != "" {
902+ fullHostname = fmt .Sprintf ("%s.%s" , fullHostname , container .Config .Domainname )
905903 }
904+ return fullHostname
905+ }
906906
907- monitor .mux .Lock ()
908- // to check whether restart policy has changed.
909- if restartPolicy .Name != "" && ! monitor .restartPolicy .IsSame (& restartPolicy ) {
910- monitor .restartPolicy = restartPolicy
907+ // RestartManager returns the current restartmanager instace connected to container.
908+ func (container * Container ) RestartManager (reset bool ) restartmanager.RestartManager {
909+ if reset {
910+ container .RestartCount = 0
911+ }
912+ if container .restartManager == nil {
913+ container .restartManager = restartmanager .New (container .HostConfig .RestartPolicy )
911914 }
912- monitor . mux . Unlock ()
915+ return container . restartManager
913916}
914917
915918type attachContext struct {
0 commit comments