runit

package
v0.0.0-...-8223eb1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package runit provides a programmatic way to interact with runit and servicebuilder (https://github.com/square/prodeng/blob/master/servicebuilder/README.md). You can use this package to make it easy to write new sb configs and exec sb.

Example usage:

import "github.com/square/p2/pkg/runit"

template := runit.NewSBTemplate("exampleapp") template.AddEntry("exampleapp_web", []string{"python", "-m", "SimpleHTTPServer"}) template.AddEntry("exampleapp_redis", []string{"redis", "-p", "6603"}) outPath, err := runit.DefaultBuilder.Write(template) // write the new config

if err != nil {
   return nil, err
}

err = runit.DefaultBuilder.Rebuild() // rebuild

Index

Constants

View Source
const (
	STATUS_DOWN = "down"
	STATUS_RUN  = "run"
)
View Source
const (
	RestartPolicyAlways RestartPolicy = "always"
	RestartPolicyNever  RestartPolicy = "never"

	DefaultRestartPolicy = RestartPolicyAlways

	DOWN_FILE_NAME = "down"
)
View Source
const DefaultTimeout = 7 * time.Second // This is runit's default wait period for commands that stop a process
View Source
const SuperviseOKTimeout = 30 * time.Second

Variables

View Source
var (
	NotRunning         StatError = errors.New("RunSV is not running and must be started")
	NotRunningTimeout  StatError = errors.New("Timed out while waiting to stop service: either RunSV or this service is not running")
	SuperviseOkMissing           = errors.New("The supervise/ok file is missing")
	Killed                       = errors.New("The process was forcibly killed")
)
View Source
var DefaultBuilder = &ServiceBuilder{
	ConfigRoot:  "/etc/servicebuilder.d",
	StagingRoot: "/var/service-stage",
	RunitRoot:   "/var/service",
}
View Source
var DefaultChpst = "/usr/bin/chpst"

DefaultChpst is the path to the default chpst binary. Specified as a var so you can override at build time.

View Source
var DefaultSV *sv
View Source
var DefaultSVPath = "/usr/bin/sv"

DefaultSVPath is the path to the default sv binary. Specified as a var so you can override at build time.

Functions

func DefaultLogExec

func DefaultLogExec() []string

func FakeChpst

func FakeChpst() string

func FakeServiceBuilder

func FakeServiceBuilder() (s *testServiceBuilder)

FakeServiceBuilder constructs a testServiceBuilder for use in unit tests. It is the caller's responsibility to always call Cleanup() on the return value to ensure that file system changes are removed when this test ends.

Types

type Exec

type Exec []string

type RecordingSV

type RecordingSV struct {
	Commands []string
}

func (*RecordingSV) LastCommand

func (r *RecordingSV) LastCommand() string

func (*RecordingSV) Once

func (r *RecordingSV) Once(service *Service) (string, error)

func (*RecordingSV) Restart

func (r *RecordingSV) Restart(service *Service, timeout time.Duration) (string, error)

func (*RecordingSV) Start

func (r *RecordingSV) Start(service *Service) (string, error)

func (*RecordingSV) Stat

func (r *RecordingSV) Stat(service *Service) (*StatResult, error)

func (*RecordingSV) Stop

func (r *RecordingSV) Stop(service *Service, timeout time.Duration) (string, error)

type RestartPolicy

type RestartPolicy string

These are in the runit package to avoid import cycles.

type SV

type SV interface {
	Start(service *Service) (string, error)
	Stop(service *Service, timeout time.Duration) (string, error)
	Stat(service *Service) (*StatResult, error)
	Restart(service *Service, timeout time.Duration) (string, error)
	Once(service *Service) (string, error)
}

func ErringSV

func ErringSV() SV

func FakeSV

func FakeSV() SV

func NewRecordingSV

func NewRecordingSV() SV

type Service

type Service struct {
	Path string
	Name string
}

type ServiceBuilder

type ServiceBuilder struct {
	ConfigRoot  string // directory to generate YAML files
	StagingRoot string // directory to place staged runit services
	RunitRoot   string // directory of runsvdir
	// contains filtered or unexported fields
}

func (*ServiceBuilder) Activate

func (s *ServiceBuilder) Activate(name string, templates map[string]ServiceTemplate) error

public API to write, stage and activate a servicebuilder template

func (*ServiceBuilder) Prune

func (s *ServiceBuilder) Prune() error

using the servicebuilder yaml files, find any extraneous runit services and remove them runsvdir automatically stops services that no longer exist, explicit stop is not required

type ServiceTemplate

type ServiceTemplate struct {
	Run      []string `yaml:"run"`
	Log      []string `yaml:"log,omitempty"`
	Finish   []string `yaml:"finish,omitempty"`
	Sleep    *int     `yaml:"sleep,omitempty"`
	LogSleep *int     `yaml:"logsleep,omitempty"`

	// Determines whether the service should be restarted by runit after it
	// exits. This isn't actually written to the servicebuilder file but
	// determines how the stage directory is written and the service
	// invoked
	// TODO: write this to the servicebuilder file and use it to determine
	// how the service should be started
	RestartPolicy RestartPolicy `yaml:"-"`
}

type StatError

type StatError error

type StatResult

type StatResult struct {
	ChildStatus string
	LogStatus   string
	ChildPID    uint64
	ChildTime   time.Duration
	LogPID      uint64
	LogTime     time.Duration
}

Jump to

Keyboard shortcuts

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