-
Notifications
You must be signed in to change notification settings - Fork 2k
/
client.go
44 lines (35 loc) · 1.07 KB
/
client.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 logmon
import (
"context"
"time"
"github.com/hashicorp/nomad/client/logmon/proto"
"github.com/hashicorp/nomad/helper/pluginutils/grpcutils"
)
type logmonClient struct {
client proto.LogMonClient
// doneCtx is closed when the plugin exits
doneCtx context.Context
}
const logmonRPCTimeout = 1 * time.Minute
func (c *logmonClient) Start(cfg *LogConfig) error {
req := &proto.StartRequest{
LogDir: cfg.LogDir,
StdoutFileName: cfg.StdoutLogFile,
StderrFileName: cfg.StderrLogFile,
MaxFiles: uint32(cfg.MaxFiles),
MaxFileSizeMb: uint32(cfg.MaxFileSizeMB),
StdoutFifo: cfg.StdoutFifo,
StderrFifo: cfg.StderrFifo,
}
ctx, cancel := context.WithTimeout(context.Background(), logmonRPCTimeout)
defer cancel()
_, err := c.client.Start(ctx, req)
return grpcutils.HandleGrpcErr(err, c.doneCtx)
}
func (c *logmonClient) Stop() error {
req := &proto.StopRequest{}
ctx, cancel := context.WithTimeout(context.Background(), logmonRPCTimeout)
defer cancel()
_, err := c.client.Stop(ctx, req)
return grpcutils.HandleGrpcErr(err, c.doneCtx)
}