subproc

package
v1.6.112 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package subproc provides helper utilities for executing the Nomad binary as a child process of the Nomad agent.

The main entrypoint is the Do function, in which the given MainFunc will be executed as a sub-process if the first argument matches the subcommand.

Context can be used to create a context.Context object with a given timeout, and is expected to be used in conjunction with SetExpiration which uses the context's termination to forcefully terminate the child process if it has not exited by itself.

Index

Constants

View Source
const (
	// ExitSuccess indicates the subprocess completed successfully.
	ExitSuccess = iota

	// ExitFailure indicates the subprocess terminated unsuccessfully.
	ExitFailure

	// ExitTimeout indicates the subprocess timed out before completion.
	ExitTimeout
)

Variables

This section is empty.

Functions

func Context

func Context(timeout time.Duration) (context.Context, context.CancelFunc)

Context creates a context setup with the given timeout.

func Do

func Do(name string, f MainFunc)

Do f if nomad was launched as, "nomad [name]". This process will exit without running any other part of Nomad.

func Log

func Log(r io.Reader, f func(msg string, args ...any))

Log the given output to the logger.

r should be a buffer containing output (typically combined stdin + stdout) f should be an HCLogger Print method (e.g. log.Debug)

func Print

func Print(format string, args ...any)

Print the given message to standard error.

func Self

func Self() string

Self returns the path to the executable of this process.

func SetExpiration

func SetExpiration(ctx context.Context)

SetExpiration is used to ensure the process terminates, once ctx is complete. A short grace period is added to allow any cleanup to happen first.

Types

type MainFunc

type MainFunc func() int

MainFunc is the function that runs for this sub-process.

The return value is a process exit code.

Jump to

Keyboard shortcuts

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