mirror of
https://github.com/docker/compose.git
synced 2025-09-24 02:07:49 +02:00
detect container is restarted
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
b387ba4a05
commit
cb3691154b
@ -138,11 +138,6 @@ func (c *monitor) Start(ctx context.Context) error {
|
|||||||
listener(newContainerEvent(event.TimeNano, ctr, api.ContainerEventRestarted))
|
listener(newContainerEvent(event.TimeNano, ctr, api.ContainerEventRestarted))
|
||||||
}
|
}
|
||||||
logrus.Debugf("container %s restarted", ctr.Name)
|
logrus.Debugf("container %s restarted", ctr.Name)
|
||||||
case events.ActionStop:
|
|
||||||
// when a container is in restarting phase, and we stop the application (abort-on-container-exit)
|
|
||||||
// we won't get any additional start+die events, just this stop as a proof container is down
|
|
||||||
logrus.Debugf("container %s stopped", ctr.Name)
|
|
||||||
containers.Remove(ctr.ID)
|
|
||||||
case events.ActionDie:
|
case events.ActionDie:
|
||||||
logrus.Debugf("container %s exited with code %d", ctr.Name, ctr.ExitCode)
|
logrus.Debugf("container %s exited with code %d", ctr.Name, ctr.ExitCode)
|
||||||
inspect, err := c.api.ContainerInspect(ctx, event.Actor.ID)
|
inspect, err := c.api.ContainerInspect(ctx, event.Actor.ID)
|
||||||
|
@ -42,7 +42,11 @@ func newLogPrinter(consumer api.LogConsumer) logPrinter {
|
|||||||
func (p *printer) HandleEvent(event api.ContainerEvent) {
|
func (p *printer) HandleEvent(event api.ContainerEvent) {
|
||||||
switch event.Type {
|
switch event.Type {
|
||||||
case api.ContainerEventExited:
|
case api.ContainerEventExited:
|
||||||
|
if event.Restarting {
|
||||||
|
p.consumer.Status(event.Source, fmt.Sprintf("exited with code %d (restarting)", event.ExitCode))
|
||||||
|
} else {
|
||||||
p.consumer.Status(event.Source, fmt.Sprintf("exited with code %d", event.ExitCode))
|
p.consumer.Status(event.Source, fmt.Sprintf("exited with code %d", event.ExitCode))
|
||||||
|
}
|
||||||
case api.ContainerEventRecreated:
|
case api.ContainerEventRecreated:
|
||||||
p.consumer.Status(event.Container.Labels[api.ContainerReplaceLabel], "has been recreated")
|
p.consumer.Status(event.Container.Labels[api.ContainerReplaceLabel], "has been recreated")
|
||||||
case api.ContainerEventLog, api.HookEventLog:
|
case api.ContainerEventLog, api.HookEventLog:
|
||||||
|
@ -245,7 +245,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
|||||||
if event.Type != api.ContainerEventStarted {
|
if event.Type != api.ContainerEventStarted {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if slices.Contains(attached, event.ID) {
|
if slices.Contains(attached, event.ID) && !event.Restarting {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user