Skip to content

Commit cb36911

Browse files
ndeloofglours
authored andcommitted
detect container is restarted
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent b387ba4 commit cb36911

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

pkg/compose/monitor.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ func (c *monitor) Start(ctx context.Context) error {
138138
listener(newContainerEvent(event.TimeNano, ctr, api.ContainerEventRestarted))
139139
}
140140
logrus.Debugf("container %s restarted", ctr.Name)
141-
case events.ActionStop:
142-
// when a container is in restarting phase, and we stop the application (abort-on-container-exit)
143-
// we won't get any additional start+die events, just this stop as a proof container is down
144-
logrus.Debugf("container %s stopped", ctr.Name)
145-
containers.Remove(ctr.ID)
146141
case events.ActionDie:
147142
logrus.Debugf("container %s exited with code %d", ctr.Name, ctr.ExitCode)
148143
inspect, err := c.api.ContainerInspect(ctx, event.Actor.ID)

pkg/compose/printer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ func newLogPrinter(consumer api.LogConsumer) logPrinter {
4242
func (p *printer) HandleEvent(event api.ContainerEvent) {
4343
switch event.Type {
4444
case api.ContainerEventExited:
45-
p.consumer.Status(event.Source, fmt.Sprintf("exited with code %d", event.ExitCode))
45+
if event.Restarting {
46+
p.consumer.Status(event.Source, fmt.Sprintf("exited with code %d (restarting)", event.ExitCode))
47+
} else {
48+
p.consumer.Status(event.Source, fmt.Sprintf("exited with code %d", event.ExitCode))
49+
}
4650
case api.ContainerEventRecreated:
4751
p.consumer.Status(event.Container.Labels[api.ContainerReplaceLabel], "has been recreated")
4852
case api.ContainerEventLog, api.HookEventLog:

pkg/compose/up.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
245245
if event.Type != api.ContainerEventStarted {
246246
return
247247
}
248-
if slices.Contains(attached, event.ID) {
248+
if slices.Contains(attached, event.ID) && !event.Restarting {
249249
return
250250
}
251251
eg.Go(func() error {

0 commit comments

Comments
 (0)