-
Notifications
You must be signed in to change notification settings - Fork 1
/
state.go
44 lines (39 loc) · 772 Bytes
/
state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package docker
import (
"fmt"
"github.com/dotcloud/docker/utils"
"sync"
"time"
)
type State struct {
sync.Mutex
Running bool
Pid int
ExitCode int
StartedAt time.Time
FinishedAt time.Time
Ghost bool
}
// String returns a human-readable description of the state
func (s *State) String() string {
if s.Running {
if s.Ghost {
return fmt.Sprintf("Ghost")
}
return fmt.Sprintf("Up %s", utils.HumanDuration(time.Now().Sub(s.StartedAt)))
}
return fmt.Sprintf("Exit %d", s.ExitCode)
}
func (s *State) setRunning(pid int) {
s.Running = true
s.Ghost = false
s.ExitCode = 0
s.Pid = pid
s.StartedAt = time.Now()
}
func (s *State) setStopped(exitCode int) {
s.Running = false
s.Pid = 0
s.FinishedAt = time.Now()
s.ExitCode = exitCode
}