containerrun

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ProcessStart is the command to restart the suspended child processes.
	ProcessStart = "START"
	// ProcessStop is the command to stop and suspend the child processes.
	ProcessStop = "STOP"
	// SignalQuit is the command to send a QUIT signal to the child processes.
	SignalQuit = "QUIT"
)

Variables

This section is empty.

Functions

func Run

func Run(
	runner Runner,
	conditionRunner Runner,
	commandChecker Checker,
	listener PacketListener,
	stdio Stdio,
	args []string,
	jobName string,
	processName string,
	postStartCommandName string,
	postStartCommandArgs []string,
	postStartConditionCommandName string,
	postStartConditionCommandArgs []string,
) error

func RunWithTestChan added in v0.0.2

func RunWithTestChan(
	runner Runner,
	conditionRunner Runner,
	commandChecker Checker,
	listener PacketListener,
	stdio Stdio,
	args []string,
	jobName string,
	processName string,
	postStartCommandName string,
	postStartCommandArgs []string,
	postStartConditionCommandName string,
	postStartConditionCommandArgs []string,
	testSigTermChan chan struct{},
) error

Run implements the logic for the container-run CLI command.

func SetBasePath added in v0.0.3

func SetBasePath(newPath string)

func WriteBPMscript added in v0.0.2

func WriteBPMscript() error

WriteBPMscript creates a bpm script for drain script compatibility.

Types

type Checker

type Checker interface {
	Check(command string) bool
}

Checker is the interface that wraps the basic Check method.

type CmdRun

type CmdRun func(
	runner Runner,
	conditionRunner Runner,
	commandChecker Checker,
	listener PacketListener,
	stdio Stdio,
	args []string,
	jobName string,
	processName string,
	postStartCommandName string,
	postStartCommandArgs []string,
	postStartConditionCommandName string,
	postStartConditionCommandArgs []string,
) error

CmdRun represents the signature for the top-level Run command.

type Command

type Command struct {
	Name string
	Arg  []string
}

Command represents a command to be run.

type CommandChecker

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

CommandChecker satisfies the Checker interface.

func NewCommandChecker

func NewCommandChecker(
	osStat func(string) (os.FileInfo, error),
	execLookPath func(file string) (string, error),
) *CommandChecker

NewCommandChecker constructs a new CommandChecker.

func (*CommandChecker) Check

func (cc *CommandChecker) Check(command string) bool

Check checks if command exists as a file or in $PATH.

type ConditionRunner

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

ConditionRunner satisfies the Runner interface. It represents a runner for a post-start pre-condition.

func NewConditionRunner

func NewConditionRunner(
	sleep func(time.Duration),
	execCommandContext func(context.Context, string, ...string) *exec.Cmd,
) *ConditionRunner

NewConditionRunner constructs a new ConditionRunner.

func (*ConditionRunner) Run

func (cr *ConditionRunner) Run(
	command Command,
	stdio Stdio,
) (Process, error)

Run is not implemented.

func (*ConditionRunner) RunContext

func (cr *ConditionRunner) RunContext(
	ctx context.Context,
	command Command,
	_ Stdio,
) (Process, error)

RunContext runs a condition until it succeeds or the context times out. The process is never returned. A context timeout makes RunContext to return the error.

type ContainerProcess

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

ContainerProcess satisfies the Process interface.

func NewContainerProcess

func NewContainerProcess(process OSProcess, pid int) *ContainerProcess

NewContainerProcess constructs a new ContainerProcess.

func (*ContainerProcess) Pid added in v0.0.3

func (p *ContainerProcess) Pid() int

func (*ContainerProcess) Signal

func (p *ContainerProcess) Signal(sig os.Signal) error

Signal sends a signal to the process. If the process is not running anymore, it's no-op.

func (*ContainerProcess) Wait

func (p *ContainerProcess) Wait() error

Wait waits for the process.

type ContainerRunner

