supervisor

package
v0.0.0-...-cb90ab6 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2013 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Backoff  string = "BACKOFF"
	Exited   string = "EXITED"
	Fatal    string = "FATAL"
	Running  string = "RUNNING"
	Starting string = "STARTING"
	Stopped  string = "STOPPED"
	Stopping string = "STOPPING"
	Unknown  string = "UNKNOWN"
)

Variables

This section is empty.

Functions

func ReadResult

func ReadResult(reader io.Reader) (payload []byte, err error)

ReadResult reads an event result and returns the payload.

func WriteResult

func WriteResult(writer io.Writer, result []byte) (n int, err error)

WriteResult writes an event result to the stream and returns the number of byte written and an error if one occurs.

Types

type Client

type Client struct {
	RpcClient  *xmlrpc.Client
	ApiVersion string
}

func NewClient

func NewClient(url string) (client Client, err error)

NewClient creates a new supervisor RPC client.

func (Client) AddProcessGroup

func (client Client) AddProcessGroup(name string) (result bool, err error)

AddProcessGroup adds a configured process group to Supervisor.

func (Client) ClearAllProcessLogs

func (client Client) ClearAllProcessLogs(name string) (result bool, err error)

ClearAllProcessLogs clears all logs all processes.

func (Client) ClearLog

func (client Client) ClearLog() (result bool, err error)

ClearLog clears the Supervisor process log.

func (Client) ClearProcessLogs

func (client Client) ClearProcessLogs(name string) (result bool, err error)

ClearProcessLogs clears all logs for the named process.

func (Client) Close

func (client Client) Close() error

Close the client.

func (Client) GetAllProcessInfo

func (client Client) GetAllProcessInfo() (info []ProcessInfo, err error)

GetAllProcessInfo retrieves information for all Supervisor processes.

func (Client) GetIdentification

func (client Client) GetIdentification() (id string, err error)

GetIdentification returns the Supervisor ID string.

func (Client) GetPID

func (client Client) GetPID() (pid int64, err error)

GetPID returns the Supervisor process PID.

func (Client) GetProcessInfo

func (client Client) GetProcessInfo(name string) (info ProcessInfo, err error)

GetProcessInfo retrieves information for a particular Supervisor process.

func (Client) GetState

func (client Client) GetState() (state *SupervisorState, err error)

GetState returns the Supervisor process state.

func (Client) GetSupervisorVersion

func (client Client) GetSupervisorVersion() (version string, err error)

GetSupervisorVersion returns the Supervisor version we connect to.

func (Client) ReadLog

func (client Client) ReadLog(offset int64, length int64) (log string, err error)

ReadLog reads the Supervisor process log.

func (Client) ReadProcessStderrLog

func (client Client) ReadProcessStderrLog(name string, offset int64, length int64) (log string, err error)

ReadProcessStderrLog reads the stderr log for the named process.

func (Client) ReadProcessStdoutLog

func (client Client) ReadProcessStdoutLog(name string, offset int64, length int64) (log string, err error)

ReadProcessStdoutLog reads the stdout log for the named process.

func (Client) RemoveProcessGroup

func (client Client) RemoveProcessGroup(name string) (result bool, err error)

RemoveProcessGroup removes a configured process group from Supervisor.

func (Client) Restart

func (client Client) Restart() (result bool, err error)

Restart restarts the Supervisor process.

func (Client) SendProcessStdin

func (client Client) SendProcessStdin(name string, chars string) (result bool, err error)

SendProcessStdin send data to the stdin of a running process.

func (Client) SendRemoteCommEvent

func (client Client) SendRemoteCommEvent(typeKey string, data string) (result bool, err error)

SendRemoteCommEvent sends an event to Supervisor processes listening to RemoveCommunicationEvents..

func (Client) Shutdown

func (client Client) Shutdown() (result bool, err error)

Shutdown shuts down the Supervisor process.

func (Client) StartAllProcesses

func (client Client) StartAllProcesses(wait bool) (info []ProcessStatus, err error)

StartAllProcesses tells Supervisor to start all stopped processes.

func (Client) StartProcess

func (client Client) StartProcess(name string, wait bool) (result bool, err error)

StartProcess tells Supervisor to start the named process.

func (Client) StartProcessGroup

func (client Client) StartProcessGroup(name string, wait bool) (result bool, err error)

StartProcessGroup tells Supervisor to start all stopped processes in the named group.

func (Client) StopAllProcesses

func (client Client) StopAllProcesses(wait bool) (info []ProcessStatus, err error)

StopAllProcesses teslls Supervisor to stop all running processes.

func (Client) StopProcess

func (client Client) StopProcess(name string, wait bool) (result bool, err error)

StopProcess tells Supervisor to stop the named process.

func (Client) StopProcessGroup

func (client Client) StopProcessGroup(name string, wait bool) (result bool, err error)

StopProcessGroup tells Supervisor to start all stopped processes in the named group.

func (Client) TailProcessStderrLog

func (client Client) TailProcessStderrLog(name string, offset int64, length int64) (tail *ProcessTail, err error)

TailProcessStderrLog reads the stderr log for the named process.

func (Client) TailProcessStdoutLog

func (client Client) TailProcessStdoutLog(name string, offset int64, length int64) (tail *ProcessTail, err error)

TailProcessStdoutLog reads the stdout log for the named process.

type Event

type Event struct {
	Header  map[string]string
	Meta    map[string]string
	Payload []byte
}

