subprocess

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotRunning = fmt.Errorf("The process isn't running")

ErrNotRunning is returned when performing an action against a stopped process.

Functions

func NewRunError

func NewRunError(cmd string, args []string, err error, stdout *bytes.Buffer, stderr *bytes.Buffer) error

NewRunError returns new RunError.

func RunCommand

func RunCommand(name string, arg ...string) (string, error)

RunCommand runs a command with optional arguments and returns stdout. If the command fails to start or returns a non-zero exit code then an error is returned containing the output of stderr. Deprecated: Use RunCommandContext.

func RunCommandCLocale

func RunCommandCLocale(name string, arg ...string) (string, error)

RunCommandCLocale runs a command with a LC_ALL=C.UTF-8 and LANGUAGE=en environment set with optional arguments and returns stdout. If the command fails to start or returns a non-zero exit code then an error is returned containing the output of stderr.

func RunCommandContext

func RunCommandContext(ctx context.Context, name string, arg ...string) (string, error)

RunCommandContext runs a command with optional arguments and returns stdout. If the command fails to start or returns a non-zero exit code then an error is returned containing the output of stderr.

func RunCommandInheritFds

func RunCommandInheritFds(ctx context.Context, filesInherit []*os.File, name string, arg ...string) (string, error)

RunCommandInheritFds runs a command with optional arguments and passes a set of file descriptors to the newly created process, returning stdout. If the command fails to start or returns a non-zero exit code then an error is returned containing the output of stderr.

func RunCommandSplit

func RunCommandSplit(ctx context.Context, env []string, filesInherit []*os.File, name string, arg ...string) (string, string, error)

RunCommandSplit runs a command with a supplied environment and optional arguments and returns the resulting stdout and stderr output as separate variables. If the supplied environment is nil then the default environment is used. If the command fails to start or returns a non-zero exit code then an error is returned containing the output of stderr too.

func RunCommandWithFds

func RunCommandWithFds(ctx context.Context, stdin io.Reader, stdout io.Writer, name string, arg ...string) error

RunCommandWithFds runs a command with supplied file descriptors.

func TryRunCommand

func TryRunCommand(name string, arg ...string) (string, error)

TryRunCommand runs the specified command up to 20 times with a 500ms delay between each call until it runs without an error. If after 20 times it is still failing then returns the error.

Types

type Process

type Process struct {
	Name     string         `yaml:"name"`
	Args     []string       `yaml:"args,flow"`
	Apparmor string         `yaml:"apparmor"`
	PID      int64          `yaml:"pid"`
	Stdin    io.ReadCloser  `yaml:"-"`
	Stdout   io.WriteCloser `yaml:"-"`
	Stderr   io.WriteCloser `yaml:"-"`

	UID       uint32 `yaml:"uid"`
	GID       uint32 `yaml:"gid"`
	SetGroups bool   `yaml:"set_groups"`

	SysProcAttr *syscall.SysProcAttr
	// contains filtered or unexported fields
}

Process struct. Has ability to set runtime arguments.

func ImportProcess

func ImportProcess(path string) (*Process, error)

ImportProcess imports a saved process into a subprocess object.

func NewProcess

func NewProcess(name string, args []string, stdoutPath string, stderrPath string) (*Process, error)

NewProcess is a constructor for a process object. Represents a process with argument config. stdoutPath and stderrPath arguments are optional. Returns an address to process.

func NewProcessWithFds

func NewProcessWithFds(name string, args []string, stdin io.ReadCloser, stdout io.WriteCloser, stderr io.WriteCloser) *Process

NewProcessWithFds is a constructor for a process object. Represents a process with argument config. Returns an address to process.

func (*Process) GetPid

func (p *Process) GetPid() (int64, error)

GetPid returns the pid for the given process object.

func (*Process) Reload

func (p *Process) Reload() error

Reload sends the SIGHUP signal to the given process object.

func (*Process) Restart

func (p *Process) Restart(ctx context.Context) error

Restart stop and starts the given process object.

func (*Process) Save

func (p *Process) Save(path string) error

Save will save the given process object to a YAML file. Can be imported at a later point.

func (*Process) SetApparmor

func (p *Process) SetApparmor(profile string)

SetApparmor allows setting the AppArmor profile.

func (*Process) SetCreds

func (p *Process) SetCreds(uid uint32, gid uint32)

SetCreds allows setting process credentials.

func (*Process) SetUserns

func (p *Process) SetUserns(uidMap []syscall.SysProcIDMap, gidMap []syscall.SysProcIDMap)

SetUserns allows running inside of a user namespace.

func (*Process) Signal

func (p *Process) Signal(signal int64) error

Signal will send a signal to the given process object given a signal value.

func (*Process) Start

func (p *Process) Start(ctx context.Context) error

Start will start the given process object.

func (*Process) StartWithFiles

func (p *Process) StartWithFiles(ctx context.Context, fds []*os.File) error

StartWithFiles will start the given process object with extra file descriptors.

func (*Process) Stop

func (p *Process) Stop() error

Stop will stop the given process object.

func (*Process) Wait

func (p *Process) Wait(ctx context.Context) (int64, error)

Wait will wait for the given process object exit code.

type RunError

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

RunError is the error from the RunCommand family of functions.

func (RunError) Error

func (e RunError) Error() string

func (RunError) StdErr

func (e RunError) StdErr() *bytes.Buffer

StdErr returns the stdout buffer.

func (RunError) StdOut

func (e RunError) StdOut() *bytes.Buffer

StdOut returns the stdout buffer.

func (RunError) Unwrap

func (e RunError) Unwrap() error

Jump to

Keyboard shortcuts

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