type ContainerRunner struct {
}

ContainerRunner satisfies the Runner interface.

func NewContainerRunner

func NewContainerRunner() *ContainerRunner

NewContainerRunner constructs a new ContainerRunner.

func (*ContainerRunner) Run

func (cr *ContainerRunner) Run(
	command Command,
	stdio Stdio,
) (Process, error)

Run runs a command async.

func (*ContainerRunner) RunContext

func (cr *ContainerRunner) RunContext(
	ctx context.Context,
	command Command,
	stdio Stdio,
) (Process, error)

RunContext runs a command async with a context.

type ExecCommandContext

type ExecCommandContext interface {
	CommandContext(ctx context.Context, name string, arg ...string) *exec.Cmd
}

ExecCommandContext wraps exec.CommandContext.

type ListenPacketFunc

type ListenPacketFunc func(network, address string) (net.PacketConn, error)

ListenPacketFunc is a type alias to the net.ListenPacket function.

type NetPacketListener

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

NetPacketListener satisfies the PacketListener interface.

func NewNetPacketListener

func NewNetPacketListener(listen ListenPacketFunc) *NetPacketListener

NewNetPacketListener constructs a new NetPacketListener.

func (*NetPacketListener) ListenPacket

func (npl *NetPacketListener) ListenPacket(network, address string) (PacketConnection, error)

ListenPacket implements listening for packets.

type OSProcess

type OSProcess interface {
	Signal(os.Signal) error
	Wait() (*os.ProcessState, error)
}

OSProcess is the interface that wraps the methods for *os.Process.

type PacketConnection

type PacketConnection interface {
	ReadFrom(p []byte) (n int, addr net.Addr, err error)
	Close() error
}

PacketConnection is the interface that wraps the PacketConn methods.

type PacketListener

type PacketListener interface {
	ListenPacket(network, address string) (PacketConnection, error)
}

PacketListener is the interface that wraps the ListenPacket methods. net.PacketConn satisfies this interface.

type Process

type Process interface {
	Pid() int
	Signal(os.Signal) error
	Wait() error
}

Process is the interface that wraps the Signal and Wait methods of a process.

type ProcessRegistry

type ProcessRegistry struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ProcessRegistry handles all the processes.

func NewProcessRegistry

func NewProcessRegistry() *ProcessRegistry

NewProcessRegistry constructs a new ProcessRegistry.

func (*ProcessRegistry) Count added in v0.0.2

func (pr *ProcessRegistry) Count() int

Count returns the number of processes in the registry

func (*ProcessRegistry) HandleSignals

func (pr *ProcessRegistry) HandleSignals(sigs <-chan os.Signal, sigterm chan<- struct{}, errors chan<- error)

HandleSignals handles the signals channel and forwards them to the registered processes. After a signal is handled it keeps running to handle any future ones.

func (*ProcessRegistry) KillAll added in v0.0.2

func (pr *ProcessRegistry) KillAll()

KillAll stops the timer and sends a kill signal to all registered processes.

func (*ProcessRegistry) Register

func (pr *ProcessRegistry) Register(p Process) int

Register registers a process in the registry and returns how many processes are registered.

func (*ProcessRegistry) SignalAll

func (pr *ProcessRegistry) SignalAll(sig os.Signal) []error

SignalAll sends a signal to all registered processes.

func (*ProcessRegistry) Unregister added in v0.0.2

func (pr *ProcessRegistry) Unregister(p Process) int

Unregister removes a process from the registry and returns how many processes are still registered.

type Runner

type Runner interface {
	Run(command Command, stdio Stdio) (Process, error)
	RunContext(ctx context.Context, command Command, stdio Stdio) (Process, error)
}

Runner is the interface that wraps the Run methods.

type Stdio

type Stdio struct {
	Out io.Writer
	Err io.Writer
}

Stdio represents the STDOUT and STDERR to be used by a process.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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