supervisord

package module
v0.0.0-...-a5469a4 Latest Latest
Warning

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

Go to latest
Published: May 17, 2021 License: MIT Imports: 5 Imported by: 6

README

go-supervisord

RPC remote control for supervisord

GoDoc

Code Examples

Reloading configuration and clearing daemon log:

import "github.com/abrander/go-supervisord"
  
func main() {
	c, err := supervisord.NewClient("http://127.0.0.1:9001/RPC2")
	if err != nil {
		panic(err.Error())
	}
	
	err = c.ClearLog()
	if err != nil {
		panic(err.Error())
	}
	
	err = c.Restart()
	if err != nil {
		panic(err.Error())
	}
}

Stop supervisord process worker:

import "github.com/abrander/go-supervisord"
  
func main() {
	c, err := supervisord.NewClient("http://127.0.0.1:9001/RPC2")
	if err != nil {
		panic(err.Error())
	}
	
	err = c.StopProcess("worker", false)
	if err != nil {
		panic(err.Error())
	}
}

Documentation

Index

Constants

View Source
const (
	StateCodeFatal      StateCode = 2  // Supervisor has experienced a serious error.
	StateCodeRunning    StateCode = 1  // Supervisor is working normally.
	StateCodeRestarting StateCode = 0  // Supervisor is in the process of restarting.
	StateCodeShutdown   StateCode = -1 // Supervisor is in the process of shutting down.

	StateNameFatal      StateName = "FATAL"      // Supervisor has experienced a serious error.
	StateNameRunning    StateName = "RUNNING"    // Supervisor is working normally.
	StateNameRestarting StateName = "RESTARTING" // Supervisor is in the process of restarting.
	StateNameShutdown   StateName = "SHUTDOWN"   // Supervisor is in the process of shutting down.
)

Variables

View Source
var (
	// Will be returned by a few functions not yet fully implemented.
	FIXMENotImplementedError error

	// Will be returned if the API endpoint returns false without further explanation.
	ReturnedFalseError error

	// Will be returned if the API endpoint returns a reply we don't know how to parse.
	ReturnedMalformedReply error
)

Functions

This section is empty.

Types

type Client

type Client struct {
	*xmlrpc.Client
}

func NewClient

func NewClient(url string, opts ...ClientOption) (*Client, error)

Get a new client suitable for communicating with a supervisord. url must contain a real url to a supervisord RPC-service.

Url for local supervisord should be http://127.0.0.1:9001/RPC2 by default.

func NewUnixSocketClient

func NewUnixSocketClient(path string, opts ...ClientOption) (*Client, error)

NewUnixSocketClient returns a new client which connects to supervisord though a local unix socket

func (*Client) AddProcessGroup

func (c *Client) AddProcessGroup(name string) error

Update the config for a running process from config file.

func (*Client) ClearAllProcessLogs

func (c *Client) ClearAllProcessLogs() error

Clear all process log files.

func (*Client) ClearLog

func (c *Client) ClearLog() error

Clear the main log.

func (*Client) ClearProcessLogs

func (c *Client) ClearProcessLogs(name string) error

Clear the stdout and stderr logs for the process name and reopen them.

func (*Client) GetAPIVersion

func (c *Client) GetAPIVersion() (string, error)

Return the version of the RPC API used by supervisord.

This API is versioned separately from Supervisor itself. The API version returned by getAPIVersion only changes when the API changes. Its purpose is to help the client identify with which version of the Supervisor API it is communicating.

When writing software that communicates with this API, it is highly recommended that you first test the API version for compatibility before making method calls.

func (*Client) GetAllProcessInfo

func (c *Client) GetAllProcessInfo() ([]ProcessInfo, error)

Get info about all processes.

func (*Client) GetIdentification

func (c *Client) GetIdentification() (string, error)

Return identifiying string of the supervisord instance.

This method allows the client to identify with which Supervisor instance it is communicating in the case of environments where multiple Supervisors may be running.

The identification is a string that must be set in Supervisor’s configuration file. This method simply returns that value back to the client.

