process

package
v0.0.0-...-8fafcef Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2014 License: MPL-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	COMMAND_START int = iota
	COMMAND_STOP
	COMMAND_RESTART
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CtrlState

type CtrlState int

type DefaultRunner

type DefaultRunner struct{}

func (*DefaultRunner) Exec

func (r *DefaultRunner) Exec(p *Process, outputChan chan []byte, done chan int) (proc *os.Process, err error)

Exec launches the given process

type Event

type Event int
const (
	StartEvent Event = iota
	StopEvent
)

func (*Event) String

func (e *Event) String() string

type Process

type Process struct {
	// Process Name
	Name string `json:"name"`

	// Enabled indicates whether to run this process. A value of false will ensure
	// it is always stopped
	Enabled bool `json:"enabled"`

	// RunAtLoad key is used to control whether your process is launched once
	// at the time the config is loaded. The default is true.
	RunAtLoad bool

	// Last status code from this process exiting
	LastExitStatus int `json:"last_exit_status,int"`

	// Launch timeout
	Timeout time.Duration `json:"timeout"`

	// Command is the executable and arguments to run
	Command []string `json:"command"`

	// Environment is a hash of environment vars to set for this process
	Environment map[string]string `json:"environment"`

	// The time this process started
	StartedAt time.Time `json:"started_at"`

	// Signal to send to the process to gracefully exit
	KillSignal os.Signal `json:"kill_signal"`

	// Timeout to wait for process to exit gracefully before killing
	KillTimeout time.Duration `json:"kill_timeout"`

	// Throttle relaunching
	Throttle time.Duration `json:"throttle"`

	// Restart process it exits
	KeepAlive bool `json:"keep_alive"`

	// User and Group to switch to after exec
	UserName  string `json:"user"`
	GroupName string `json:"group"`

	// WorkingDirectory is the directory to chdir to after forking
	WorkingDirectory string `json:"working_directory"`

	Events chan Event

	sync.Mutex
	// contains filtered or unexported fields
}

Process represents a process running under command of Nord agent

func NewProcess

func NewProcess(name string, command ...string) *Process

NewProcess constructs a new Process instance which can be accepted by the management queue

func NewProcessFromConfig

func NewProcessFromConfig(conf *ProcessConfig) *Process

NewProcessFromConfig creates a process from a ProcessConf

func (*Process) IsRunning

func (p *Process) IsRunning() bool

func (*Process) IsStopped

func (p *Process) IsStopped() bool

func (*Process) OutputChan

func (p *Process) OutputChan() chan []byte

func (*Process) PID

func (p *Process) PID() int

func (*Process) Restart

func (p *Process) Restart() error

func (*Process) Run

func (p *Process) Run()

func (*Process) SetRunner

func (p *Process) SetRunner(r ProcessRunner)

SetRunner sets the process runner (useful for testing with a mock runner) FIXME(ivanvanderbyl): This probably doesn't need to be exported

func (*Process) Start

func (p *Process) Start() error

Start the process

func (*Process) Status

func (p *Process) Status() string

Status returns the process state

func (*Process) Stop

func (p *Process) Stop() error

func (*Process) Wait

func (p *Process) Wait()

type ProcessConfig

type ProcessConfig struct {
	// Name is a required key that uniquely identifies the process to Watchdog.
	Name string `mapstructure:"name"`

	// Disables is an optional key that instructs Watchdog on whether to load and
	// run this process. If this is set to false, watchdog will stop the process
	// and not respond to commands to start it. This configuration file will still
	// be monitored for changes in the event it later gets set to true, which will
	// in turn launch the process if it is configured to do so.
	Disabled bool `mapstructure:"disabled"`

	// UserName is an optional key specifies the user to run the job as.
	// This key is only applicable when watchdog is running as root.
	UserName string `mapstructure:"user_name"`

	// GroupName is an optional key specifies the group to run the process as.
	// This key is only applicable when watchdog is running as root.
	//
	// If UserName is set and GroupName is not, the the group will be set to
	// the default group of the user
	GroupName string `mapstructure:"group_name"`

	// Program key maps to the first argument of exec.Command().  If this key is
	// missing, then the first element of the array of strings provided to the
	// ProgramArguments will be used instead.
	//
	// This key is required in the absence of the ProgramArguments key.
	Program string `mapstructure:"program"`

	// ProgramArguments key maps to the second and subsequent arguments of
	// exec.Command. This key is required in the absence of the Program key.
	ProgramArguments []string `mapstructure:"program_arguments"`

	// KeepAlive key is used to control whether Watchdog should restart this
	// process in the event that is exits early. If this key is set to false,
	// Watchdog will not restart the process unless you manually tell it to do so.
	KeepAlive bool `mapstructure:"keep_alive"`

	// RunAtLoad key is used to control whether your process is launched once
	// at the time the config is loaded. The default is true.
	RunAtLoad bool `mapstructure:"run_at_load"`

	// WorkingDirectory is an optional key that is used to specify a directory
	// to chdir(2) to before running the process.
	WorkingDirectory string `mapstructure:"working_directory"`

	// EnvironmentVariables key is used to specify additional environmental
	// variables to be set before running the process.
	EnvironmentVariables map[string]string `mapstructure:"environment_variables"`

	// KillSignal is used to specify which os.Signal to send to the process to
	// instruct it to exit gracefully. Default is SIGKILL.
	KillSignal string `mapstructure:"kill_signal"`

	// KillTimeout is used to specify the amount of time to wait for the process
	// to safely exit after sending KillSignal before sending a SIGTERM. The
	// default is 10s.
	KillTimeout string `mapstructure:"kill_timeout"`

	// ThrottleInterval specifies the amount of time to wait before respawning the
	// process after it exits, if it is set to KeepAlive. The default value is
	// 10s.
	ThrottleInterval string `mapstructure:"throttle_interval"`

	// PidFile specifies where to write a pid file for this process when it is
	// spawned. An empty value disables this function.
	PidFile string

	// Outlets specifies a an outlet type by key and value of configuration to
	// be passed to that outlet when being constructed.
	Outlets map[string]map[string]string
}

ProcessConfig provides methods for loading and parsing configuration files into a struct which can be loaded as a process.

All exported fields in this struct are supported in a process configuration file.

func DecodeConfigFromJSON

func DecodeConfigFromJSON(r io.Reader) (*ProcessConfig, error)

DecodeConfigFromJSON loads a ProcessConfig from a JSON file

func DecodeConfigFromProcfile

func DecodeConfigFromProcfile(r io.Reader) (*ProcessConfig, error)

DecodeConfigFromProcfile will construct a minimal process configuration from a Foreman Procfile, starting it immediately and keeping it alive.

func DecodeConfigFromTOML

func DecodeConfigFromTOML(r io.Reader) (*ProcessConfig, error)

DecodeConfigFromTOML loads a ProcessConfig from a TOML file

func LoadConfigFile

func LoadConfigFile(path string) (*ProcessConfig, error)

LoadConfigFile loads a process configuration from a file on disk.

func (*ProcessConfig) IsValid

func (p *ProcessConfig) IsValid() bool

IsValid returns whether the config is valid for starting a process.

type ProcessRunner

type ProcessRunner interface {
	Exec(*Process, chan []byte, chan int) (*os.Process, error)
}

ProcessRunner is an interface for running processes, used mainly for switching between a live runner and a test runner

type ProcessState

type ProcessState int
const (
	ProcessStopped ProcessState = iota
	ProcessStarting
	ProcessRunning
	ProcessStopping
)

func (*ProcessState) String

func (p *ProcessState) String() string

Jump to

Keyboard shortcuts

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