core

package
v0.0.0-...-30ba24f Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

Supervisor provides the ability to manage Instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cfg

type Cfg struct {
	// InstancesDir - directory that stores
	// executable files for running Instances.
	InstancesDir string `json:"instances_dir"`
	// TermTimeout - time to wait for the Instance to
	// terminate correctly. After this timeout expires,
	// the SIGKILL signal will be used to stop the
	// instance if the force option is true, else an
	// error will be returned.
	TermTimeout time.Duration `json:"termination_timeout"`
}

Cfg stores Supervisor settings.

type Instance

type Instance struct {
	// Name is the name of the Instance.
	Name string
	// Cmd represents an external command being prepared or run.
	Cmd *exec.Cmd
	// Restartable indicates whether to restart the instance in
	// case of failure or not.
	Restartable bool
	// Env describes the environment settled by a client.
	Env []string
	// contains filtered or unexported fields
}

Instance describes a running process.

func NewInstance

func NewInstance(name string, cmd *exec.Cmd, env []string, restart bool) *Instance

NewInstance creates an Instance.

func (*Instance) IsAlive

func (inst *Instance) IsAlive() bool

IsAlive verifies that the Instance is alive by sending a "0" signal.

func (*Instance) Restart

func (inst *Instance) Restart() error

Restart restarts the Instance.

func (*Instance) Start

func (inst *Instance) Start() error

Start runs the Instatnce.

func (*Instance) Status

func (inst *Instance) Status() *InstanceStatus

Status returns the current status of the Instance.

func (*Instance) Stop

func (inst *Instance) Stop(timeout time.Duration, force bool) error

Stop terminates the Instance.

timeout - the time that was provided to the process to terminate correctly befor the "SIGKILL" signal is used.

force - if force is "true" the "SIGKILL" signal will be sent to the process in case of using "SIGINT" doesn't terminate the process.

type InstanceStatus

type InstanceStatus struct {
	// Name is the name of the Instance.
	Name string `json:"name"`
	// State describes the state of the Instance.
	// Available values: see Instance states.
	State string `json:"state"`
	// Pid is a process ID.
	Pid int `json:"pid"`
	// Restartable indicates whether to restart the instance in
	// case of failure or not.
	Restartable bool `json:"restartable"`
	// Env describes the environment settled by a client.
	Env []string `json:"env"`
}

InstanceStatus describes the status of the Instance.

type Supervisor

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

Supervisor stores the information about started Instances.

func NewSupervisor

func NewSupervisor(cfg *Cfg) *Supervisor

NewSupervisor creates a Supervisor.

func (*Supervisor) GetInstanceStatus

func (sv *Supervisor) GetInstanceStatus(id int) (*InstanceStatus, error)

GetInstanceStatus returns the current status of the Instance. On failure, returns an empty string and error.

func (*Supervisor) ListInstances

func (sv *Supervisor) ListInstances() map[string]*InstanceStatus

ListInstances returns a list of running instances.

func (*Supervisor) RestartAfterTermInstance

func (sv *Supervisor) RestartAfterTermInstance(pid int) (int, error)

RestartAfterTermInstance should be used to restart an instance in case of an unexpected termination of the instance. First of all, the method checks if the instance is alive. In this case, the method returns the current Instance ID with an error. If the Instance has been terminated and Instance.Restartable is true, then the Instance will be restarted. On success returns the Instance ID (0 invalid).

func (*Supervisor) StartInstance

func (sv *Supervisor) StartInstance(name string, env []string, restartable bool) (int, error)

StartInstance starts a new Instance with the specified parameters. On fail returns 0, error.

func (*Supervisor) StopAllInstances

func (sv *Supervisor) StopAllInstances()

StopAllInstances terminate all Instances managed by the Supervisor.

func (*Supervisor) StopInstance

func (sv *Supervisor) StopInstance(id int, force bool) error

StopInstance terminate an Instance by ID.

Jump to

Keyboard shortcuts

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