Documentation ¶
Index ¶
- Constants
- Variables
- func AddHandle(handler Handler)
- func Aggregate(op, key string, value float64, id string, tags ...Tag)
- func BadRequestError(cause interface{}) error
- func Error(code uint32, cause interface{}) error
- func InternalError(cause interface{}) error
- func Jobs() map[string]Job
- func Kill(cmdID string) error
- func Killall()
- func MustArguments(args interface{}) *json.RawMessage
- func New()
- func NotAcceptableError(cause interface{}) error
- func NotFoundError(cause interface{}) error
- func PreconditionFailedError(cause interface{}) error
- func Register(name string, factory ProcessFactory)
- func RegisterBuiltIn(name string, runnable Runnable)
- func RegisterBuiltInWithCtx(name string, runnable RunnableWithCtx)
- func RegisterExtension(cmd string, exe string, workdir string, cmdargs []string, ...) error
- func RunSlice(slice settings.StartupSlice)
- func ServiceUnavailableError(cause interface{}) error
- func SetUnprivileged()
- func Start()
- type Channel
- type Command
- type ContainerCommandArguments
- type ContainerProcess
- type Context
- type DelayHook
- type ExitHook
- type GetPID
- type Handler
- type Job
- type JobFlags
- type JobResult
- type JobState
- type M
- type MatchHook
- type MessageHandler
- type NOOPHook
- type PIDHook
- type PIDTable
- type PreHandler
- type Process
- type ProcessFactory
- type ProcessStats
- type Queue
- type ResultHandler
- type RunError
- type Runnable
- type RunnableWithCtx
- type RunnerHook
- type Signaler
- type Stater
- type StatsHandler
- type StreamHook
- type Streams
- type SystemCommandArguments
- type Tag
- type Tags
- type TestingPIDTable
Constants ¶
const ( StandardStreamBufferSize = 100 //buffer size for each of stdout and stderr GenericStreamBufferSize = 10 //we only keep last 100 message of all types. )
const ( AggreagteAverage = "A" AggreagteDifference = "D" )
const (
//CommandSystem is the first and built in `core.system` command
CommandSystem = "core.system"
)
Variables ¶
Functions ¶
func AddHandle ¶ added in v1.2.0
func AddHandle(handler Handler)
AddHandle add handler to various process events
func BadRequestError ¶ added in v1.2.0
func BadRequestError(cause interface{}) error
func InternalError ¶ added in v1.2.0
func InternalError(cause interface{}) error
func MustArguments ¶ added in v1.2.0
func MustArguments(args interface{}) *json.RawMessage
MustArguments serialize an object to *json.RawMessage
func NotAcceptableError ¶ added in v1.2.0
func NotAcceptableError(cause interface{}) error
func NotFoundError ¶ added in v1.2.0
func NotFoundError(cause interface{}) error
func PreconditionFailedError ¶ added in v1.2.0
func PreconditionFailedError(cause interface{}) error
func Register ¶ added in v1.2.0
func Register(name string, factory ProcessFactory)
Register registers a command process factory
func RegisterBuiltIn ¶ added in v1.2.0
RegisterBuiltIn registers a built in function
func RegisterBuiltInWithCtx ¶ added in v1.2.0
func RegisterBuiltInWithCtx(name string, runnable RunnableWithCtx)
RegisterBuiltInWithCtx registers a built in function that accepts a command and a context
func RegisterExtension ¶ added in v1.2.0
func RegisterExtension(cmd string, exe string, workdir string, cmdargs []string, env map[string]string) error
RegisterExtension registers a new command (extension) so it can be executed via commands
func RunSlice ¶ added in v1.2.0
func RunSlice(slice settings.StartupSlice)
RunSlice runs a slice of processes honoring dependencies. It won't just start in order, but will also make sure a service won't start until it's dependencies are running.
func ServiceUnavailableError ¶ added in v1.2.0
func ServiceUnavailableError(cause interface{}) error
func SetUnprivileged ¶ added in v1.2.0
func SetUnprivileged()
SetUnprivileged switch to unprivileged mode (no way back) all process that runs after calling this will has some of their capabilities dropped
Types ¶
type Channel ¶ added in v1.2.0
type Channel interface { io.ReadWriteCloser }
Channel is a 2 way communication channel that is mainly used to talk to the main containerd process `coreX`
type Command ¶ added in v1.2.0
type Command struct { //Unique ID of the command, sets the job id ID string `json:"id"` //Command is the command name Command string `json:"command"` //Arguments, handled by the process Arguments *json.RawMessage `json:"arguments"` //Queue if set, commands with same queue are run synchronusly Queue string `json:"queue"` //StatsInterval fine tune when process statistics should be collected StatsInterval int `json:"stats_interval,omitempty"` //MaxTime max running time of the process, or it will get terminated MaxTime int `json:"max_time,omitempty"` //MaxRestart how many times the process manager should restart this process, if it failes MaxRestart int `json:"max_restart,omitempty"` //RecurringPeriod for recurring commands, defines how long it should wait between each run RecurringPeriod int `json:"recurring_period,omitempty"` //Stream if set to true, real time output of the process will get streamed over the output //channel Stream bool `json:"stream"` //LogLevels sets which log levels are to be logged LogLevels []int `json:"log_levels,omitempty"` //Tags custom user tags to be attached to the job Tags Tags `json:"tags"` //For internal use only, flags that can be set from inside the internal API Flags JobFlags `json:"-"` }
Command is the main way to communicate witht he process manager A Command.command is matched against a list of know process factories that build the corresponding process to handle the rest of the command arguments.
type ContainerCommandArguments ¶ added in v1.2.0
type ContainerCommandArguments struct { Name string `json:"name"` Dir string `json:"dir"` Args []string `json:"args"` Env map[string]string `json:"env"` HostNetwork bool `json:"host_network"` Chroot string `json:"chroot"` Log string `json:"log"` }
ContainerCommandArguments arguments for container command
func (*ContainerCommandArguments) String ¶ added in v1.2.0
func (c *ContainerCommandArguments) String() string
type ContainerProcess ¶ added in v1.2.0
ContainerProcess interface
type Context ¶ added in v1.2.0
type Context struct { Command *Command // contains filtered or unexported fields }
type DelayHook ¶
type DelayHook struct { NOOPHook Delay time.Duration Action func() // contains filtered or unexported fields }
DelayHook called after a certain amount of time passes from process start
type Handler ¶ added in v1.2.0
type Handler interface{}
Handler defines an interface to receiver the process manager events A handler can be any object that implements one or many handle methods below
type Job ¶ added in v1.2.0
type Job interface { Command() *Command Signal(sig syscall.Signal) error Process() Process Wait() *JobResult StartTime() int64 Subscribe(stream.MessageHandler) // contains filtered or unexported methods }
func Run ¶ added in v1.2.0
func Run(cmd *Command, hooks ...RunnerHook) (Job, error)
Run runs a command immediately (no pre-processors)
func RunFactory ¶ added in v1.2.0
func RunFactory(cmd *Command, factory ProcessFactory, hooks ...RunnerHook) (Job, error)
RunFactory run a command by creating a process by calling the factory with that command. accepts optional hooks to certain process events.
type JobFlags ¶ added in v1.2.0
type JobFlags struct { Protected bool NoOutput bool NoSetPGID bool //set new process group id for job }
JobFlags to control job behavior but only from the internal API Clients can't set the JobFlags, unlike the other public flags on the Command struct body.
type JobResult ¶ added in v1.2.0
type JobResult struct { ID string `json:"id"` Command string `json:"command"` Data string `json:"data"` Streams Streams `json:"streams,omitempty"` Critical string `json:"critical,omitempty"` Level uint16 `json:"level"` State JobState `json:"state"` Code uint32 `json:"code"` StartTime int64 `json:"starttime"` Time int64 `json:"time"` Tags Tags `json:"tags"` Container uint64 `json:"container"` }
JobResult represents a result of a job
func NewJobResult ¶ added in v1.2.0
NewJobResult creates a new job result from command
type JobState ¶ added in v1.2.0
type JobState string
JobState of a job
const ( //StateSuccess successs exit status StateSuccess JobState = "SUCCESS" //StateError error exist status StateError JobState = "ERROR" //StateTimeout timeout exit status StateTimeout JobState = "TIMEOUT" //StateKilled killed exit status StateKilled JobState = "KILLED" //StateUnknownCmd unknown cmd exit status StateUnknownCmd JobState = "UNKNOWN_CMD" //StateDuplicateID dublicate id exit status StateDuplicateID JobState = "DUPILICATE_ID" )
type MatchHook ¶
type MatchHook struct { NOOPHook Match string Action func(msg *stream.Message) // contains filtered or unexported fields }
MatchHook is called if a message matches a given pattern
type MessageHandler ¶
MessageHandler gets called on the receive of each single message from all commands
type PIDTable ¶ added in v1.2.0
type PIDTable interface { //PIDTable atomic registration of PID. MUST grantee that that no wait4 will happen //on any of the child process until the register operation is done. RegisterPID(g GetPID) (int, error) //WaitPID waits for a certain ID until it exits WaitPID(pid int) syscall.WaitStatus }
PIDTable a table that keeps track of running process ids
type PreHandler ¶ added in v1.2.0
type PreHandler interface {
Pre(cmd *Command)
}
PreHandler is called with the commands before exectution
type Process ¶ added in v1.2.0
Process interface
func NewContainerProcess ¶ added in v1.2.0
NewContainerProcess creates a new contained process, used soley from the container subsystem. Clients can't create container process directly they instead has to go throught he container subsystem which does most of the heavy lifting.
func NewSystemProcess ¶ added in v1.2.0
type ProcessFactory ¶ added in v1.2.0
ProcessFactory interface
func GetProcessFactory ¶
func GetProcessFactory(cmd *Command) ProcessFactory
GetProcessFactory gets a process factory from command name
func NewInternalProcess ¶ added in v1.2.2
func NewInternalProcess(runnable Runnable) ProcessFactory
NewInternalProcess factory to build Runnable processes
func NewInternalProcessWithCtx ¶ added in v1.2.2
func NewInternalProcessWithCtx(runnable RunnableWithCtx) ProcessFactory
type ProcessStats ¶ added in v1.2.0
type ProcessStats struct { CPU float64 `json:"cpu"` RSS uint64 `json:"rss"` VMS uint64 `json:"vms"` Swap uint64 `json:"swap"` Debug string `json:"debug,ommitempty"` }
ProcessStats holds process cpu and memory usage
type Queue ¶ added in v1.2.0
type Queue struct {
// contains filtered or unexported fields
}
* Queue is used for sequential cmds exectuions
type ResultHandler ¶
ResultHandler receives the command result on exit
type Runnable ¶ added in v1.2.0
Runnable represents a runnable built in function that can be managed by the process manager.
type RunnableWithCtx ¶ added in v1.2.0
type RunnerHook ¶
type RunnerHook interface { //Tick is called if certain amount has passed sicne process starting Tick(delay time.Duration) //Message is called on each received message from the process Message(msg *stream.Message) //Exit is called on process exit Exit(state JobState) //PID is executed once the child process is started and got an PID PID(pid int) }
RunnerHook is a per process event handler
type Stater ¶ added in v1.2.0
type Stater interface { Process Stats() *ProcessStats }
Stater a process that supports stats query
type StatsHandler ¶ added in v0.11.0
type StatsHandler interface {
Stats(operation string, key string, value float64, id string, tags ...Tag)
}
StatsHandler receives parsed stats messages
type StreamHook ¶ added in v1.2.0
StreamHook captures full stdout and stderr of a process.
func (*StreamHook) Message ¶ added in v1.2.0
func (h *StreamHook) Message(msg *stream.Message)
type SystemCommandArguments ¶ added in v1.2.0
type SystemCommandArguments struct { Name string `json:"name"` Dir string `json:"dir"` Args []string `json:"args"` Env map[string]string `json:"env"` StdIn string `json:"stdin"` }
func (*SystemCommandArguments) String ¶ added in v1.2.0
func (s *SystemCommandArguments) String() string
type TestingPIDTable ¶ added in v1.2.2
type TestingPIDTable struct{}
TestingPIDTable is used for testing to mock the process manager
func (*TestingPIDTable) RegisterPID ¶ added in v1.2.2
func (t *TestingPIDTable) RegisterPID(g GetPID) (int, error)
RegisterPID notify the process manager that a process has been started with the given PID
func (*TestingPIDTable) WaitPID ¶ added in v1.2.2
func (t *TestingPIDTable) WaitPID(pid int) syscall.WaitStatus
WaitPID waits for a PID until it exits