1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/state.go

54 lines
854 B
Go
Raw Normal View History

2013-01-18 16:13:39 -08:00
package docker
import (
2013-03-12 05:36:37 -07:00
"fmt"
2013-05-14 22:37:35 +00:00
"github.com/dotcloud/docker/utils"
"sync"
2013-01-28 14:30:05 -08:00
"time"
2013-01-18 16:13:39 -08:00
)
type State struct {
2013-01-22 17:30:37 -08:00
Running bool
Pid int
ExitCode int
StartedAt time.Time
l *sync.Mutex
2013-04-11 09:26:17 -07:00
Ghost bool
2013-01-18 16:13:39 -08:00
}
// String returns a human-readable description of the state
func (s *State) String() string {
if s.Running {
2013-04-11 09:26:17 -07:00
if s.Ghost {
return fmt.Sprintf("Ghost")
2013-04-11 09:26:17 -07:00
}
2013-05-14 22:37:35 +00:00
return fmt.Sprintf("Up %s", utils.HumanDuration(time.Now().Sub(s.StartedAt)))
}
2013-01-29 03:18:07 -08:00
return fmt.Sprintf("Exit %d", s.ExitCode)
}
2013-01-18 16:13:39 -08:00
func (s *State) setRunning(pid int) {
s.Running = true
s.ExitCode = 0
s.Pid = pid
s.StartedAt = time.Now()
2013-01-18 16:13:39 -08:00
}
func (s *State) setStopped(exitCode int) {
s.Running = false
s.Pid = 0
s.ExitCode = exitCode
}
func (s *State) initLock() {
s.l = &sync.Mutex{}
}
func (s *State) lock() {
s.l.Lock()
}
func (s *State) unlock() {
s.l.Unlock()
}