github.com/manicqin/nomad@v0.9.5/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  		FileExtension:  cfg.FileExtension,
    30  	}
    31  	ctx, cancel := context.WithTimeout(context.Background(), logmonRPCTimeout)
    32  	defer cancel()
    33  
    34  	_, err := c.client.Start(ctx, req)
    35  	return grpcutils.HandleGrpcErr(err, c.doneCtx)
    36  }
    37  
    38  func (c *logmonClient) Stop() error {
    39  	req := &proto.StopRequest{}
    40  	ctx, cancel := context.WithTimeout(context.Background(), logmonRPCTimeout)
    41  	defer cancel()
    42  
    43  	_, err := c.client.Stop(ctx, req)
    44  	return grpcutils.HandleGrpcErr(err, c.doneCtx)
    45  }