Documentation ¶
Overview ¶
Package proc provides a mechanism for running processes under management. Managed processes can be started, monitored, signaled and killed.
Index ¶
- type LogWriter
- type LoggingCmd
- type ManagedProc
- type MockManagedProc
- func (m *MockManagedProc) Args() []string
- func (m *MockManagedProc) Completed() bool
- func (m *MockManagedProc) EXPECT() *MockManagedProcMockRecorder
- func (m *MockManagedProc) Hangup() error
- func (m *MockManagedProc) Kill() error
- func (m *MockManagedProc) Path() string
- func (m *MockManagedProc) Quit() error
- func (m *MockManagedProc) Running() bool
- func (m *MockManagedProc) Start() error
- func (m *MockManagedProc) Term() error
- func (m *MockManagedProc) Usr1() error
- func (m *MockManagedProc) Wait() error
- type MockManagedProcMockRecorder
- func (mr *MockManagedProcMockRecorder) Args() *gomock.Call
- func (mr *MockManagedProcMockRecorder) Completed() *gomock.Call
- func (mr *MockManagedProcMockRecorder) Hangup() *gomock.Call
- func (mr *MockManagedProcMockRecorder) Kill() *gomock.Call
- func (mr *MockManagedProcMockRecorder) Path() *gomock.Call
- func (mr *MockManagedProcMockRecorder) Quit() *gomock.Call
- func (mr *MockManagedProcMockRecorder) Running() *gomock.Call
- func (mr *MockManagedProcMockRecorder) Start() *gomock.Call
- func (mr *MockManagedProcMockRecorder) Term() *gomock.Call
- func (mr *MockManagedProcMockRecorder) Usr1() *gomock.Call
- func (mr *MockManagedProcMockRecorder) Wait() *gomock.Call
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 ¶
NewDefaultLogWriter creates a new LogWriter that emits lines to the default logger (on stderr) with the given prefix.
func NewLogWriter ¶
NewLogWriter creates a new LogWriter that emits lines to the given logger with the given prefix.
type LoggingCmd ¶
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) Completed ¶
func (m *MockManagedProc) Completed() bool
Completed mocks base method
func (*MockManagedProc) EXPECT ¶
func (m *MockManagedProc) EXPECT() *MockManagedProcMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
func (*MockManagedProc) Running ¶
func (m *MockManagedProc) Running() bool
Running mocks base method
type MockManagedProcMockRecorder ¶
type MockManagedProcMockRecorder struct {
// contains filtered or unexported fields
}
MockManagedProcMockRecorder is the mock recorder for MockManagedProc
func (*MockManagedProcMockRecorder) Args ¶
func (mr *MockManagedProcMockRecorder) Args() *gomock.Call
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 ¶
func (mr *MockManagedProcMockRecorder) Kill() *gomock.Call
Kill indicates an expected call of Kill
func (*MockManagedProcMockRecorder) Path ¶
func (mr *MockManagedProcMockRecorder) Path() *gomock.Call
Path indicates an expected call of Path
func (*MockManagedProcMockRecorder) Quit ¶
func (mr *MockManagedProcMockRecorder) Quit() *gomock.Call
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 ¶
func (mr *MockManagedProcMockRecorder) Start() *gomock.Call
Start indicates an expected call of Start
func (*MockManagedProcMockRecorder) Term ¶
func (mr *MockManagedProcMockRecorder) Term() *gomock.Call
Term indicates an expected call of Term
func (*MockManagedProcMockRecorder) Usr1 ¶
func (mr *MockManagedProcMockRecorder) Usr1() *gomock.Call
Usr1 indicates an expected call of Usr1
func (*MockManagedProcMockRecorder) Wait ¶
func (mr *MockManagedProcMockRecorder) Wait() *gomock.Call
Wait indicates an expected call of Wait