From cb3691154ba0ea8f48e39406e3dfcd9771039496 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 5 Sep 2025 09:22:48 +0200 Subject: [PATCH] detect container is restarted Signed-off-by: Nicolas De Loof --- pkg/compose/monitor.go | 5 ----- pkg/compose/printer.go | 6 +++++- pkg/compose/up.go | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/compose/monitor.go b/pkg/compose/monitor.go index b0f9cc0af..983eced9e 100644 --- a/pkg/compose/monitor.go +++ b/pkg/compose/monitor.go @@ -138,11 +138,6 @@ func (c *monitor) Start(ctx context.Context) error { listener(newContainerEvent(event.TimeNano, ctr, api.ContainerEventRestarted)) } 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: logrus.Debugf("container %s exited with code %d", ctr.Name, ctr.ExitCode) inspect, err := c.api.ContainerInspect(ctx, event.Actor.ID) diff --git a/pkg/compose/printer.go b/pkg/compose/printer.go index 079736869..9e1dd0150 100644 --- a/pkg/compose/printer.go +++ b/pkg/compose/printer.go @@ -42,7 +42,11 @@ func newLogPrinter(consumer api.LogConsumer) logPrinter { func (p *printer) HandleEvent(event api.ContainerEvent) { switch event.Type { case api.ContainerEventExited: - p.consumer.Status(event.Source, fmt.Sprintf("exited with code %d", event.ExitCode)) + 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)) + } case api.ContainerEventRecreated: p.consumer.Status(event.Container.Labels[api.ContainerReplaceLabel], "has been recreated") case api.ContainerEventLog, api.HookEventLog: diff --git a/pkg/compose/up.go b/pkg/compose/up.go index b3c4373e2..9c1e968d4 100644 --- a/pkg/compose/up.go +++ b/pkg/compose/up.go @@ -245,7 +245,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options if event.Type != api.ContainerEventStarted { return } - if slices.Contains(attached, event.ID) { + if slices.Contains(attached, event.ID) && !event.Restarting { return } eg.Go(func() error {