command

package
v5.10.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2019 License: MIT, MIT Imports: 10 Imported by: 0

Documentation

Overview

Package command provides system command execution.

Index

Constants

View Source
const (
	// TimeoutOutput specifies the command execution output in the
	// event of an execution timeout.
	TimeoutOutput string = "Execution timed out\n"

	// OKExitStatus specifies the command execution exit status
	// that indicates a success, A-OK.
	OKExitStatus int = 0

	// TimeoutExitStatus specifies the command execution exit
	// status in the event of an execution timeout.
	TimeoutExitStatus int = 2

	// FallbackExitStatus specifies the command execution exit
	// status used when golang is unable to determine the exit
	// status.
	FallbackExitStatus int = 3
)

Variables

This section is empty.

Functions

func Command

func Command(ctx context.Context, command string) *exec.Cmd

Command returns a command to execute a script through a shell.

func KillProcess

func KillProcess(cmd *exec.Cmd) error

KillProcess kills the command process and any child processes

func SetProcessGroup

func SetProcessGroup(cmd *exec.Cmd)

SetProcessGroup sets the process group of the command process

Types

type ExecutionRequest

type ExecutionRequest struct {
	// Command is the command to be executed.
	Command string

	// Env ...
	Env []string

	// Input to provide the command via STDIN.
	Input string

	// Execution timeout in seconds, will be set to a default if
	// not specified.
	Timeout int

	// Name is the name of the resource that is invoking the execution.
	Name string

	// InProgress is a map of checks that are still in execution, this is
	// necessary for a check or hook to escape zombie processes.
	InProgress map[string]*types.CheckConfig

	// InProgressMu is the mutex for the InProgress map.
	InProgressMu *sync.Mutex
}

ExecutionRequest provides information about a system command execution, somewhat of an abstraction intended to be used for Sensu check, mutator, and handler execution.

func FakeCommand

func FakeCommand(command string, args ...string) ExecutionRequest

FakeCommand takes a command and (optionally) command args and will execute the TestHelperProcess test within the package FakeCommand is called from.

func (*ExecutionRequest) Execute

Execute executes a system command (fork/exec) with a timeout, optionally writing to STDIN, capturing its combined output (STDOUT/ERR) and exit status.

type ExecutionResponse

type ExecutionResponse struct {
	// Combined command execution STDOUT/ERR.
	Output string

	// Command execution exit status.
	Status int

	// Duration provides command execution time in seconds.
	Duration float64
}

ExecutionResponse provides the response information of an ExecutionRequest.

func FixtureExecutionResponse

func FixtureExecutionResponse(status int, output string) *ExecutionResponse

FixtureExecutionResponse returns an Execution for use in testing

type Executor

type Executor interface {
	Execute(context.Context, ExecutionRequest) (*ExecutionResponse, error)
}

Executor ...

func NewExecutor

func NewExecutor() Executor

NewExecutor ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL