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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package host
import (
"context"
"syscall"
"time"
)
type Backend string
const (
BackendSystemdUser Backend = "systemd-user"
BackendProc Backend = "proc"
)
type Capabilities struct {
Backend Backend
EnforcesLimits bool
OOMKillReported bool
FDStore bool
PrivateHostname bool
Journal bool
}
type Restart string
const (
RestartNo Restart = "no"
RestartOnFailure Restart = "on-failure"
RestartAlways Restart = "always"
)
type ActiveState string
const (
Active ActiveState = "active"
Activating ActiveState = "activating"
Deactivating ActiveState = "deactivating"
Reloading ActiveState = "reloading"
Inactive ActiveState = "inactive"
Failed ActiveState = "failed"
NotFound ActiveState = "not-found"
)
type Output struct {
StdoutFile string
StderrFile string
}
type Limits struct {
MemoryMax uint64
CPUWeight uint64
CPUQuotaPercent int
TasksMax uint64
}
type UnitSpec struct {
Name string
Description string
Exec []string
Env []string
EnvFiles []string
WorkDir string
Output Output
Limits Limits
OOMPolicy string
KillSignal syscall.Signal
StopTimeout time.Duration
After []string
Wants []string
Slice string
Restart Restart
PrivateHostname string
FDStore int
Delegate bool
}
type UnitStatus struct {
Name string
State ActiveState
SubState string
Result string
MainPID int
InvocationID string
ExecMainCode int32
ExecMainStatus int32
ActiveSince time.Time
Adopted bool
Description string
Backend Backend
}
type UnitEvent struct {
Name string
Status UnitStatus
}
type Verdict int
const (
VerdictUnknown Verdict = iota
VerdictRunning
VerdictLost
)
func (v Verdict) String() string {
switch v {
case VerdictRunning:
return "Running"
case VerdictLost:
return "Lost"
}
return "Unknown"
}
type LostReason string
const (
LostHostRebooted LostReason = "HostRebooted"
LostUnitGone LostReason = "UnitGone"
LostUnitExited LostReason = "UnitExited"
LostUnitFailed LostReason = "UnitFailed"
LostOOMKilled LostReason = "OOMKilled"
LostIdentityMismatch LostReason = "IdentityMismatch"
)
type Identity struct {
Unit string
InvocationID string
PID int
StartTicks uint64
BootID string
Backend Backend
Manager string
}
type Observation struct {
Verdict Verdict
Reason LostReason
Detail string
Status UnitStatus
Stopped bool
}
type Units interface {
Start(ctx context.Context, spec UnitSpec) (UnitStatus, error)
Inspect(ctx context.Context, name string) (UnitStatus, error)
Stop(ctx context.Context, name string) error
ResetFailed(ctx context.Context, name string) error
List(ctx context.Context, prefix string) ([]UnitStatus, error)
Identify(ctx context.Context, name string, pid int) (Identity, error)
Check(ctx context.Context, want Identity) (Observation, error)
StopSlice(ctx context.Context, slice string) error
Watch(ctx context.Context, prefix string) (<-chan UnitEvent, error)
Capabilities() Capabilities
Close() error
}
type Processes interface {
Wait(ctx context.Context, pid int, startTicks uint64) error
}
type Clock interface {
Now() time.Time
After(d time.Duration) <-chan time.Time
}