Documentation
¶
Index ¶
Constants ¶
const ( // STATUS_RUNNING indicates that the Job is currently started and running. STATUS_RUNNING = iota // STATUS_RESTARTING indicates that the Job is not running but will be // restarted after a delay. STATUS_RESTARTING = iota // STATUS_STOPPED indicates that the Job is not running and will not be // automatically started again. STATUS_STOPPED = iota )
These are statuses for a running Relauncher or Service.
Variables ¶
var ( ErrAlreadyRunning = errors.New("Job already running.") ErrNotRunning = errors.New("Job is not running.") ErrNotWaiting = errors.New("Job is not waiting to relaunch.") )
These are errors which may be returned from various executable functions.
var NullLog = nullLog{}
NullLog is a Log which returns no-op writers.
Functions ¶
This section is empty.
Types ¶
type Cmd ¶
type Cmd struct { // Stdout stores the standard output configuration. Stdout Log // Stderr stores the standard error configuration. Stderr Log // Directory is the working directory for the command Directory string // SetUID specifies whether or not the UID field should be used. SetUID bool // UID is the UID to run the command under. UID int // SetGID specifies whether or not the GID field should be used. SetGID bool // GID is the GID to run the command under. GID int // Arguments is the command-line arguments for the command. Arguments []string // Environment is a mapping of environment variables for the command. Environment map[string]string }
Cmd is the full configuration for a command-line executable.
func Command ¶
Command creates a new Cmd with generic settings given a set of command-line arguments.
type Job ¶
type Job interface { // Start starts the job. After this is called, calling Stop() must stop the // job. // This is not thread-safe. Start() error // Stop stops the job asynchronously if it is running. // This is thread-safe. Stop() error // Wait waits for the job to finish. // This is not thread-safe. Wait() error }
Job is a restartable task which can be run synchronously.
type Log ¶
type Log interface {
Open() (io.WriteCloser, error)
}
Log is a general log destination for a command's output.
type Relauncher ¶
type Relauncher struct {
// contains filtered or unexported fields
}
Relauncher automatically relaunches a task at a regular interval.
func Relaunch ¶
func Relaunch(job Job, interval time.Duration) *Relauncher
Relaunch starts a job and continually relaunches it on a given interval.
func (*Relauncher) History ¶
func (t *Relauncher) History() History
History returns the Relauncher's history.
func (*Relauncher) HistoryStatus ¶
func (t *Relauncher) HistoryStatus() (History, Status)
HistoryStatus returns both the Relauncher's history and it's status.
func (*Relauncher) Interval ¶
func (t *Relauncher) Interval() time.Duration
Interval returns the relaunch interval for a given relauncher.
func (*Relauncher) SkipWait ¶
func (t *Relauncher) SkipWait() error
SkipWait skips the current relaunch timeout if applicable. If the job was not relaunching, this returns ErrNotWaiting.
func (*Relauncher) Status ¶
func (t *Relauncher) Status() Status
Status returns the Relauncher's status
func (*Relauncher) Stop ¶
func (t *Relauncher) Stop()
Stop stops the relauncher. This method waits for the background job to terminate if necessary.
type Service ¶
type Service interface { // History returns a brief history of the Service. History() History // HistoryStatus returns the history and the status of a service. HistoryStatus() (History, Status) // SkipWait skips a wait if the service is a Relauncher and is waiting. SkipWait() error // Start starts the service if it is not already running. // By the time this returns, Status() must not be STATUS_STOPPED unless an // error is returned. Start() error // Status returns the status of the service. Status() Status // Stop stops the service synchronously. // By the time this returns, Status() must be STATUS_STOPPED unless an error // is returned. Stop() error // Wait waits for the service to stop. // Like Stop(), Wait() will only return once Status() has been set to // STATUS_STOPPED. Wait() error }
Service is a restartable Job which runs in the background.
func JobService ¶
JobService creates a Service that runs a specified Job.