func (*Client) GetPID

func (c *Client) GetPID() (int, error)

Return the PID of supervisord.

func (*Client) GetProcessInfo

func (c *Client) GetProcessInfo(name string) (*ProcessInfo, error)

Get info about a process named name.

func (*Client) GetState

func (c *Client) GetState() (State, error)

Return current state of supervisord as a struct.

This is an internal value maintained by Supervisor that determines what Supervisor believes to be its current operational state.

Some method calls can alter the current state of the Supervisor. For example, calling the Shutdown() while the station is in the StateCodeRunning state places the Supervisor in the StateCodeShutdown state while it is shutting down.

func (*Client) GetSupervisorVersion

func (c *Client) GetSupervisorVersion() (string, error)

Return the version of the supervisor package in use by supervisord.

func (*Client) ReadLog

func (c *Client) ReadLog(offset int, length int) (string, error)

Read length bytes from the main log starting at offset.

It can either return the entire log, a number of characters from the tail of the log, or a part of the log specified by the offset and length parameters.

func (*Client) ReadProcessStderrLog

func (c *Client) ReadProcessStderrLog(name string, offset int, length int) (string, error)

Read length bytes from name’s stderr log starting at offset.

func (*Client) ReadProcessStdoutLog

func (c *Client) ReadProcessStdoutLog(name string, offset int, length int) (string, error)

Read length bytes from name’s stdout log starting at offset.

func (*Client) ReloadConfig

func (c *Client) ReloadConfig() ([]string, []string, []string, error)

Reload supervisord configuration.

This will not change, start or stop any running processes. It will only read new configuration. See Update() for an all-in-one solution.

func (*Client) RemoveProcessGroup

func (c *Client) RemoveProcessGroup(name string) error

Remove a stopped process from the active configuration.

func (*Client) Restart

func (c *Client) Restart() error

Restart the supervisor process.

This method soft restarts the Supervisor daemon. If any processes are running, they are automatically killed without warning. Note that the actual UNIX process for Supervisor cannot restart; only Supervisor’s main program loop. This has the effect of resetting the internal states of Supervisor.

Unlike most other methods, if Supervisor is in the StateCodeFatal state, this method will still function.

func (*Client) SendProcessStdin

func (c *Client) SendProcessStdin(name string, chars string) error

Send a string to the stdin of the process name. If the process’s stdin cannot accept input (e.g. it was closed by the child process), return non-nil error.

func (*Client) SendRemoteCommEvent

func (c *Client) SendRemoteCommEvent(typ, data interface{}) error

This is not implemented yet.

func (*Client) Shutdown

func (c *Client) Shutdown() error

Shut down the supervisor process.

This method shuts down the Supervisor daemon. If any processes are running, they are automatically killed without warning.

Unlike most other methods, if Supervisor is in the StateCodeFatal state, this method will still function.

func (*Client) SignalAllProcesses

func (c *Client) SignalAllProcesses(signal syscall.Signal) ([]ProcessInfo, error)

SignalAllProcesses sends a signal to all processes in the process list Requires supervisord >= 3.2.0 http://supervisord.org/changes.html#id6

func (*Client) SignalProcess

func (c *Client) SignalProcess(name string, signal syscall.Signal) error

SignalProcess sends a signal to a process name: Name of the process to signal (or ‘group:name’) signal: Signal to send Requires supervisord >= 3.2.0 http://supervisord.org/changes.html#id6

func (*Client) StartAllProcesses

func (c *Client) StartAllProcesses(wait bool) ([]ProcessInfo, error)

Start all processes listed in the configuration file.

Set wait to true if the call should wait for completion before returning.

func (*Client) StartProcess

func (c *Client) StartProcess(name string, wait bool) error

Start a process.

func (*Client) StartProcessGroup

func (c *Client) StartProcessGroup(name string, wait bool) ([]ProcessInfo, error)

Start all processes in the group named name.

Set wait to true if the call should wait for completion before returning.

func (*Client) StopAllProcesses

