monitor.go 933 B

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