github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/client/logmon/client.go (about)

     1  package logmon
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"github.com/hashicorp/nomad/client/logmon/proto"
     8  	"github.com/hashicorp/nomad/helper/pluginutils/grpcutils"
     9  )
    10  
    11  type logmonClient struct {
    12  	client proto.LogMonClient
    13  
    14  	// doneCtx is closed when the plugin exits
    15  	doneCtx context.Context
    16  }
    17  
    18  const logmonRPCTimeout = 1 * time.Minute
    19  
    20  func (c *logmonClient) Start(cfg *LogConfig) error {
    21  	req := &proto.StartRequest{
    22  		LogDir:         cfg.LogDir,
    23  		StdoutFileName: cfg.StdoutLogFile,
    24  		StderrFileName: cfg.StderrLogFile,
    25  		MaxFiles:       uint32(cfg.MaxFiles),
    26  		MaxFileSizeMb:  uint32(cfg.MaxFileSizeMB),
    27  		StdoutFifo:     cfg.StdoutFifo,
    28  		StderrFifo:     cfg.StderrFifo,
    29  	}
    30  	ctx, cancel := context.WithTimeout(context.Background(), logmonRPCTimeout)
    31  	defer cancel()
    32  
    33  	_, err := c.client.Start(ctx, req)
    34  	return grpcutils.HandleGrpcErr(err, c.doneCtx)
    35  }
    36  
    37  func (c *logmonClient) Stop() error {
    38  	req := &proto.StopRequest{}
    39  	ctx, cancel := context.WithTimeout(context.Background(), logmonRPCTimeout)
    40  	defer cancel()
    41  
    42  	_, err := c.client.Stop(ctx, req)
    43  	return grpcutils.HandleGrpcErr(err, c.doneCtx)
    44  }