docker/state.go

43 строки
723 B
Go
Исходник Обычный вид История

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