Stop log producer before restarting container

pull/18461/head
NiniOak 1 year ago
parent facd5b0ec1
commit 59bfc81d49

@ -68,14 +68,17 @@ func (g ConnectContainer) GetPort(port int) (int, error) {
} }
func (g ConnectContainer) Restart() error { func (g ConnectContainer) Restart() error {
_, err := g.GetStatus() var deferClean utils.ResettableDefer
if err != nil { defer deferClean.Execute()
return fmt.Errorf("error fetching sidecar container state %s", err)
if utils.FollowLog {
if err := g.container.StopLogProducer(); err != nil {
return fmt.Errorf("stopping log producer: %w", err)
}
} }
fmt.Printf("Stopping container: %s\n", g.GetName()) fmt.Printf("Stopping container: %s\n", g.GetName())
err = g.container.Stop(g.ctx, nil) err := g.container.Stop(g.ctx, nil)
if err != nil { if err != nil {
return fmt.Errorf("error stopping sidecar container %s", err) return fmt.Errorf("error stopping sidecar container %s", err)
} }
@ -85,6 +88,17 @@ func (g ConnectContainer) Restart() error {
if err != nil { if err != nil {
return fmt.Errorf("error starting sidecar container %s", err) return fmt.Errorf("error starting sidecar container %s", err)
} }
if utils.FollowLog {
if err := g.container.StartLogProducer(g.ctx); err != nil {
return fmt.Errorf("starting log producer: %w", err)
}
g.container.FollowOutput(&LogConsumer{})
deferClean.Add(func() {
_ = g.container.StopLogProducer()
})
}
return nil return nil
} }

Loading…
Cancel
Save