process

package
v0.0.1-alpha7 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package process provides the process runner implementation on the host.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Op

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

type OpOption

type OpOption func(*Op)

func WithEnvs

func WithEnvs(envs ...string) OpOption

Add a new environment variable to the process in the format of `KEY=VALUE`.

func WithOutputFile

func WithOutputFile(file *os.File) OpOption

Sets the file to which stderr and stdout will be written. For instance, you can set it to os.Stderr to pipe all the sub-process stderr and stdout to the parent process's stderr. Default is to set the os.Pipe to forward its output via io.ReadCloser.

func WithRestartConfig

func WithRestartConfig(config RestartConfig) OpOption

Configures the process restart behavior.

func WithRunAsBashScript

func WithRunAsBashScript() OpOption

Set true to run commands as a bash script. This is useful for running multiple/complicated commands.

type Process

type Process interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error

	// Waits for the process to exit and returns the error, if any.
	// If the command completes successfully, the error will be nil.
	Wait() <-chan error

	PID() int32

	StdoutReader() io.Reader
	StderrReader() io.Reader
}

func New

func New(commands [][]string, opts ...OpOption) (Process, error)

type RestartConfig

type RestartConfig struct {
	// Set true to restart the process on error exit.
	OnError bool
	// Set the maximum number of restarts.
	Limit int
	// Set the interval between restarts.
	Interval time.Duration
}

RestartConfig is the configuration for the process restart.

Jump to

Keyboard shortcuts

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