state.go
a27b4b8c
 package docker
 
 import (
45a8bba1
 	"fmt"
2e69e172
 	"github.com/dotcloud/docker/utils"
7c2b085d
 	"sync"
333abbf8
 	"time"
a27b4b8c
 )
 
 type State struct {
1cf9c80e
 	sync.Mutex
fbf85e2e
 	Running    bool
 	Pid        int
 	ExitCode   int
 	StartedAt  time.Time
2eb404ab
 	FinishedAt time.Time
fbf85e2e
 	Ghost      bool
a27b4b8c
 }
 
904b0ab5
 // String returns a human-readable description of the state
 func (s *State) String() string {
 	if s.Running {
313d13ea
 		if s.Ghost {
b1fbebb4
 			return fmt.Sprintf("Ghost")
313d13ea
 		}
2e69e172
 		return fmt.Sprintf("Up %s", utils.HumanDuration(time.Now().Sub(s.StartedAt)))
904b0ab5
 	}
bcfe2aa2
 	return fmt.Sprintf("Exit %d", s.ExitCode)
904b0ab5
 }
 
a27b4b8c
 func (s *State) setRunning(pid int) {
 	s.Running = true
91520838
 	s.Ghost = false
a27b4b8c
 	s.ExitCode = 0
 	s.Pid = pid
64fc86fb
 	s.StartedAt = time.Now()
a27b4b8c
 }
 
 func (s *State) setStopped(exitCode int) {
 	s.Running = false
 	s.Pid = 0
2eb404ab
 	s.FinishedAt = time.Now()
a27b4b8c
 	s.ExitCode = exitCode
 }