mirror of
https://github.com/containers/podman.git
synced 2025-06-30 15:49:03 +08:00
Merge pull request #6591 from jgallucci32/patch-1
Merged request to fix -f to stop following logs
This commit is contained in:
@ -2,6 +2,7 @@ package libpod
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/containers/libpod/libpod/define"
|
"github.com/containers/libpod/libpod/define"
|
||||||
"github.com/containers/libpod/libpod/logs"
|
"github.com/containers/libpod/libpod/logs"
|
||||||
@ -72,5 +73,27 @@ func (c *Container) readFromLogFile(options *logs.LogOptions, logChannel chan *l
|
|||||||
}
|
}
|
||||||
options.WaitGroup.Done()
|
options.WaitGroup.Done()
|
||||||
}()
|
}()
|
||||||
|
// Check if container is still running or paused
|
||||||
|
go func() {
|
||||||
|
if options.Follow {
|
||||||
|
for {
|
||||||
|
state, err := c.State()
|
||||||
|
if err != nil && errors.Cause(err) != define.ErrNoSuchCtr {
|
||||||
|
logrus.Error(err)
|
||||||
|
break
|
||||||
|
} else if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if state != define.ContainerStateRunning && state != define.ContainerStatePaused {
|
||||||
|
err := t.Stop()
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -288,4 +288,16 @@ var _ = Describe("Podman logs", func() {
|
|||||||
logc.WaitWithDefaultTimeout()
|
logc.WaitWithDefaultTimeout()
|
||||||
Expect(logc).To(Exit(0))
|
Expect(logc).To(Exit(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("follow output stopped container", func() {
|
||||||
|
containerName := "logs-f"
|
||||||
|
|
||||||
|
logc := podmanTest.Podman([]string{"run", "--name", containerName, "-d", ALPINE})
|
||||||
|
logc.WaitWithDefaultTimeout()
|
||||||
|
Expect(logc).To(Exit(0))
|
||||||
|
|
||||||
|
results := podmanTest.Podman([]string{"logs", "-f", containerName})
|
||||||
|
results.WaitWithDefaultTimeout()
|
||||||
|
Expect(results).To(Exit(0))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user