commands

package
v0.0.0-...-8018142 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MPL-2.0 Imports: 15 Imported by: 2

README

commands

GoDoc

Documentation

Overview

Package commands provides a wrapper around os/exec to consistently manage process execution, cancellation of their child processes, timeouts, logging, arg parsing, and correct shutdown.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseArgs

func ParseArgs(raw interface{}) (executable string, args []string, err error)

ParseArgs parses the executable and its arguments from supported types.

Types

type Command

type Command struct {
	Name    string // this gets used only in logs, defaults to Exec
	Cmd     *exec.Cmd
	Exec    string
	Args    []string
	Timeout time.Duration
	// contains filtered or unexported fields
}

Command wraps an os/exec.Cmd with a timeout, logging, and arg parsing.

func NewCommand

func NewCommand(rawArgs interface{}, timeout time.Duration, fields log.Fields) (*Command, error)

NewCommand parses JSON config into a Command

func (*Command) EnvName

func (c *Command) EnvName() string

EnvName formats Name for use as an environment variable name (PID).

func (*Command) Kill

func (c *Command) Kill()

Kill sends a kill signal to the underlying process if it still exists, as well as all its children

func (*Command) Run

func (c *Command) Run(pctx context.Context, bus *events.EventBus)

Run creates an exec.Cmd for the Command and runs it asynchronously. If the parent context is closed/canceled this will terminate the child process and do any cleanup we need.

func (*Command) Term

func (c *Command) Term()

Term sends a terminate signal to the underlying process if it still exists, as well as all its children

Jump to

Keyboard shortcuts

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