proc

package
v0.0.0-...-c8a214a Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package proc provides a mechanism for running processes under management. Managed processes can be started, monitored, signaled and killed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogWriter

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

LogWriter copies data written to pipe (normally from an os.Process) to the given log (or the default log).

func NewDefaultLogWriter

func NewDefaultLogWriter(prefix string) LogWriter

NewDefaultLogWriter creates a new LogWriter that emits lines to the default logger (on stderr) with the given prefix.

func NewLogWriter

func NewLogWriter(logger *log.Logger, prefix string) LogWriter

NewLogWriter creates a new LogWriter that emits lines to the given logger with the given prefix.

func (LogWriter) Close

func (w LogWriter) Close() error

Close closes the LogWriter and emits any buffered data.

func (LogWriter) ReadFrom

func (w LogWriter) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads as much data as possible from the given io.Reader.

func (LogWriter) Write

func (w LogWriter) Write(b []byte) (int, error)

Write writes data to the LogWriter. Data is line buffered before being emitted. Partial lines are held until a subsequent call to Write that includes a new line character, or a subsequent call to Close.

type LoggingCmd

type LoggingCmd struct {
	*exec.Cmd
}

LoggingCmd is a wrapper around os.exec.Cmd that logs stdout and stderr to a log.Logger.

func DefaultLoggingCommand

func DefaultLoggingCommand(cmd string, args ...string) *LoggingCmd

DefaultLoggingCommand constructs a LoggingCmd that logs to the default logger. The cmd and args parameters are passed directly to os.exec.Command. See that method for details.

func LoggingCommand

func LoggingCommand(logger *log.Logger, cmd string, args ...string) *LoggingCmd

LoggingCommand constructs a LoggingCmd that logs to the given logger. The cmd and args parameters are passed directly to os.exec.Command. See that method for details.

func (*LoggingCmd) Kill

func (c *LoggingCmd) Kill() error

Kill the process. Killing an unstarted process does not produce an error.

func (*LoggingCmd) Pid

func (c *LoggingCmd) Pid() int

Pid retrieves the process id, if started. Otherwise returns -1.

func (*LoggingCmd) Quit

func (c *LoggingCmd) Quit() error

Quit sends a quit signal to the process. Signaling an unstarted process does not produce an error.

type ManagedProc

type ManagedProc interface {
	// Path returns the path of the command to be run.
	Path() string

	// Args returns a copy of the arguments of the command to be run.
	Args() []string

	// Start the process.
	Start() error

	// Process is running.
	Running() bool

	// Process ran to completion and exited without being signaled.
	Completed() bool

	// Sends SIGHUP to the process. Returns an error if the
	// process is not running.
	Hangup() error

	// Sends SIGQUIT to the process. If the process has already
	// terminated, no error is returned.
	Quit() error

	// Sends SIGKILL to the process. If the process has already
	// terminated, no error is returned.
	Kill() error

	// Sends SIGTERM to the process. If the process has already
	// terminated, no error is returned.
	Term() error

	// Sends SIGUSR1 to the process. If the process has already
	// terminated, no error is returned.
	Usr1() error

	// Waits until the process exits.
	Wait() error
}

ManagedProc models a process under management.

func NewDefaultManagedProc

func NewDefaultManagedProc(exe string, args []string, onExit func(error)) ManagedProc

NewDefaultManagedProc constructs a new ManagedProc using DefaultLoggingCommand. Invokes onExit (if non-nil) when the process stops running. If the process cannot be started, an error is returned. In this case onExit is not invoked.

func NewManagedProc

func NewManagedProc(
	exe string,
	args []string,
	logger *log.Logger,
	onExit func(error),
) ManagedProc

NewManagedProc constructs a new ManagedProc with a LoggingCommand using the given logger. See NewDefaultManagedProc for details on onExit.

type MockManagedProc

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

MockManagedProc is a mock of ManagedProc interface

func NewMockManagedProc

func NewMockManagedProc(ctrl *gomock.Controller) *MockManagedProc

NewMockManagedProc creates a new mock instance

func (*MockManagedProc) Args

func (m *MockManagedProc) Args() []string

Args mocks base method

func (*MockManagedProc) Completed

func (m *MockManagedProc) Completed() bool

Completed mocks base method

func (*MockManagedProc) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockManagedProc) Hangup

func (m *MockManagedProc) Hangup() error

Hangup mocks base method

func (*MockManagedProc) Kill

func (m *MockManagedProc) Kill() error

Kill mocks base method

func (*MockManagedProc) Path

func (m *MockManagedProc) Path() string

Path mocks base method

func (*MockManagedProc) Quit

func (m *MockManagedProc) Quit() error

Quit mocks base method

func (*MockManagedProc) Running

func (m *MockManagedProc) Running() bool

Running mocks base method

func (*MockManagedProc) Start

func (m *MockManagedProc) Start() error

Start mocks base method

func (*MockManagedProc) Term

func (m *MockManagedProc) Term() error

Term mocks base method

func (*MockManagedProc) Usr1

func (m *MockManagedProc) Usr1() error

Usr1 mocks base method

func (*MockManagedProc) Wait

func (m *MockManagedProc) Wait() error

Wait mocks base method

type MockManagedProcMockRecorder

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

MockManagedProcMockRecorder is the mock recorder for MockManagedProc

func (*MockManagedProcMockRecorder) Args

Args indicates an expected call of Args

func (*MockManagedProcMockRecorder) Completed

func (mr *MockManagedProcMockRecorder) Completed() *gomock.Call

Completed indicates an expected call of Completed

func (*MockManagedProcMockRecorder) Hangup

func (mr *MockManagedProcMockRecorder) Hangup() *gomock.Call

Hangup indicates an expected call of Hangup

func (*MockManagedProcMockRecorder) Kill

Kill indicates an expected call of Kill

func (*MockManagedProcMockRecorder) Path

Path indicates an expected call of Path

func (*MockManagedProcMockRecorder) Quit

Quit indicates an expected call of Quit

func (*MockManagedProcMockRecorder) Running

func (mr *MockManagedProcMockRecorder) Running() *gomock.Call

Running indicates an expected call of Running

func (*MockManagedProcMockRecorder) Start

Start indicates an expected call of Start

func (*MockManagedProcMockRecorder) Term

Term indicates an expected call of Term

func (*MockManagedProcMockRecorder) Usr1

Usr1 indicates an expected call of Usr1

func (*MockManagedProcMockRecorder) Wait

Wait indicates an expected call of Wait

Directories

Path Synopsis
proc-test is a trivial application that responds to signals such as those sent by proc.LoggingCommand and proc.ManagedProc
proc-test is a trivial application that responds to signals such as those sent by proc.LoggingCommand and proc.ManagedProc

Jump to

Keyboard shortcuts

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