Event represents a Supervisor event. An event consists of a header, metadata (meta) and an optional payload.

func ReadEvent

func ReadEvent(reader io.Reader) (event Event, err error)

ReadEvent waits for a Supervisor event and returns the parsed event. The err will be non-nil if an error occurred. This may include io.EOF which should preceed closing of the reader.

func (Event) HeaderInt

func (event Event) HeaderInt(key string) int

HeaderInt returns the requested header value as an int or 0 if missing or broken.

func (Event) MetaInt

func (event Event) MetaInt(key string) int

MetaInt returns the requested meta value as an int or 0 if missing or broken.

func (Event) Name

func (event Event) Name() string

Name returns the name of the event.

func (Event) Parent

func (event Event) Parent() string

Parent returns the parent type of the event.

func (Event) Pool

func (event Event) Pool() string

Pool returns the event pool where the event originated.

func (Event) PoolSerial

func (event Event) PoolSerial() int

PoolSerial returns the serial of the event in the event pool where the event originated.

func (Event) Serial

func (event Event) Serial() int

Serial returns the event serial number.

func (Event) State

func (event Event) State() string

State determines the state of the process or supervisor instance based on the name.

func (Event) String

func (event Event) String() string

String returns the event as a human readable string.

func (Event) ToBytes

func (event Event) ToBytes() []byte

ToBytes converts the event to a byte array suitable for parsing.

func (Event) Version

func (event Event) Version() string

Version returns the version of the Supervisor instance that sent the event.

type Listener

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

func NewListener

func NewListener(in io.Reader, out io.Writer) Listener

NewListener creates a new event listener with the given in and out streams. The listener will never close the streams.

func (Listener) Ack

func (l Listener) Ack() error

Ack puts the listener into the ACKNOWLEDGED state.

func (Listener) Busy

func (l Listener) Busy() error

Busy puts the listener into the BUSY state.

func (Listener) Fail

func (l Listener) Fail() error

Fail saends a FAIL result to Supervisor.

func (Listener) Ok

func (l Listener) Ok() error

OK sends an OK result to Supervisor.

func (Listener) Read

func (l Listener) Read() (event Event, err error)

Read waits for and returns an event from supervisor. An error is returned if the read fails. If EOF is encountered the error will be io.EOF.

func (Listener) Ready

func (l Listener) Ready() error

Ready puts the listener into the READY state.

func (Listener) Result

func (l Listener) Result(result []byte) error

Result sends a result payload to Supervisor.

func (Listener) Run

func (l Listener) Run(events chan Event) error

Run starts the listener and sends recieved events over the provided channel. It will listen for events until EOF is recieved. This is a simple implementation that will send an OK result followed by a READY after every event is recieved and parsed. If parsing or reading fails for any reason then Run will exit with an error.

type Monitor

type Monitor struct {
	Client     Client
	Listener   Listener
	Supervisor *Supervisor
	Processes  map[string]*Process
	// contains filtered or unexported fields
}

func NewMonitor

func NewMonitor(url string, in io.Reader, out io.Writer, events chan interface{}) (mon Monitor, err error)

NewMonitor creates a new Supervisor monitor.

func (Monitor) Close

func (mon Monitor) Close() error

Close the monitor.

func (Monitor) Refresh

func (mon Monitor) Refresh() (err error)

Refresh polls the Supervisor instance for the current state.

func (Monitor) Run

func (mon Monitor) Run() error

Run monitors the status of the Supervisor instance and sends events to the provided channel.

type Process

type Process struct {
	Name  string
	Group string
	State string
	PID   int
}

type ProcessAddEvent

type ProcessAddEvent struct {
	Supervisor Supervisor
	Process    Process
}

ProcessAddEvent is emitted when a process is added to Supervisor.

type ProcessInfo

type ProcessInfo struct {
	Name          string
	Description   string
	Group         string
	Start         int64
	Stop          int64
	Now           int64
	State         int64
	StateName     string
	SpawnErr      string
	ExitStatus    int64
	Logfile       string
	StdoutLogfile string
	StderrLogfile string
	PID           int64
}

func (ProcessInfo) String

func (info ProcessInfo) String() string

type ProcessRemoveEvent

type ProcessRemoveEvent ProcessAddEvent

ProcessRemoveEvent is emitted when a process is removed from Supervisor.

type ProcessStateEvent

type ProcessStateEvent struct {
	Supervisor Supervisor
	Process    Process
	FromState  string
	Tries      int
}

ProcessStateEvent is emitted when a process changes state.

type ProcessStatus

type ProcessStatus struct {
	Name        string
	Description string
	Group       string
	Status      int64
}

func (ProcessStatus) String

func (status ProcessStatus) String() string

type ProcessTail

type ProcessTail struct {
	Log      string
	Offset   int64
	Overflow bool
}

func (ProcessTail) String

func (tail ProcessTail) String() string

type Supervisor

type Supervisor struct {
	Name  string
	State string
}

func NewSupervisor

func NewSupervisor() *Supervisor

type SupervisorState

type SupervisorState struct {
	StateCode int64
	StateName string
}

func (SupervisorState) String

func (state SupervisorState) String() string

type SupervisorStateEvent

type SupervisorStateEvent struct {
	Supervisor Supervisor
	FromName   string
	FromState  string
}

SupervisorStateEvent is emitted when the Supervisor instance changes state.

Jump to

Keyboard shortcuts

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