-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.go
50 lines (42 loc) · 1.05 KB
/
monitor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package container // import "github.com/docker/docker/container"
import (
"context"
"time"
"github.com/containerd/log"
)
const (
loggerCloseTimeout = 10 * time.Second
)
// Reset puts a container into a state where it can be restarted again.
func (container *Container) Reset(lock bool) {
if lock {
container.Lock()
defer container.Unlock()
}
if err := container.CloseStreams(); err != nil {
log.G(context.TODO()).Errorf("%s: %s", container.ID, err)
}
// Re-create a brand new stdin pipe once the container exited
if container.Config.OpenStdin {
container.StreamConfig.NewInputPipes()
}
if container.LogDriver != nil {
if container.LogCopier != nil {
exit := make(chan struct{})
go func() {
container.LogCopier.Wait()
close(exit)
}()
timer := time.NewTimer(loggerCloseTimeout)
defer timer.Stop()
select {
case <-timer.C:
log.G(context.TODO()).Warn("Logger didn't exit in time: logs may be truncated")
case <-exit:
}
}
container.LogDriver.Close()
container.LogCopier = nil
container.LogDriver = nil
}
}