service

package
v0.0.0-...-a9989e0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2013 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Service defaults.
	DefaultStartTimeout = 1 * time.Second
	DefaultStartRetries = 3
	DefaultStopSignal   = syscall.SIGINT
	DefaultStopTimeout  = 5 * time.Second
	DefaultStopRestart  = true

	// Service commands.
	Start    = "start"
	Stop     = "stop"
	Restart  = "restart"
	Shutdown = "shutdown"

	// Service states.
	Starting = "starting"
	Running  = "running"
	Stopping = "stopping"
	Stopped  = "stopped"
	Exited   = "exited"
	Backoff  = "backoff"
	Fatal    = "fatal"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Name     string
	Response chan<- Response
}

Command is sent to a Service to initiate a state change.

type Event

type Event struct {
	Service *Service // The service from which the event originated.
	State   string   // The new state of the service.
	Error   error    // An error indicating why the service is in Exited or Backoff.
}

Event is sent by a Service on a state change.

type ExitError

type ExitError string

ExitError indicated why the service entered an Exited or Backoff state.

func (ExitError) Error

func (err ExitError) Error() string

Error returns the error message of the ExitError.

type Response

type Response struct {
	Service *Service
	Name    string
	Error   error
}

Response contains the result of a Command.

func (Response) Success

func (r Response) Success() bool

Success returns True if the Command was successful.

type Service

type Service struct {
	Directory    string                       // The process's working directory. Defaults to the current directory.
	Environment  []string                     // The environment of the process. Defaults to nil which indicates the current environment.
	StartTimeout time.Duration                // How long the process has to run before it's considered Running.
	StartRetries int                          // How many times to restart a process if it fails to start. Defaults to 3.
	StopSignal   syscall.Signal               // The signal to send when stopping the process. Defaults to SIGINT.
	StopTimeout  time.Duration                // How long to wait for a process to stop before sending a SIGKILL. Defaults to 5s.
	StopRestart  bool                         // Whether or not to restart the process if it exits unexpectedly. Defaults to true.
	Stdout       io.Writer                    // Where to send the process's stdout. Defaults to /dev/null.
	Stderr       io.Writer                    // Where to send the process's stderr. Defaults to /dev/null.
	CommandHook  func(*Service, string) error // Function to call before executing a command. Will cancel the command on error.
	// contains filtered or unexported fields
}

Service represents a controllable process. Exported fields may be set to configure the service.

func NewService

func NewService(args []string) (svc *Service, err error)

New creates a new service with the default configution.

func (Service) Pid

func (s Service) Pid() int

Pid gets the PID of the service or 0 if not Running or Stopping.

func (*Service) Run

func (s *Service) Run(commands <-chan Command, events chan<- Event)

func (Service) State

func (s Service) State() string

State gets the current state of the service.

Jump to

Keyboard shortcuts

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