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