Documentation
¶
Overview ¶
Package process provides the process runner implementation on the host.
Index ¶
- func CountProcessesByStatus(ctx context.Context) (map[string][]*procs.Process, error)
- func CountRunningPids() (uint64, error)
- type Op
- type OpOption
- func WithBashScriptContentsToRun(script string) OpOption
- func WithCommand(args ...string) OpOption
- func WithCommands(commands [][]string) OpOption
- func WithEnvs(envs ...string) OpOption
- func WithOutputFile(file *os.File) OpOption
- func WithRestartConfig(config RestartConfig) OpOption
- func WithRunAsBashScript() OpOption
- type Process
- type RestartConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountProcessesByStatus ¶ added in v0.1.5
CountProcessesByStatus counts all processes by its process status.
func CountRunningPids ¶ added in v0.3.1
CountRunningPids returns the number of running pids.
Types ¶
type OpOption ¶
type OpOption func(*Op)
func WithBashScriptContentsToRun ¶ added in v0.0.4
Sets the bash script contents to run. This is useful for running multiple/complicated commands.
func WithCommand ¶ added in v0.0.4
Add a new command to run.
func WithCommands ¶ added in v0.0.4
Sets/overwrites the commands to run.
func WithOutputFile ¶
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.
If the process exits with a non-zero exit code, stdout/stderr pipes may not work. If retry configuration is specified, specify the output file to read all the output.
func WithRestartConfig ¶
func WithRestartConfig(config RestartConfig) OpOption
Configures the process restart behavior. If the process exits with a non-zero exit code, stdout/stderr pipes may not work.
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 {
// Starts the process but does not wait for it to exit.
Start(ctx context.Context) error
// Aborts the process and waits for it to exit.
Abort(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
// Returns the current pid of the process.
PID() int32
// Returns the stdout reader.
// stderr/stdout piping sometimes doesn't work well on latest mac with io.ReadAll
// Use bufio.NewScanner(p.StdoutReader()) instead.
//
// If the process exits with a non-zero exit code, stdout/stderr pipes may not work.
// If retry configuration is specified, specify the output file to read all the output.
StdoutReader() io.Reader
// Returns the stderr reader.
// stderr/stdout piping sometimes doesn't work well on latest mac with io.ReadAll
// Use bufio.NewScanner(p.StderrReader()) instead.
//
// If the process exits with a non-zero exit code, stdout/stderr pipes may not work.
// If retry configuration is specified, specify the output file to read all the output.
StderrReader() io.Reader
}
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. If the process exits with a non-zero exit code, stdout/stderr pipes may not work. If retry configuration is specified, specify the output file to read all the output.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
bash-script-output-to-file
command
|
|
|
restart-commands
command
|
|
|
simple-command
command
|
|
|
simple-commands
command
|
|
|
stream-blocking-commands
command
|
|
|
stream-commands
command
|