exec

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExitedInRunForever = errors.New("exec: command should not exit in RunForever")
)

Functions

func IsCmdRunning

func IsCmdRunning(cmd *exec.Cmd) bool

func IsCmdRunningHandler

func IsCmdRunningHandler(cmd *exec.Cmd) error

Types

type Cmd

type Cmd struct {
	// contains filtered or unexported fields
}

Cmd represents an external command being prepared or run basically. It also can combine several existing Command into a pipeline, just like running in shell: echo "3\n2\n1" | sort

A Cmd cannot be reused after calling its Run, Output or CombinedOutput methods.

func Command

func Command(name string, args ...string) *Cmd

Standard Command api follow os/exec.Command

func CommandContext

func CommandContext(ctx context.Context, name string, args ...string) *Cmd

Standard CommandContext api follow os/exec.CommandContext

func (*Cmd) CombinedOutput

func (c *Cmd) CombinedOutput() ([]byte, error)

CombinedOutput runs the command and returns its combined standard output and standard error.

func (*Cmd) CombinedOutputClosure

func (c *Cmd) CombinedOutputClosure() func(...string) ([]byte, error)

CombinedOutputClosure returns function closure allowing you to call this command latter. The closure runs the command and reads all bytes from combined standard output and standard error

func (*Cmd) Command

func (c *Cmd) Command() *exec.Cmd

Command returns a runnable *exec.Cmd

func (*Cmd) Output

func (c *Cmd) Output() ([]byte, error)

Output runs the command and returns its standard output. Any returned error will usually be of type *ExitError.

func (*Cmd) OutputClosure

func (c *Cmd) OutputClosure() func(...string) ([]byte, error)

OutputClosure returns a function closure allowing you to call this command latter. The closure runs the command and reads all bytes from standard output

echo := Command("echo").OutputClosure() echo("123") echo("321")

func (*Cmd) Pipe

func (c *Cmd) Pipe(name string, args ...string) *Cmd

Pipe creates a new command with given args and connects this command's standard output to new command's standard input

func (*Cmd) ReadStderr

func (c *Cmd) ReadStderr() ([]byte, error)

ReadStderr reads all bytes from command's standard error The command must have been finished by Wait.

func (*Cmd) ReadStdout

func (c *Cmd) ReadStdout() ([]byte, error)

ReadStdout reads all bytes from command's standard output The command must have been finished by Wait.

func (*Cmd) Run

func (c *Cmd) Run() error

Run starts the specified command and waits for it to complete.

The returned error is nil if the command runs, you can safely get output from Stdout() or error message from Stderr()

If the command starts but does not complete successfully, the error is of type *ExitError. Other error types may be returned for other situations.

If the calling goroutine has locked the operating system thread with runtime.LockOSThread and modified any inheritable OS-level thread state (for example, Linux or Plan 9 name spaces), the new process will inherit the caller's thread state./

func (*Cmd) RunForever

func (c *Cmd) RunForever(startup *Probe) error

func (*Cmd) SetCmdMutator

func (c *Cmd) SetCmdMutator(f func(name string, args []string) (string, []string))

SetCmdMutator set a mutator function to mutator the runtime command's name and args

func (*Cmd) SetIO

func (c *Cmd) SetIO(in io.Reader, out, err io.Writer)

SetIO sets standard input/output/err output for command

func (*Cmd) Start

func (c *Cmd) Start() error

Start starts the specified command but does not wait for it to complete.

The Wait method will return the exit code and release associated resources once the command exits.

func (*Cmd) Wait

func (c *Cmd) Wait() error

Wait waits for the command to exit and waits for any copying to stdin or copying from stdout or stderr to complete.

The command must have been started by Start.

The returned error is nil if the command runs, you can safely get output from Stdout() or error message from Stderr()

If the command fails to run or doesn't complete successfully, the error is of type *ExitError. Other error types may be returned for I/O problems.

If any of c.Stdin, c.Stdout or c.Stderr are not an *os.File, Wait also waits for the respective I/O loop copying to or from the process to complete.

Wait releases any resources associated with the Cmd.

type Probe

type Probe struct {
	// The action taken to determine the health of a cmd
	// Default to IsCmdRunningHandler
	Handler func(running *exec.Cmd) error `json:"handler,inline" protobuf:"bytes,1,opt,name=handler"`
	// Number of seconds after the container has started before liveness probes are initiated.
	// +optional
	InitialDelaySeconds int `json:"initialDelaySeconds,omitempty" protobuf:"varint,2,opt,name=initialDelaySeconds"`
	// How often (in seconds) to perform the probe.
	// Default to 1 seconds. Minimum value is 1.
	// +optional
	PeriodSeconds int `json:"periodSeconds,omitempty" protobuf:"varint,4,opt,name=periodSeconds"`
	// Minimum consecutive successes for the probe to be considered successful after having failed.
	// Defaults to 2. Must be 1 for liveness. Minimum value is 1.
	// +optional
	SuccessThreshold int `json:"successThreshold,omitempty" protobuf:"varint,5,opt,name=successThreshold"`
	// Minimum consecutive failures for the probe to be considered failed after having succeeded.
	// Defaults to 3. Minimum value is 1.
	// +optional
	FailureThreshold int `json:"failureThreshold,omitempty" protobuf:"varint,6,opt,name=failureThreshold"`
}

Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic.

type ProbeError

type ProbeError struct {
	// contains filtered or unexported fields
}

func (*ProbeError) Error

func (e *ProbeError) Error() string

Jump to

Keyboard shortcuts

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