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
- Variables
- func DefaultLogExec() []string
- func FakeChpst() string
- func FakeServiceBuilder() (s *testServiceBuilder)
- type Exec
- type RecordingSV
- func (r *RecordingSV) LastCommand() string
- func (r *RecordingSV) Once(service *Service) (string, error)
- func (r *RecordingSV) Restart(service *Service, timeout time.Duration) (string, error)
- func (r *RecordingSV) Start(service *Service) (string, error)
- func (r *RecordingSV) Stat(service *Service) (*StatResult, error)
- func (r *RecordingSV) Stop(service *Service, timeout time.Duration) (string, error)
- type RestartPolicy
- type SV
- type Service
- type ServiceBuilder
- type ServiceTemplate
- type StatError
- type StatResult
Constants ¶
const ( STATUS_DOWN = "down" STATUS_RUN = "run" )
const ( RestartPolicyAlways RestartPolicy = "always" RestartPolicyNever RestartPolicy = "never" DefaultRestartPolicy = RestartPolicyAlways DOWN_FILE_NAME = "down" )
const DefaultTimeout = 7 * time.Second // This is runit's default wait period for commands that stop a process
const SuperviseOKTimeout = 30 * time.Second
Variables ¶
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") )
var DefaultBuilder = &ServiceBuilder{
ConfigRoot: "/etc/servicebuilder.d",
StagingRoot: "/var/service-stage",
RunitRoot: "/var/service",
}
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.
var DefaultSV *sv
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 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 RecordingSV ¶
type RecordingSV struct {
Commands []string
}
func (*RecordingSV) LastCommand ¶
func (r *RecordingSV) LastCommand() string
func (*RecordingSV) Stat ¶
func (r *RecordingSV) Stat(service *Service) (*StatResult, 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 NewRecordingSV ¶
func NewRecordingSV() SV
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:"-"` }