func (c *Client) StopAllProcesses(wait bool) ([]ProcessInfo, error)

Stop all processes in the process list.

Set wait to true if the call should wait for completion before returning.

func (*Client) StopProcess

func (c *Client) StopProcess(name string, wait bool) error

Stop a process named by name.

Set wait to true if the call should wait for completion before returning.

func (*Client) StopProcessGroup

func (c *Client) StopProcessGroup(name string, wait bool) ([]ProcessInfo, error)

Stop all processes in the process group named name.

Set wait to true if the call should wait for completion before returning.

func (*Client) TailProcessStderrLog

func (c *Client) TailProcessStderrLog(name string, offset int, length int) ([]LogSegment, error)

This is not implemented yet.

func (*Client) TailProcessStdoutLog

func (c *Client) TailProcessStdoutLog(name string, offset int, length int) ([]LogSegment, error)

This is not implemented yet.

func (*Client) Update

func (c *Client) Update() error

This will reload configuration and adapt running processes to the new configuration. Changed program groups will be restarted. Should behave like "supervisorctl update".

type ClientOption

type ClientOption func(*options)

ClientOption is used to customize the client.

func WithAuthentication

func WithAuthentication(username, password string) ClientOption

WithAuthentication sets the username and password to use when authenticating against the server.

type LogSegment

type LogSegment struct {
	Payload  string `xmlrpc:"string"`
	Offset   int    `xmlrpc:"offset"`
	Overflow bool   `xmlrpc:"overflow"`
}

A LogSegment represents a "tail" of a log

type ProcessInfo

type ProcessInfo struct {
	Name          string       `xmlrpc:"name"`           // Name of the process
	Group         string       `xmlrpc:"group"`          // Name of the process’ group
	Start         int          `xmlrpc:"start"`          // UNIX timestamp of when the process was started
	Stop          int          `xmlrpc:"stop"`           // UNIX timestamp of when the process last ended, or 0 if the process has never been stopped
	Now           int          `xmlrpc:"now"`            // UNIX timestamp of the current time, which can be used to calculate process up-time.
	State         ProcessState `xmlrpc:"state"`          // State code, see ProcessState.
	StateName     string       `xmlrpc:"statename"`      // String description of state
	SpawnErr      string       `xmlrpc:"spawnerr"`       // Description of error that occurred during spawn, or empty string if none
	ExitStatus    int          `xmlrpc:"exitstatus"`     // Exit status (errorlevel) of process, or 0 if the process is still running
	StdoutLogfile string       `xmlrpc:"stdout_logfile"` // Absolute path and filename to the STDOUT logfile
	StderrLogfile string       `xmlrpc:"stderr_logfile"` // Absolute path and filename to the STDOUT logfile
	Pid           int          `xmlrpc:"pid"`            // UNIX process ID (PID) of the process, or 0 if the process is not running
}

A structure containing data about a process.

type ProcessState

type ProcessState int

A process controlled by supervisord will be in one of the below states at any given time. You may see these state names in various user interface elements in clients.

const (
	StateStopped  ProcessState = 0    // The process has been stopped due to a stop request or has never been started
	StateStarting ProcessState = 10   // The process is starting due to a start request
	StateRunning  ProcessState = 20   // The process is running
	StateBackoff  ProcessState = 30   // The process entered the StateStarting state but subsequently exited too quickly to move to the StateRunning state
	StateStopping ProcessState = 40   // The process is stopping due to a stop request
	StateExited   ProcessState = 100  // The process exited from the StateRunning state (expectedly or unexpectedly)
	StateFatal    ProcessState = 200  // The process could not be started successfully
	StateUnknown  ProcessState = 1000 // The process is in an unknown state (supervisord programming error)
)

type State

type State struct {
	Code StateCode `xmlrpc:"statecode"`
	Name StateName `xmlrpc:"statename"`
}

Represents Supervisord's internal state.

type StateCode

type StateCode int

A numeric representation of Supervisord's internal state.

type StateName

type StateName string

A textual representation of Supervisord's internal state.

Jump to

Keyboard shortcuts

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