Documentation ¶
Index ¶
- Constants
- func GetInMemoryLogStream(ctx context.Context, proc Process, count int) ([]string, error)
- func HasContextManager(ctx context.Context, name string) bool
- func HasManager(ctx context.Context) bool
- func Kill(ctx context.Context, p Process) error
- func KillAll(ctx context.Context, procs []Process) error
- func NewInMemoryLogger(maxSize int) (*options.LoggerConfig, error)
- func RegisterSignalTriggerFactory(id SignalTriggerID, factory SignalTriggerFactory) error
- func SignalEvent(context.Context, string) error
- func Terminate(ctx context.Context, p Process) error
- func TerminateAll(ctx context.Context, procs []Process) error
- func WithContextManager(ctx context.Context, name string, mgr Manager) context.Context
- func WithManager(ctx context.Context, mgr Manager) context.Context
- func WithNewContextManager(ctx context.Context, name string, fn func() Manager) context.Context
- type Command
- func BuildCommand(id string, pri level.Priority, args []string, dir string, ...) *Command
- func BuildCommandGroup(id string, pri level.Priority, cmds [][]string, dir string, ...) *Command
- func BuildCommandGroupContinueOnError(id string, pri level.Priority, cmds [][]string, dir string, ...) *Command
- func BuildRemoteCommand(id string, pri level.Priority, host string, args []string, dir string, ...) *Command
- func BuildRemoteCommandGroup(id string, pri level.Priority, host string, cmds [][]string, dir string) *Command
- func BuildRemoteCommandGroupContinueOnError(id string, pri level.Priority, host string, cmds [][]string, dir string) *Command
- func NewCommand() *Command
- func (c *Command) Add(args []string) *Command
- func (c *Command) AddEnv(k, v string) *Command
- func (c *Command) AddWhen(cond bool, args []string) *Command
- func (c *Command) Append(cmds ...string) *Command
- func (c *Command) AppendArgs(args ...string) *Command
- func (c *Command) AppendArgsWhen(cond bool, args ...string) *Command
- func (c *Command) AppendLoggers(l ...*options.LoggerConfig) *Command
- func (c *Command) AppendTags(t ...string) *Command
- func (c *Command) AppendWhen(cond bool, cmds ...string) *Command
- func (c *Command) ApplyFromOpts(opts *options.Create) *Command
- func (c *Command) Background(runBackground bool) *Command
- func (c *Command) Bash(script string) *Command
- func (c *Command) BashWhen(cond bool, script string) *Command
- func (c *Command) Close() error
- func (c *Command) ContinueOnError(cont bool) *Command
- func (c *Command) Directory(d string) *Command
- func (c *Command) Environment(e map[string]string) *Command
- func (c *Command) Export() ([]*options.Create, error)
- func (c *Command) ExportCreateOptions() ([]*options.Create, error)
- func (c *Command) Extend(cmds [][]string) *Command
- func (c *Command) ExtendLoggers(l []*options.LoggerConfig) *Command
- func (c *Command) ExtendRemoteArgs(args ...string) *Command
- func (c *Command) ExtendTags(t []string) *Command
- func (c *Command) ExtendWhen(cond bool, cmds [][]string) *Command
- func (c *Command) GetProcIDs() []string
- func (c *Command) GetProcessConstructor() ProcessConstructor
- func (c *Command) Host(h string) *Command
- func (c *Command) ID(id string) *Command
- func (c *Command) IgnoreError(ignore bool) *Command
- func (c *Command) Password(p string) *Command
- func (c *Command) Port(p int) *Command
- func (c *Command) PostHook(h options.CommandPostHook) *Command
- func (c *Command) PreHook(fn options.CommandPreHook) *Command
- func (c *Command) Prerequisite(chk func() bool) *Command
- func (c *Command) Priority(l level.Priority) *Command
- func (c *Command) PrivKey(key string) *Command
- func (c *Command) PrivKeyFile(path string) *Command
- func (c *Command) PrivKeyPassphrase(pass string) *Command
- func (c *Command) ProcConstructor(processConstructor ProcessConstructor) *Command
- func (c *Command) ProxyHost(h string) *Command
- func (c *Command) ProxyPassword(p string) *Command
- func (c *Command) ProxyPort(p int) *Command
- func (c *Command) ProxyPrivKey(key string) *Command
- func (c *Command) ProxyPrivKeyFile(path string) *Command
- func (c *Command) ProxyPrivKeyPassphrase(pass string) *Command
- func (c *Command) ProxyUser(u string) *Command
- func (c *Command) RedirectErrorToOutput(v bool) *Command
- func (c *Command) RedirectOutputToError(v bool) *Command
- func (c *Command) Run(ctx context.Context) error
- func (c *Command) RunParallel(ctx context.Context) error
- func (c *Command) SetCombinedSender(l level.Priority, s send.Sender) *Command
- func (c *Command) SetCombinedWriter(writer io.WriteCloser) *Command
- func (c *Command) SetErrorSender(l level.Priority, s send.Sender) *Command
- func (c *Command) SetErrorWriter(writer io.WriteCloser) *Command
- func (c *Command) SetInput(r io.Reader) *Command
- func (c *Command) SetInputBytes(b []byte) *Command
- func (c *Command) SetLoggers(l []*options.LoggerConfig) *Command
- func (c *Command) SetOutputOptions(opts options.Output) *Command
- func (c *Command) SetOutputSender(l level.Priority, s send.Sender) *Command
- func (c *Command) SetOutputWriter(writer io.WriteCloser) *Command
- func (c *Command) SetRemoteOptions(opts *options.Remote) *Command
- func (c *Command) SetRunFunc(f func(options.Command) error) *Command
- func (c *Command) SetTags(tags []string) *Command
- func (c *Command) Sh(script string) *Command
- func (c *Command) ShWhen(cond bool, script string) *Command
- func (c *Command) ShellScript(shell, script string) *Command
- func (c *Command) ShellScriptWhen(cond bool, shell, script string) *Command
- func (c *Command) String() string
- func (c *Command) Sudo(sudo bool) *Command
- func (c *Command) SudoAs(user string) *Command
- func (c *Command) SuppressStandardError(v bool) *Command
- func (c *Command) SuppressStandardOutput(v bool) *Command
- func (c *Command) User(u string) *Command
- func (c *Command) Wait(ctx context.Context) (int, error)
- func (c *Command) WithOptions(mod func(*options.Command)) *Command
- type LogStream
- type LoggingCache
- type Manager
- type ManagerOptions
- type OOMTracker
- type Process
- type ProcessConstructor
- type ProcessInfo
- type ProcessTracker
- type ProcessTrigger
- type ProcessTriggerSequence
- type SignalTrigger
- type SignalTriggerFactory
- type SignalTriggerID
- type SignalTriggerSequence
Constants ¶
const ( // EnvironID is the environment variable that is set on all processes. The // value of this environment variable is always the ID of the process. EnvironID = "JASPER_ID" // ManagerEnvironID is the environment variable that is set on // all managed process that always identifies the process' // manager. Used for process tracking and forensics. ManagerEnvironID = "JASPER_MANAGER" // DefaultCachePruneDelay is the duration between LRU cache prunes. DefaultCachePruneDelay = 10 * time.Second // DefaultMaxCacheSize is the maximum allowed size of the LRU cache. DefaultMaxCacheSize = 1024 * 1024 * 1024 )
Variables ¶
This section is empty.
Functions ¶
func GetInMemoryLogStream ¶
GetInMemoryLogStream gets at most count logs from the in-memory output logs for the given Process proc. If the process has not been called with Process.Wait(), this is not guaranteed to produce all the logs. This function assumes that there is exactly one in-memory logger attached to this process's output. It returns io.EOF if the stream is done. For remote interfaces, this function will not work; use (RemoteClient).GetLogStream() instead.
func HasContextManager ¶
HasContextManager checks the provided context to see if a Manager with the given name is attached to the provided context.
func HasManager ¶
HasManager returns true when the default context Manager is attached.
func Kill ¶
Kill sends a SIGKILL signal to the given process under the given context. This guarantees that the process will die. This function does not Wait() on the given process upon sending the signal.
func KillAll ¶
KillAll sends a SIGKILL signal to each of the given processes under the given context. This guarantees that each process will actually die. This function calls Wait() on each process after sending them SIGKILL signals. Use Kill() in a loop if you do not wish to potentially hang on Wait().
func NewInMemoryLogger ¶
func NewInMemoryLogger(maxSize int) (*options.LoggerConfig, error)
NewInMemoryLogger is a basic constructor that constructs a logger configuration for plain formatted in-memory buffered logger. The logger will capture up to maxSize messages.
func RegisterSignalTriggerFactory ¶
func RegisterSignalTriggerFactory(id SignalTriggerID, factory SignalTriggerFactory) error
RegisterSignalTriggerFactory registers a factory to create the signal trigger represented by the id.
func SignalEvent ¶
SignalEvent is a no-op on Unix-based systems.
func Terminate ¶
Terminate sends a SIGTERM signal to the given process under the given context. This does not guarantee that the process will actually die. This function does not Wait() on the given process upon sending the signal.
func TerminateAll ¶
TerminateAll sends a SIGTERM signal to each of the given processes under the given context. This does not guarantee that each process will actually die. This function calls Wait() on each process after sending them SIGTERM signals. On Windows, this function sends a SIGKILL instead of SIGTERM. Use Terminate() in a loop if you do not wish to potentially hang on Wait().
func WithContextManager ¶
WithContextManager attaches a jasper.Manager with a specific name to the context.
func WithManager ¶
WithManager attaches a Manager instance to the context
func WithNewContextManager ¶
WithNewContextLogger checks if a logger is configured with a specific name in the current context. If this logger exists, WithNewContextLogger is a noop; otherwise, it constructs a logger with the sender produced by the provided function and attaches it to the context returning that context.
The name provided controls the id of the logger in the context, not the name of the logger.
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command objects allow a quick and lightweight interface for firing off ad-hoc processes for smaller tasks. Command immediately supports features such as output and error functionality and remote execution. Command methods are not thread-safe.
func BuildCommand ¶
func BuildCommand(id string, pri level.Priority, args []string, dir string, env map[string]string) *Command
BuildCommand builds the Command given the configuration of arguments.
func BuildCommandGroup ¶
func BuildCommandGroup(id string, pri level.Priority, cmds [][]string, dir string, env map[string]string) *Command
BuildCommandGroup runs the group of sub-commands given the configuration of arguments.
func BuildCommandGroupContinueOnError ¶
func BuildCommandGroupContinueOnError(id string, pri level.Priority, cmds [][]string, dir string, env map[string]string) *Command
BuildCommandGroupContinueOnError runs the group of sub-commands given the configuration of arguments, continuing execution despite any errors.
func BuildRemoteCommand ¶
func BuildRemoteCommand(id string, pri level.Priority, host string, args []string, dir string, env map[string]string) *Command
BuildRemoteCommand builds the Command remotely given the configuration of arguments.
func BuildRemoteCommandGroup ¶
func BuildRemoteCommandGroup(id string, pri level.Priority, host string, cmds [][]string, dir string) *Command
BuildRemoteCommandGroup runs the group of sub-commands remotely given the configuration of arguments.
func BuildRemoteCommandGroupContinueOnError ¶
func BuildRemoteCommandGroupContinueOnError(id string, pri level.Priority, host string, cmds [][]string, dir string) *Command
BuildRemoteCommandGroupContinueOnError runs the group of sub-commands remotely given the configuration of arguments, continuing execution despite any errors.
func NewCommand ¶
func NewCommand() *Command
NewCommand returns a blank Command. New blank Commands will use basicProcess as their default Process for executing sub-commands unless it is changed via ProcConstructor().
func (*Command) AddEnv ¶
AddEnv adds a key value pair of environment variable to value into the Command's environment variable map. If this is a remote command, it sets the environment of the command being run remotely.
func (*Command) Append ¶
Append takes a series of strings and splits them into sub-commands and adds them to the Command.
func (*Command) AppendArgs ¶
AppendArgs is the variadic equivalent of Add, which adds a command in the form of arguments.
func (*Command) AppendArgsWhen ¶
AppendArgsWhen is the variadic equivalent of AddWhen, which adds a command in the form of arguments only when the conditional is true.
func (*Command) AppendLoggers ¶
func (c *Command) AppendLoggers(l ...*options.LoggerConfig) *Command
AppendLoggers adds one or more loggers to the existing configured loggers in the command.
func (*Command) AppendTags ¶
AppendTags adds the specified tags to the existing tag slice. Tags are used to filter process with the manager.
func (*Command) AppendWhen ¶
AppendWhen adds a sequence of subcommands to the Command only when the conditional is true.
func (*Command) ApplyFromOpts ¶
ApplyFromOpts uses the options.Create to configure the Command. All existing options will be overwritten. Use of this function is discouraged unless all desired options are populated in the given opts. If Args is set on the options.Create, it will be ignored; the command arguments can be added using Add, Append, AppendArgs, or Extend.
func (*Command) Background ¶
Background allows you to set the command to run in the background when you call Run(), the command will begin executing but will not complete when run returns.
func (*Command) Bash ¶
Bash adds a script using "bash -c", as syntactic sugar for the ShellScript2 method.
func (*Command) ContinueOnError ¶
ContinueOnError sets a flag for determining if the Command should continue executing its sub-commands even if one of them errors.
func (*Command) Directory ¶
Directory sets the working directory. If this is a remote command, it sets the working directory of the command being run remotely.
func (*Command) Environment ¶
Environment replaces the current environment map with the given environment map. If this is a remote command, it sets the environment of the command being run remotely.
func (*Command) Export ¶
Export returns all of the options.Create that will be used to spawn the processes that run all subcommands.
func (*Command) ExportCreateOptions ¶
func (*Command) ExtendLoggers ¶
func (c *Command) ExtendLoggers(l []*options.LoggerConfig) *Command
ExtendLoggers takes the existing slice of loggers and adds that to any existing configuration.
func (*Command) ExtendRemoteArgs ¶
ExtendRemoteArgs allows you to add arguments, when needed, to the Password sets the password in order to authenticate to a remote host. underlying ssh command, for remote commands.
func (*Command) ExtendTags ¶
ExtendTags adds all tags in the specified slice to the tags will be added to the process after creation. Tags are used to filter process with the manager.
func (*Command) ExtendWhen ¶
ExtendWhen adds on multiple sub-commands, only when the conditional is true.
func (*Command) GetProcIDs ¶
GetProcIDs returns an array of Process IDs associated with the sub-commands being run. This method will return a nil slice until processes have actually been created by the Command for execution.
func (*Command) GetProcessConstructor ¶
func (c *Command) GetProcessConstructor() ProcessConstructor
func (*Command) ID ¶
ID sets the ID of the Command, which is independent of the IDs of the subcommands that are executed.
func (*Command) IgnoreError ¶
IgnoreError sets a flag for determining if the Command should return a nil error despite errors in its sub-command executions.
func (*Command) PostHook ¶
func (c *Command) PostHook(h options.CommandPostHook) *Command
PostHook allows you to add a function that runs (locally) after the each subcommand in the Command completes. When specified, the PostHook can override or annotate any error produced by the command execution. The error returned is subject to the IgnoreError options. The PostHook is not run when using SetRunFunction.
func (*Command) PreHook ¶
func (c *Command) PreHook(fn options.CommandPreHook) *Command
PreHook allows you to add a function that runs (locally) before each subcommand executes, and allows you to log or modify the creation option. The PreHook is not run when using SetRunFunction.
func (*Command) Prerequisite ¶
Prerequisite sets a function on the Command such that the Command will only execute if the function returns true. The Prerequisite function runs once per Command object regardless of how many subcommands are present. Prerequsite functions run even if the command's RunFunction is set.
func (*Command) PrivKeyFile ¶
PrivKeyFile sets the path to the private key file in order to authenticate to a remote host.
func (*Command) PrivKeyPassphrase ¶
PrivKeyPassphrase sets the passphrase for the private key file in order to authenticate to a remote host.
func (*Command) ProcConstructor ¶
func (c *Command) ProcConstructor(processConstructor ProcessConstructor) *Command
ProcConstructor returns a blank Command that will use the process created by the given ProcessConstructor.
func (*Command) ProxyPassword ¶
ProxyPassword sets the password in order to authenticate to a proxy host.
func (*Command) ProxyPrivKey ¶
ProxyPrivKey sets the proxy private key in order to authenticate to a remote host.
func (*Command) ProxyPrivKeyFile ¶
ProxyPrivKeyFile sets the path to the proxy private key file in order to authenticate to a proxy host.
func (*Command) ProxyPrivKeyPassphrase ¶
ProxyPrivKeyPassphrase sets the passphrase for the private key file in order to authenticate to a proxy host.
func (*Command) RedirectErrorToOutput ¶
RedirectErrorToOutput sets a flag for determining if the Command should send all standard error content to standard output.
func (*Command) RedirectOutputToError ¶
RedirectOutputToError sets a flag for determining if the Command should send all standard output content to standard error.
func (*Command) RunParallel ¶
RunParallel is the same as Run(), but will run all sub-commands in parallel. Use of this function effectively ignores the ContinueOnError flag.
func (*Command) SetCombinedSender ¶
SetCombinedSender is the combination of SetErrorSender() and SetOutputSender().
func (*Command) SetCombinedWriter ¶
func (c *Command) SetCombinedWriter(writer io.WriteCloser) *Command
SetCombinedWriter is the combination of SetErrorWriter() and SetOutputWriter().
func (*Command) SetErrorSender ¶
SetErrorSender sets a Sender to be used by this Command for its output to stderr.
func (*Command) SetErrorWriter ¶
func (c *Command) SetErrorWriter(writer io.WriteCloser) *Command
SetErrorWriter sets a Writer to be used by this Command for its output to stderr.
func (*Command) SetInputBytes ¶
SetInputBytes is the same as SetInput but sets b as the bytes to be read from standard input.
func (*Command) SetLoggers ¶
func (c *Command) SetLoggers(l []*options.LoggerConfig) *Command
SetLoggers sets the logging output on this command to the specified slice. This removes any loggers previously configured.
func (*Command) SetOutputOptions ¶
SetOutputOptions sets the output options for a command. This overwrites an existing output options.
func (*Command) SetOutputSender ¶
SetOutputSender sets a Sender to be used by this Command for its output to stdout.
func (*Command) SetOutputWriter ¶
func (c *Command) SetOutputWriter(writer io.WriteCloser) *Command
SetOutputWriter sets a Writer to be used by this Command for its output to stdout.
func (*Command) SetRemoteOptions ¶
SetRemoteOptions sets the configuration for remote operations. This overrides any existing remote configuration.
func (*Command) SetRunFunc ¶
SetRunFunc sets the function that overrides the default behavior when a command is run, allowing the caller to run the command with their own custom function given all the given inputs to the command.
func (*Command) SetTags ¶
SetTags overrides any existing tags for a process with the specified list. Tags are used to filter process with the manager.
func (*Command) ShWhen ¶
ShWhen adds a shell script (e.g. "sh -c") only when the conditional is true.
func (*Command) ShellScript ¶
ShellScript adds an operation to the command that runs a shell script, using the shell's "-c" option).
func (*Command) ShellScriptWhen ¶
ShellScriptWhen a shell script option only when the conditional of true.
func (*Command) Sudo ¶
Sudo runs each command with superuser privileges with the default target user. This will cause the commands to fail if the commands are executed in Windows. If this is a remote command, the command being run remotely uses superuser privileges.
func (*Command) SudoAs ¶
SudoAs runs each command with sudo but allows each command to be run as a user other than the default target user (usually root). This will cause the commands to fail if the commands are executed in Windows. If this is a remote command, the command being run remotely uses superuser privileges.
func (*Command) SuppressStandardError ¶
SuppressStandardError sets a flag for determining if the Command should discard all standard error content.
func (*Command) SuppressStandardOutput ¶
SuppressStandardOutput sets a flag for determining if the Command should discard all standard output content.
func (*Command) Wait ¶
Wait returns the exit code and error waiting for the underlying process to complete. For commands run with RunParallel, Wait only returns a zero exit code if all the underlying processes return exit code zero; otherwise, it returns a non-zero exit code. Similarly, it will return a non-nil error if any of the underlying processes encounter an error while waiting.
type LogStream ¶
type LogStream struct { Logs []string `bson:"logs,omitempty" json:"logs,omitempty"` Done bool `bson:"done" json:"done"` }
LogStream represents the output of reading the in-memory log buffer as a stream, containing the logs (if any) and whether or not the stream is done reading.
type LoggingCache ¶
type LoggingCache interface { Create(id string, opts *options.Output) (*options.CachedLogger, error) Put(id string, logger *options.CachedLogger) error Get(id string) *options.CachedLogger // Remove removes an existing logger from the logging cache. Remove(id string) // CloseAndRemove closes and removes an existing logger from the // logging cache. CloseAndRemove(ctx context.Context, id string) error // Clear closes and removes any remaining loggers in the logging cache. Clear(ctx context.Context) error // Prune removes all loggers that were last accessed before the given // timestamp. Prune(lastAccessed time.Time) Len() int }
LoggingCache provides an interface to a cache of loggers.
func NewLoggingCache ¶
func NewLoggingCache() LoggingCache
NewLoggingCache produces a thread-safe implementation of a logging cache for use in manager implementations.
type Manager ¶
type Manager interface { ID() string CreateProcess(context.Context, *options.Create) (Process, error) CreateCommand(context.Context) *Command Register(context.Context, Process) error List(context.Context, options.Filter) ([]Process, error) Group(context.Context, string) ([]Process, error) Get(context.Context, string) (Process, error) Clear(context.Context) Close(context.Context) error LoggingCache(context.Context) LoggingCache WriteFile(ctx context.Context, opts options.WriteFile) error }
Manager provides a basic, high level process management interface for processes, and supports creation and introspection. External interfaces and remote management tools can be implemented in terms of this interface.
func Context ¶
Context resolves a jasper.Manager from the given context, and if one does not exist (or the context is nil), produces the global Manager instance.
func ContextManager ¶
ContextLoger produces a jasper.Manager stored in the context by a given name. If such a context is not stored the standard/default jasper.Manager is returned.
func NewManager ¶
func NewManager(opts ManagerOptions) Manager
type ManagerOptions ¶
type OOMTracker ¶
type OOMTracker interface { Check(context.Context) error Clear(context.Context) error Report() (bool, []int) }
OOMTracker provides a tool for detecting if there have been OOM events on the system. The Clear operation may affect the state the system logs and the data reported will reflect the entire system, not simply processes managed by Jasper tools.
func NewOOMTracker ¶
func NewOOMTracker() OOMTracker
NewOOMTracker returns an implementation of the OOMTracker interface for the current platform.
type Process ¶
type Process interface { // Returns a UUID for the process. Use this ID to retrieve // processes from managers using the Get method. ID() string // Info returns a copy of a structure that reports the current // state of the process. If the context is canceled or there // is another error, an empty struct may be returned. Info(context.Context) ProcessInfo // Running provides a quick predicate for checking to see if a // process is running. Running(context.Context) bool // Complete provides a quick predicate for checking if a // process has finished. Complete(context.Context) bool // Signal sends the specified signals to the underlying // process. Its error response reflects the outcome of sending // the signal, not the state of the process signaled. Signal(context.Context, syscall.Signal) error // Wait blocks until the process exits or the context is // canceled or is not properly defined. Wait will return the // exit code as -1 if it was unable to return a true code due // to some other error, but otherwise will return the actual // exit code of the process. Returns nil if the process has // completed successfully. // // Note that death by signal does not return the signal code // and instead is returned as -1. Wait(context.Context) (int, error) // Respawn respawns a near-identical version of the process on // which it is called. It will spawn a new process with the same // options and return the new, "respawned" process. // // However, it is not guaranteed to read the same bytes from // (options.Create).StandardInput as the original process; if // standard input must be duplicated, // (options.Create).StandardInputBytes should be set. Respawn(context.Context) (Process, error) // RegisterSignalTrigger associates triggers with a process, // which execute before the process is about to be signaled. RegisterSignalTrigger(context.Context, SignalTrigger) error // RegisterSignalTriggerID associates triggers represented by // identifiers with a process, which execute before // the process is about to be signaled. RegisterSignalTriggerID(context.Context, SignalTriggerID) error // RegisterTrigger associates triggers with a process, // erroring when the context is canceled, the process is // complete. RegisterTrigger(context.Context, ProcessTrigger) error // Tag adds a tag to a process. Implementations should avoid // allowing duplicate tags to exist. Tag(string) // GetTags should return all tags for a process. GetTags() []string // ResetTags should clear all existing tags. ResetTags() }
Process objects reflect ways of starting and managing processes. Process generally reflect only the primary process at the top of a tree and "child" processes are not directly reflected. Process implementations either wrap Go's own process management calls (e.g. os/exec.Cmd) or may wrap remote process management tools (e.g. jasper services on remote systems.)
func NewBasicProcess ¶
func NewBlockingProcess ¶
NewBlockingProcess creates a new process
func NewProcess ¶
NewProcess is a factory function which constructs a local Process outside of the context of a manager.
func SyncrhonizeProcess ¶
type ProcessConstructor ¶
ProcessConstructor is a function type that, given a context.Context and a options.Create struct, returns a Process and an error.
type ProcessInfo ¶
type ProcessInfo struct { ID string `json:"id" bson:"id"` Host string `json:"host" bson:"host"` PID int `json:"pid" bson:"pid"` ExitCode int `json:"exit_code" bson:"exit_code"` IsRunning bool `json:"is_running" bson:"is_running"` Successful bool `json:"successful" bson:"successful"` Complete bool `json:"complete" bson:"complete"` Timeout bool `json:"timeout" bson:"timeout"` Options options.Create `json:"options" bson:"options"` StartAt time.Time `json:"start_at" bson:"start_at"` EndAt time.Time `json:"end_at" bson:"end_at"` }
ProcessInfo reports on the current state of a process. It is always returned and passed by value, and reflects the state of the process when it was created.
type ProcessTracker ¶
type ProcessTracker interface { // Add begins tracking a process identified by its ProcessInfo. Add(ProcessInfo) error // Cleanup terminates this group of processes. Cleanup() error }
ProcessTracker provides a way to logically group processes that should be managed collectively. Implementation details are platform-specific since each one has its own means of managing groups of processes.
type ProcessTrigger ¶
type ProcessTrigger func(ProcessInfo)
ProcessTrigger describes the way to write cleanup functions for processes, which provide ways of adding behavior to processes after they complete. A ProcessTrigger can read the fields within ProcessInfo.Options but should not mutate them.
func MakeDefaultTrigger ¶
type ProcessTriggerSequence ¶
type ProcessTriggerSequence []ProcessTrigger
ProcessTriggerSequence is simply a convenience type to simplify running more than one triggered operation.
func (ProcessTriggerSequence) Run ¶
func (s ProcessTriggerSequence) Run(info ProcessInfo)
Run loops over triggers and calls each of them successively.
type SignalTrigger ¶
type SignalTrigger func(ProcessInfo, syscall.Signal) (skipSignal bool)
SignalTrigger describes the way to write hooks that will execute before a process is about to be signaled. It returns a bool indicating if the signal should be skipped after execution of the trigger. A SignalTrigger can read the fields within ProcessInfo.Options but should not mutate them.
type SignalTriggerFactory ¶
type SignalTriggerFactory func() SignalTrigger
SignalTriggerFactory is a function that creates a SignalTrigger.
func GetSignalTriggerFactory ¶
func GetSignalTriggerFactory(id SignalTriggerID) (SignalTriggerFactory, bool)
GetSignalTriggerFactory retrieves a factory to create the signal trigger represented by the id.
type SignalTriggerID ¶
type SignalTriggerID string
SignalTriggerID is the unique representation of a signal trigger.
const ( // CleanTerminationSignalTrigger is the ID for the signal trigger to use for // termination of processes with exit code 0. CleanTerminationSignalTrigger SignalTriggerID = "clean_terminate" )
type SignalTriggerSequence ¶
type SignalTriggerSequence []SignalTrigger
SignalTriggerSequence is a convenience type to simplify running more than one signal trigger.
func (SignalTriggerSequence) Run ¶
func (s SignalTriggerSequence) Run(info ProcessInfo, sig syscall.Signal) (skipSignal bool)
Run loops over signal triggers and calls each of them successively. It returns a boolean indicating whether or not the signal should be skipped after executing all of the signal triggers.
Source Files ¶
- command.go
- context.go
- event_unix.go
- interface.go
- logging.go
- manager_basic.go
- manager_remote.go
- manager_self_clearing.go
- manager_synchronized.go
- output.go
- process.go
- process_basic.go
- process_blocking.go
- process_synchronized.go
- signal.go
- signal_unix.go
- subprocess_unix.go
- subtree_oom.go
- subtree_oom_linux.go
- tracker.go
- triggers.go
- triggers_registry.go
- triggers_unix.go