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
package hostsvc
import (
"context"
"errors"
"fmt"
"time"
)
const (
ProcOpHello = "hello"
ProcOpStart = "start"
ProcOpInspect = "inspect"
ProcOpStop = "stop"
ProcOpStopSlice = "stop-slice"
ProcOpResetFailed = "reset-failed"
ProcOpList = "list"
ProcOpIdentify = "identify"
ProcOpCheck = "check"
ProcOpWatch = "watch"
ProcOpShutdown = "shutdown"
)
const ProcStopCallTimeout = 3 * time.Minute
const (
procErrUnsupported = "unsupported"
)
type ProcClient interface {
Manager
Hello(ctx context.Context) (ProcHello, error)
Shutdown(ctx context.Context) error
}
type ProcRequest struct {
Op string `json:"op"`
Spec *UnitSpec `json:"spec,omitempty"`
Name string `json:"name,omitempty"`
Prefix string `json:"prefix,omitempty"`
Slice string `json:"slice,omitempty"`
PID int `json:"pid,omitempty"`
Identity *Identity `json:"identity,omitempty"`
}
type ProcHello struct {
Instance string `json:"instance"`
PID int `json:"pid"`
StartTicks uint64 `json:"startTicks"`
BootID string `json:"bootID"`
Started time.Time `json:"started"`
State string `json:"state"`
Socket string `json:"socket"`
}
type ProcResponse struct {
Err string `json:"err,omitempty"`
ErrKind string `json:"errKind,omitempty"`
Status *UnitStatus `json:"status,omitempty"`
Statuses []UnitStatus `json:"statuses,omitempty"`
Identity *Identity `json:"identity,omitempty"`
Observation *Observation `json:"observation,omitempty"`
Hello *ProcHello `json:"hello,omitempty"`
Event *UnitEvent `json:"event,omitempty"`
}
func ProcError(err error) ProcResponse {
r := ProcResponse{Err: err.Error()}
if errors.Is(err, ErrUnsupported) {
r.ErrKind = procErrUnsupported
}
return r
}
func (r ProcResponse) Error() error {
if r.Err == "" {
return nil
}
if r.ErrKind == procErrUnsupported {
return fmt.Errorf("%w: %s", ErrUnsupported, r.Err)
}
return errors.New(r.Err)
}
func ProcCapabilities() Capabilities {
return Capabilities{Backend: BackendProc, FDStore: procFDStore}
}