supervises

package module
v0.0.0-...-40ffbed Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: ISC Imports: 13 Imported by: 0

README

SYNOPSIS

supervises [options] "command ..." "..."

DESCRIPTION

Minimal command line supervisor.

BUILDING

go install codeberg.org/msantos/supervises/cmd/supervises@latest

Source

cd cmd/supervises
CGO_ENABLED=0 go build -trimpath -ldflags "-s -w"

EXAMPLES

supervises 'nc -vnl 7070' 'nc -vnl 7071' 'nc -vnl 7072'

SIGILS

  • @: run in shell

       supervises @'nc -l 8080 >nc.log'
    
  • =: discard stdout/stderr

       # equivalent to: supervises @'nc -l 8080 >/dev/null 2>&1'
       supervises ='nc -l 8080'
    
  • =1: discard stdout

       # equivalent to: supervises @'nc -l 8080 >/dev/null'
       supervises =1'nc -l 8080'
    
  • =2: discard stderr

       # equivalent to: supervises @'nc -l 8080 2>/dev/null'
       supervises =2'nc -l 8080'
    

OPTIONS

help : Display usage

signal int : signal sent to subprocesses on exit (default 9)

verbose : Enable debug messages

errexit : retries apply to tasks exiting with a non-0 status

retry-count int : retry limit before exiting (0: no limit)

retry-period duration : time interval for retries (0: no limit)

retry-wait duration : retry backoff interval (default 1s)

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrExitFailure    = errors.New("failed")
	ErrInvalidCommand = errors.New("invalid command")
	ErrSignal         = errors.New("terminated by signal")
)

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	Path        string
	Args        []string
	Env         []string
	Dir         string
	Stdin       io.Reader
	Stdout      io.Writer
	Stderr      io.Writer
	ExtraFiles  []*os.File
	SysProcAttr *syscall.SysProcAttr
}

func (*Cmd) String

func (c *Cmd) String() string

type ExitError

type ExitError struct {
	Argv     string
	Err      error
	Cmd      *exec.Cmd
	ExitCode int
}

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) String

func (e *ExitError) String() string

type Opt

type Opt struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, opt ...Option) *Opt

New returns configuration for supervisors.

func (*Opt) Cmd

func (o *Opt) Cmd(args ...string) ([]*Cmd, error)

func (*Opt) Context

func (o *Opt) Context() context.Context

func (*Opt) Reset

func (o *Opt) Reset()

func (*Opt) Supervise

func (o *Opt) Supervise(args ...*Cmd) error
Example
package main

import (
	"context"
	"errors"
	"fmt"
	"os"
	"time"

	"codeberg.org/msantos/supervises"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
	defer cancel()

	s := supervises.New(ctx)
	cmds, err := s.Cmd("@echo test123; exec sleep 10", "cat")
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}

	err = s.Supervise(cmds...)

	var ee *supervises.ExitError

	if !errors.As(err, &ee) {
		fmt.Fprintln(os.Stderr, err.Error())
		return
	}

}
Output:

test123

type Option

type Option func(*Opt)

func WithCancelFunc

func WithCancelFunc(f func(*exec.Cmd, syscall.Signal) error) Option

WithCancelFunc sets the function to reap cancelled subprocesses.

func WithCancelSignal

func WithCancelSignal(sig syscall.Signal) Option

WithCancelSignal sets the signal sent to subprocesses on exit.

func WithNotifySignals

func WithNotifySignals(sigs ...os.Signal) Option

WithNotifySignals sets trapped signals by the supervisor.

func WithRetry

func WithRetry(retry func(*Cmd, *ExitError) *ExitError) Option

WithRetry sets the retry behaviour.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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