fix compile error
[platform/upstream/docker-engine.git] / container / monitor.go
1 package container
2
3 import (
4         "time"
5
6         "github.com/Sirupsen/logrus"
7 )
8
9 const (
10         loggerCloseTimeout = 10 * time.Second
11 )
12
13 // Reset puts a container into a state where it can be restarted again.
14 func (container *Container) Reset(lock bool) {
15         if lock {
16                 container.Lock()
17                 defer container.Unlock()
18         }
19
20         if err := container.CloseStreams(); err != nil {
21                 logrus.Errorf("%s: %s", container.ID, err)
22         }
23
24         // Re-create a brand new stdin pipe once the container exited
25         if container.Config.OpenStdin {
26                 container.StreamConfig.NewInputPipes()
27         }
28
29         if container.LogDriver != nil {
30                 if container.LogCopier != nil {
31                         exit := make(chan struct{})
32                         go func() {
33                                 container.LogCopier.Wait()
34                                 close(exit)
35                         }()
36                         select {
37                         case <-time.After(loggerCloseTimeout):
38                                 logrus.Warn("Logger didn't exit in time: logs may be truncated")
39                         case <-exit:
40                         }
41                 }
42                 container.LogDriver.Close()
43                 container.LogCopier = nil
44                 container.LogDriver = nil
45         }
46 }