mirror of https://github.com/containers/podman.git
Fix journald logs --follow
Previously, --follow with a podman logs using journald would not exit Signed-off-by: Ashley Cui <acui@redhat.com>
This commit is contained in:
parent
f2d057c943
commit
9016387bba
|
@ -11,8 +11,10 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containers/podman/v2/libpod/define"
|
||||
"github.com/containers/podman/v2/libpod/logs"
|
||||
journal "github.com/coreos/go-systemd/v22/sdjournal"
|
||||
"github.com/hpcloud/tail/watch"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -65,8 +67,12 @@ func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOption
|
|||
if options.Tail == math.MaxInt64 {
|
||||
r.Rewind()
|
||||
}
|
||||
state, err := c.State()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if options.Follow {
|
||||
if options.Follow && state == define.ContainerStateRunning {
|
||||
go func() {
|
||||
done := make(chan bool)
|
||||
until := make(chan time.Time)
|
||||
|
@ -78,6 +84,21 @@ func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOption
|
|||
// nothing to do anymore
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
for {
|
||||
state, err := c.State()
|
||||
if err != nil {
|
||||
until <- time.Time{}
|
||||
logrus.Error(err)
|
||||
break
|
||||
}
|
||||
time.Sleep(watch.POLL_DURATION)
|
||||
if state != define.ContainerStateRunning && state != define.ContainerStatePaused {
|
||||
until <- time.Time{}
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
follower := FollowBuffer{logChannel}
|
||||
err := r.Follow(until, follower)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue