pm

package
v1.2.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	StandardStreamBufferSize = 100 //buffer size for each of stdout and stderr
	GenericStreamBufferSize  = 10  //we only keep last 100 message of all types.
)
View Source
const (
	AggreagteAverage    = "A"
	AggreagteDifference = "D"
)
View Source
const (
	CommandSystem = "core.system"
)

Variables

View Source
var (
	MaxJobs           int
	UnknownCommandErr = errors.New("unkonw command")
	DuplicateIDErr    = errors.New("duplicate job id")
)

Functions

func AddHandle added in v1.2.0

func AddHandle(handler Handler)

func Aggregate added in v1.2.0

func Aggregate(op, key string, value float64, id string, tags ...Tag)

func BadRequestError added in v1.2.0

func BadRequestError(cause interface{}) error

func Error added in v1.2.0

func Error(code uint32, cause interface{}) error

func InternalError added in v1.2.0

func InternalError(cause interface{}) error

func Jobs added in v1.2.0

func Jobs() map[string]Job

Processes returs a list of running processes

func Kill added in v1.2.0

func Kill(cmdID string) error

Kill kills a r by the cmd ID

func Killall added in v1.2.0

func Killall()

Killall kills all running processes.

func MustArguments added in v1.2.0

func MustArguments(args interface{}) *json.RawMessage

func New added in v1.2.0

func New()

NewPM creates a new PM

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)

func RegisterBuiltIn added in v1.2.0

func RegisterBuiltIn(name string, runnable Runnable)

func RegisterBuiltInWithCtx added in v1.2.0

func RegisterBuiltInWithCtx(name string, runnable RunnableWithCtx)

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()

func Start added in v1.2.0

func Start()

Start starts the r manager.

Types

type Channel added in v1.2.0

type Channel interface {
	io.ReadWriteCloser
}

type Command added in v1.2.0

type Command struct {
	ID              string           `json:"id"`
	Command         string           `json:"command"`
	Arguments       *json.RawMessage `json:"arguments"`
	Queue           string           `json:"queue"`
	StatsInterval   int              `json:"stats_interval,omitempty"`
	MaxTime         int              `json:"max_time,omitempty"`
	MaxRestart      int              `json:"max_restart,omitempty"`
	RecurringPeriod int              `json:"recurring_period,omitempty"`
	Stream          bool             `json:"stream"`
	LogLevels       []int            `json:"log_levels,omitempty"`
	Tags            Tags             `json:"tags"`

	Flags JobFlags `json:"-"`
}

Cmd is an executable command

func LoadCmd added in v1.2.0

func LoadCmd(str []byte) (*Command, error)

LoadCmd loads cmd from json string.

func (*Command) String added in v1.2.0

func (cmd *Command) String() string

String represents cmd as a string

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"`
}

func (*ContainerCommandArguments) String added in v1.2.0

func (c *ContainerCommandArguments) String() string

type ContainerProcess added in v1.2.0

type ContainerProcess interface {
	Process
	Channel() Channel
}

type Context added in v1.2.0

type Context struct {
	Command *Command
	// contains filtered or unexported fields
}

func (*Context) Log added in v1.2.0

func (c *Context) Log(text string, level ...uint16)

func (*Context) Message added in v1.2.0

func (c *Context) Message(msg *stream.Message)

type DelayHook

type DelayHook struct {
	NOOPHook

	Delay  time.Duration
	Action func()
	// contains filtered or unexported fields
}

func (*DelayHook) Tick

func (h *DelayHook) Tick(delay time.Duration)

type ExitHook

type ExitHook struct {
	NOOPHook

	Action func(bool)
	// contains filtered or unexported fields
}

func (*ExitHook) Exit

func (h *ExitHook) Exit(state JobState)

type GetPID added in v1.2.0

type GetPID func() (int, error)

type Handler added in v1.2.0

type Handler interface{}

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 JobOf added in v1.2.0

func JobOf(id string) (Job, bool)

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)

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 cant 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

func NewJobResult(cmd *Command) *JobResult

NewJobResult creates a new job result from command

func System added in v1.2.0

func System(bin string, args ...string) (*JobResult, error)

System is a wrapper around core.system

type JobState added in v1.2.0

type JobState string
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 M added in v1.2.0

type M map[string]interface{}

type MatchHook

type MatchHook struct {
	NOOPHook
	Match  string
	Action func(msg *stream.Message)
	// contains filtered or unexported fields
}

func (*MatchHook) Message

func (h *MatchHook) Message(msg *stream.Message)

type MessageHandler

type MessageHandler interface {
	Message(*Command, *stream.Message)
}

type NOOPHook

type NOOPHook struct {
}

func (*NOOPHook) Exit

func (h *NOOPHook) Exit(state JobState)

func (*NOOPHook) Message

func (h *NOOPHook) Message(msg *stream.Message)

func (*NOOPHook) PID

func (h *NOOPHook) PID(pid int)

func (*NOOPHook) Tick

func (h *NOOPHook) Tick(delay time.Duration)

type PIDHook

type PIDHook struct {
	NOOPHook

	Action func(pid int)
	// contains filtered or unexported fields
}

func (*PIDHook) PID

func (h *PIDHook) PID(pid int)

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) error
	WaitPID(pid int) syscall.WaitStatus
}

type PreHandler added in v1.2.0

type PreHandler interface {
	Pre(cmd *Command)
}

type Process added in v1.2.0

type Process interface {
	Command() *Command
	Run() (<-chan *stream.Message, error)
}

Process interface

func NewContainerProcess added in v1.2.0

func NewContainerProcess(table PIDTable, cmd *Command) Process

func NewSystemProcess added in v1.2.0

func NewSystemProcess(table PIDTable, cmd *Command) Process

type ProcessFactory added in v1.2.0

type ProcessFactory func(PIDTable, *Command) Process

func GetProcessFactory

func GetProcessFactory(cmd *Command) ProcessFactory

NewProcess creates a new process from a command

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

func (*Queue) Channel added in v1.2.0

func (q *Queue) Channel() <-chan Job

func (*Queue) Init added in v1.2.0

func (q *Queue) Init()

func (*Queue) Notify added in v1.2.0

func (q *Queue) Notify(job Job)

func (*Queue) Push added in v1.2.0

func (q *Queue) Push(job Job)

type ResultHandler

type ResultHandler interface {
	Result(cmd *Command, result *JobResult)
}

type RunError added in v1.2.0

type RunError interface {
	Code() uint32
	Cause() interface{}
}

type Runnable added in v1.2.0

type Runnable func(*Command) (interface{}, error)

Runnable represents a runnable built in function that can be managed by the process manager.

type RunnableWithCtx added in v1.2.0

type RunnableWithCtx func(*Context) (interface{}, error)

type RunnerHook

type RunnerHook interface {
	Tick(delay time.Duration)
	Message(msg *stream.Message)
	Exit(state JobState)
	PID(pid int)
}

type Signaler added in v1.2.0

type Signaler interface {
	Process
	Signal(sig syscall.Signal) error
}

type Stater added in v1.2.0

type Stater interface {
	Process
	Stats() *ProcessStats
}

type StatsHandler added in v0.11.0

type StatsHandler interface {
	Stats(operation string, key string, value float64, id string, tags ...Tag)
}

type StreamHook added in v1.2.0

type StreamHook struct {
	NOOPHook
	Stdout bytes.Buffer
	Stderr bytes.Buffer
}

func (*StreamHook) Message added in v1.2.0

func (h *StreamHook) Message(msg *stream.Message)

type Streams added in v1.2.0

type Streams []string

func (Streams) Stderr added in v1.2.0

func (s Streams) Stderr() string

func (Streams) Stdout added in v1.2.0

func (s Streams) Stdout() string

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 Tag added in v1.2.0

type Tag struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Tags added in v1.2.0

type Tags []string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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