Documentation ¶
Index ¶
- Constants
- Variables
- func CountServices(sgs []ServiceOrGroup) int
- func InterruptGroup(cfg OperationConfig, pgid int, service *ServiceConfig) error
- func KillGroup(cfg OperationConfig, pgid int, service *ServiceConfig) error
- type ContextOverride
- type LaunchChecks
- type LockState
- type OperationConfig
- type ServiceCommand
- func (c *ServiceCommand) BuildSync(force bool, task tracker.Task) error
- func (c *ServiceCommand) BuildWithTracker(force bool, task tracker.Task) error
- func (c *ServiceCommand) Env() []string
- func (c *ServiceCommand) Getenv(key string) string
- func (c *ServiceCommand) RunStopScript() ([]byte, error)
- func (c *ServiceCommand) StartAsync(cfg OperationConfig, task tracker.Task) error
- type ServiceConfig
- func (c *ServiceConfig) Build(cfg OperationConfig, overrides ContextOverride, task tracker.Task) error
- func (c *ServiceConfig) GetCommand(overrides ContextOverride) (*ServiceCommand, error)
- func (c *ServiceConfig) GetDescription() string
- func (c *ServiceConfig) GetName() string
- func (c *ServiceConfig) GetPidPathLegacy() string
- func (c *ServiceConfig) GetRunLog() string
- func (c *ServiceConfig) IsSudo(cfg OperationConfig) bool
- func (c *ServiceConfig) Launch(cfg OperationConfig, overrides ContextOverride, task tracker.Task, ...) error
- func (c *ServiceConfig) Matches(name string) bool
- func (c *ServiceConfig) MatchesPlatform() bool
- func (c *ServiceConfig) ObtainLock(reason string) (*ServiceConfig, func() error, error)
- func (c *ServiceConfig) Restart(cfg OperationConfig, overrides ContextOverride, task tracker.Task, ...) error
- func (c *ServiceConfig) SetWatch(watch ServiceWatch) error
- func (c *ServiceConfig) Start(cfg OperationConfig, overrides ContextOverride, task tracker.Task, ...) error
- func (c *ServiceConfig) Status() ([]ServiceStatus, error)
- func (c *ServiceConfig) Stop(cfg OperationConfig, overrides ContextOverride, task tracker.Task, ...) error
- func (c *ServiceConfig) UnmarshalJSON(data []byte) error
- func (c *ServiceConfig) Watch() ([]ServiceWatch, error)
- type ServiceConfigCommands
- type ServiceConfigProperties
- type ServiceGroupConfig
- func (c *ServiceGroupConfig) Build(cfg OperationConfig, overrides ContextOverride, task tracker.Task) error
- func (c *ServiceGroupConfig) GetDescription() string
- func (c *ServiceGroupConfig) GetName() string
- func (c *ServiceGroupConfig) IsSudo(cfg OperationConfig) bool
- func (c *ServiceGroupConfig) Launch(cfg OperationConfig, overrides ContextOverride, task tracker.Task, ...) error
- func (c *ServiceGroupConfig) Matches(name string) bool
- func (c *ServiceGroupConfig) Restart(cfg OperationConfig, overrides ContextOverride, task tracker.Task, ...) error
- func (c *ServiceGroupConfig) Start(cfg OperationConfig, overrides ContextOverride, task tracker.Task, ...) error
- func (c *ServiceGroupConfig) Status() ([]ServiceStatus, error)
- func (c *ServiceGroupConfig) Stop(cfg OperationConfig, overrides ContextOverride, task tracker.Task, ...) error
- func (c *ServiceGroupConfig) Watch() ([]ServiceWatch, error)
- type ServiceOrGroup
- type ServiceStatus
- type ServiceWatch
Constants ¶
const StatusRunning = "RUNNING"
StatusRunning is the status string for a running service
const StatusStopped = "STOPPED"
StatusStopped is the status string for a stopped service
Variables ¶
var StartupTimeoutSeconds = 30
StartupTimeoutSeconds is the amount of time in seconds that Edward will wait for a service to start before timing out
Functions ¶
func CountServices ¶
func CountServices(sgs []ServiceOrGroup) int
CountServices returns the total number of services in the slice of services and groups.
func InterruptGroup ¶
func InterruptGroup(cfg OperationConfig, pgid int, service *ServiceConfig) error
InterruptGroup sends an interrupt signal to a process group. Will use sudo if required by this service.
func KillGroup ¶
func KillGroup(cfg OperationConfig, pgid int, service *ServiceConfig) error
KillGroup sends a kill signal to a process group. Will use sudo priviledges if required by this service.
Types ¶
type ContextOverride ¶
type ContextOverride struct { // Overrides to environment variables Env []string }
ContextOverride defines overrides for service configuration caused by commandline flags or group configuration.
func (ContextOverride) Merge ¶
func (c ContextOverride) Merge(m ContextOverride) ContextOverride
type LaunchChecks ¶
type LaunchChecks struct { // A string to look for in the service's logs that indicates it has completed startup. LogText string `json:"log_text,omitempty"` // One or more specific ports that are expected to be opened when this service starts. Ports []int `json:"ports,omitempty"` // Wait for a specified amount of time (in ms) before calling the service started if still running. Wait int64 `json:"wait,omitempty"` }
LaunchChecks defines the mechanism for testing whether a service has started successfully
type OperationConfig ¶
type OperationConfig struct { EdwardExecutable string // Path to the edward executable for launching runners Exclusions []string // Names of services/groups to be excluded from this operation NoWatch bool SkipBuild bool }
OperationConfig provides additional configuration for an operation on a service or group
func (*OperationConfig) IsExcluded ¶
func (o *OperationConfig) IsExcluded(sg ServiceOrGroup) bool
IsExcluded returns true if the given service/group is excluded by this OperationConfig. No operations should be performed on excluded services.
type ServiceCommand ¶
type ServiceCommand struct { // Parent service config Service *ServiceConfig `json:"service"` // Pid of currently running instance Pid int `json:"pid"` // Config file from which this instance was launched ConfigFile string `json:"configFile"` // The edward version under which this instance was launched EdwardVersion string `json:"edwardVersion"` // Overrides applied by the group under which this service was started Overrides ContextOverride `json:"overrides,omitempty"` Logger common.Logger `json:"-"` }
ServiceCommand provides state and functions for managing a service
func LoadServiceCommand ¶
func LoadServiceCommand(service *ServiceConfig, overrides ContextOverride) (command *ServiceCommand, err error)
LoadServiceCommand loads the command to control the specified service
func (*ServiceCommand) BuildSync ¶
func (c *ServiceCommand) BuildSync(force bool, task tracker.Task) error
BuildSync will buid the service synchronously. If force is false, the build will be skipped if the service is already running.
func (*ServiceCommand) BuildWithTracker ¶
func (c *ServiceCommand) BuildWithTracker(force bool, task tracker.Task) error
BuildWithTracker builds a service. If force is false, the build will be skipped if the service is already running.
func (*ServiceCommand) Env ¶
func (c *ServiceCommand) Env() []string
Env provides the combined environment variables for this service command
func (*ServiceCommand) Getenv ¶
func (c *ServiceCommand) Getenv(key string) string
Getenv returns the environment variable value for the provided key, if present. Env overrides are consulted first, followed by service env settings, then the os Env.
func (*ServiceCommand) RunStopScript ¶
func (c *ServiceCommand) RunStopScript() ([]byte, error)
RunStopScript will execute the stop script for this command, returning full output from running the script. Assumes the service has a stop script configured.
func (*ServiceCommand) StartAsync ¶
func (c *ServiceCommand) StartAsync(cfg OperationConfig, task tracker.Task) error
StartAsync starts the service in the background Will block until the service is known to have started successfully. If the service fails to launch, an error will be returned.
type ServiceConfig ¶
type ServiceConfig struct { // Service name, used to identify in commands Name string `json:"name"` // Alternative names for this service Aliases []string `json:"aliases,omitempty"` // Service description Description string `json:"description,omitempty"` // Optional path to service. If nil, uses cwd Path *string `json:"path,omitempty"` // Does this service require sudo privileges? RequiresSudo bool `json:"requiresSudo,omitempty"` // Commands for managing the service Commands ServiceConfigCommands `json:"commands"` // Checks to perform to ensure that a service has started correctly LaunchChecks *LaunchChecks `json:"launch_checks,omitempty"` // Env holds environment variables for a service, for example: GOPATH=~/gocode/ // These will be added to the vars in the environment under which the Edward command was run Env []string `json:"env,omitempty"` Platform string `json:"platform,omitempty"` // Path to watch for updates, relative to config file. If specified, will enable hot reloading. WatchJSON json.RawMessage `json:"watch,omitempty"` // Action for warming up this service Warmup *warmup.Warmup `json:"warmup,omitempty"` // Path to config file from which this service was loaded // This may be the file that imported the config containing the service definition. ConfigFile string `json:"-"` // Logger for actions on this service Logger common.Logger `json:"-"` // contains filtered or unexported fields }
ServiceConfig represents a service that can be managed by Edward
func (*ServiceConfig) Build ¶
func (c *ServiceConfig) Build(cfg OperationConfig, overrides ContextOverride, task tracker.Task) error
Build builds this service
func (*ServiceConfig) GetCommand ¶
func (c *ServiceConfig) GetCommand(overrides ContextOverride) (*ServiceCommand, error)
GetCommand returns the ServiceCommand for this service
func (*ServiceConfig) GetDescription ¶
func (c *ServiceConfig) GetDescription() string
GetDescription returns the description for this service
func (*ServiceConfig) GetName ¶
func (c *ServiceConfig) GetName() string
GetName returns the name for this service
func (*ServiceConfig) GetPidPathLegacy ¶
func (c *ServiceConfig) GetPidPathLegacy() string
func (*ServiceConfig) GetRunLog ¶
func (c *ServiceConfig) GetRunLog() string
GetRunLog returns the path to the run log for this service
func (*ServiceConfig) IsSudo ¶
func (c *ServiceConfig) IsSudo(cfg OperationConfig) bool
IsSudo returns true if this service requires sudo to run. If this service is excluded by cfg, then will always return false.
func (*ServiceConfig) Launch ¶
func (c *ServiceConfig) Launch(cfg OperationConfig, overrides ContextOverride, task tracker.Task, pool *worker.Pool) error
Launch launches this service
func (*ServiceConfig) Matches ¶
func (c *ServiceConfig) Matches(name string) bool
Matches returns true if the service name or an alias matches the provided name.
func (*ServiceConfig) MatchesPlatform ¶
func (c *ServiceConfig) MatchesPlatform() bool
MatchesPlatform determines whether or not this service can be run on the current OS
func (*ServiceConfig) ObtainLock ¶
func (c *ServiceConfig) ObtainLock(reason string) (*ServiceConfig, func() error, error)
ObtainLock will lock this service from performing other operations, It will return an unlocked instance of this service for performing an operation, and a function to unlock it.
func (*ServiceConfig) Restart ¶
func (c *ServiceConfig) Restart(cfg OperationConfig, overrides ContextOverride, task tracker.Task, pool *worker.Pool) error
Restart restarts this service
func (*ServiceConfig) SetWatch ¶
func (c *ServiceConfig) SetWatch(watch ServiceWatch) error
SetWatch sets the watch configuration for this service
func (*ServiceConfig) Start ¶
func (c *ServiceConfig) Start(cfg OperationConfig, overrides ContextOverride, task tracker.Task, pool *worker.Pool) error
Start builds then launches this service
func (*ServiceConfig) Status ¶
func (c *ServiceConfig) Status() ([]ServiceStatus, error)
Status returns the status for this service
func (*ServiceConfig) Stop ¶
func (c *ServiceConfig) Stop(cfg OperationConfig, overrides ContextOverride, task tracker.Task, pool *worker.Pool) error
Stop stops this service
func (*ServiceConfig) UnmarshalJSON ¶
func (c *ServiceConfig) UnmarshalJSON(data []byte) error
UnmarshalJSON provides additional handling when unmarshaling a service from config. Currently, this handles legacy fields and fields with multiple possible types.
func (*ServiceConfig) Watch ¶
func (c *ServiceConfig) Watch() ([]ServiceWatch, error)
Watch returns the watch configuration for this service
type ServiceConfigCommands ¶
type ServiceConfigCommands struct { // Command to build Build string `json:"build,omitempty"` // Command to launch Launch string `json:"launch,omitempty"` // Optional command to stop Stop string `json:"stop,omitempty"` }
ServiceConfigCommands define the commands for building, launching and stopping a service All commands are optional
type ServiceConfigProperties ¶
type ServiceConfigProperties struct { // Regex to detect a line indicating the service has started successfully Started string `json:"started,omitempty"` // Custom properties, mapping a property name to a regex Custom map[string]string `json:"-"` }
ServiceConfigProperties provides a set of regexes to detect properties of a service Deprecated: This has been dropped in favour of LaunchChecks
type ServiceGroupConfig ¶
type ServiceGroupConfig struct { // A name for this group, used to identify it in commands Name string // Alternative names for this group Aliases []string // A description Description string // Full services contained within this group Services []*ServiceConfig // Groups on which this group depends Groups []*ServiceGroupConfig // Launch order for children ChildOrder []string // Environment variables to be passed to all child services Env []string Logger common.Logger }
ServiceGroupConfig is a group of services that can be managed together
func (*ServiceGroupConfig) Build ¶
func (c *ServiceGroupConfig) Build(cfg OperationConfig, overrides ContextOverride, task tracker.Task) error
Build builds all services within this group
func (*ServiceGroupConfig) GetDescription ¶
func (c *ServiceGroupConfig) GetDescription() string
GetDescription returns the description for this group
func (*ServiceGroupConfig) GetName ¶
func (c *ServiceGroupConfig) GetName() string
GetName returns the name for this group
func (*ServiceGroupConfig) IsSudo ¶
func (c *ServiceGroupConfig) IsSudo(cfg OperationConfig) bool
IsSudo returns true if any of the services in this group require sudo to run
func (*ServiceGroupConfig) Launch ¶
func (c *ServiceGroupConfig) Launch(cfg OperationConfig, overrides ContextOverride, task tracker.Task, pool *worker.Pool) error
Launch will launch all services within this group
func (*ServiceGroupConfig) Matches ¶
func (c *ServiceGroupConfig) Matches(name string) bool
Matches returns true if the group name or an alias matches the provided name.
func (*ServiceGroupConfig) Restart ¶
func (c *ServiceGroupConfig) Restart(cfg OperationConfig, overrides ContextOverride, task tracker.Task, pool *worker.Pool) error
Restart restarts all services within this group
func (*ServiceGroupConfig) Start ¶
func (c *ServiceGroupConfig) Start(cfg OperationConfig, overrides ContextOverride, task tracker.Task, pool *worker.Pool) error
Start will build and launch all services within this group
func (*ServiceGroupConfig) Status ¶
func (c *ServiceGroupConfig) Status() ([]ServiceStatus, error)
Status returns the status for all services within this group
func (*ServiceGroupConfig) Stop ¶
func (c *ServiceGroupConfig) Stop(cfg OperationConfig, overrides ContextOverride, task tracker.Task, pool *worker.Pool) error
Stop stops all services within this group
func (*ServiceGroupConfig) Watch ¶
func (c *ServiceGroupConfig) Watch() ([]ServiceWatch, error)
Watch returns all service watches configured for this group
type ServiceOrGroup ¶
type ServiceOrGroup interface { GetName() string GetDescription() string Build(cfg OperationConfig, overrides ContextOverride, task tracker.Task) error // Build this service/group from source Start(cfg OperationConfig, overrides ContextOverride, task tracker.Task, pool *worker.Pool) error // Build and Launch this service/group Launch(cfg OperationConfig, overrides ContextOverride, task tracker.Task, pool *worker.Pool) error // Launch this service/group without building Stop(cfg OperationConfig, overrides ContextOverride, task tracker.Task, pool *worker.Pool) error Restart(cfg OperationConfig, overrides ContextOverride, task tracker.Task, pool *worker.Pool) error Status() ([]ServiceStatus, error) IsSudo(cfg OperationConfig) bool Watch() ([]ServiceWatch, error) }
ServiceOrGroup provides a common interface to services and groups
type ServiceStatus ¶
type ServiceStatus struct { Service *ServiceConfig Status string Pid int StartTime time.Time Ports []string StderrCount int StdoutCount int }
ServiceStatus contains the status for a service at a given point in time
type ServiceWatch ¶
type ServiceWatch struct { Service *ServiceConfig `json:"-"` IncludedPaths []string `json:"include,omitempty"` ExcludedPaths []string `json:"exclude,omitempty"` }
ServiceWatch defines a set of directories to be watched for changes to a service's source.