copr

package module
v0.0.0-...-33418d1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: MIT Imports: 23 Imported by: 0

README

copr

Simple process control and monitoring

Documentation

Index

Constants

View Source
const (
	GlobalEnvFile = "copr.global.env"
)
View Source
const (
	SecretFile = "copr.secrets"
)

Variables

This section is empty.

Functions

func LoadGlobalEnv

func LoadGlobalEnv(file string, secs *Secrets) (map[string]string, error)

func UnzipTo

func UnzipTo(zipfile string, dir string) error

func ValidateUnitDir

func ValidateUnitDir(dir string) error

func ZipDir

func ZipDir(w io.Writer, dir string) error

Types

type CTLResponse

type CTLResponse struct {
	CtrlMessages []string `json:"ctrl-message,omitempty"`
	CtrlErrors   []string `json:"ctrl-errors,omitempty"`
}

type Command

type Command any

type CommandDeploy

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

func NewCommandDeploy

func NewCommandDeploy(unit string, dir string) *CommandDeploy

type CommandDisable

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

func NewCommandDisable

func NewCommandDisable(unit string) *CommandDisable

type CommandEnable

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

func NewCommandEnable

func NewCommandEnable(unit string) *CommandEnable

type CommandResponse

type CommandResponse struct {
	Messages []string
	Errors   []error
	Data     any
}

func (*CommandResponse) AddError

func (cr *CommandResponse) AddError(err error)

func (*CommandResponse) AddMsg

func (cr *CommandResponse) AddMsg(pattern string, args ...any)

func (CommandResponse) Error

func (cr CommandResponse) Error() error

func (CommandResponse) ErrorStrings

func (cr CommandResponse) ErrorStrings() []string

func (*CommandResponse) Errorf

func (cr *CommandResponse) Errorf(pattern string, args ...any)

func (CommandResponse) HasErrors

func (cr CommandResponse) HasErrors() bool

type CommandStart

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

func NewCommandStart

func NewCommandStart(unit string) *CommandStart

type CommandStartAll

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

func NewCommandStartAll

func NewCommandStartAll() *CommandStartAll

type CommandStop

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

func NewCommandStop

func NewCommandStop(unit string) *CommandStop

type CommandStopAll

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

func NewCommandStopAll

func NewCommandStopAll() *CommandStopAll

type Controller

type Controller struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewController

func NewController(dir string, secs *Secrets, glbEnv map[string]string) (*Controller, error)

func (*Controller) Deploy

func (c *Controller) Deploy(unit string, dir string) CommandResponse

func (*Controller) Disable

func (c *Controller) Disable(unit string) CommandResponse

func (*Controller) Enable

func (c *Controller) Enable(unit string) CommandResponse

func (*Controller) RunCtx

func (c *Controller) RunCtx(ctx context.Context)

func (*Controller) Start

func (c *Controller) Start(unit string) CommandResponse

func (*Controller) StartAll

func (c *Controller) StartAll() CommandResponse

API

func (*Controller) Stat

func (c *Controller) Stat(unit string) CommandResponse

func (*Controller) StatAll

func (c *Controller) StatAll() CommandResponse

func (*Controller) Stop

func (c *Controller) Stop(unit string) CommandResponse

func (*Controller) StopAll

func (c *Controller) StopAll() CommandResponse

type Guard

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

func NewGuard

func NewGuard(programm string, opts ...GuardOption) (*Guard, error)

func (*Guard) IsStarted

func (g *Guard) IsStarted() bool

func (*Guard) PID

func (g *Guard) PID() int

func (*Guard) RunCtx

func (g *Guard) RunCtx(ctx context.Context)

func (*Guard) Start

func (g *Guard) Start() (pid int, err error)

func (*Guard) Status

func (g *Guard) Status() GuardState

func (*Guard) Stop

func (g *Guard) Stop() error

func (*Guard) UpdateOpts

func (g *Guard) UpdateOpts(opts ...GuardOption) error

type GuardOption

type GuardOption func(g *Guard) error

func WithArgs

func WithArgs(args ...string) GuardOption

func WithEnv

func WithEnv(env ...string) GuardOption

func WithKillTimeout

func WithKillTimeout(d time.Duration) GuardOption

func WithOnChange

func WithOnChange(onChange func(rs GuardRunningState, pid int)) GuardOption

func WithRestartAfter

func WithRestartAfter(d time.Duration) GuardOption

func WithStdErr

func WithStdErr(w io.Writer) GuardOption

func WithStdIn

func WithStdIn(r io.Reader) GuardOption

func WithStdOut

func WithStdOut(w io.Writer) GuardOption

func WithWd

func WithWd(wd string) GuardOption

type GuardRunningState

type GuardRunningState string
const (
	GuardStatusNotRunning     GuardRunningState = "not-running"
	GuardStatusRunningStopped GuardRunningState = "running-stopped"
	GuardStatusRunningStarted GuardRunningState = "running-started"
)

type GuardState

type GuardState struct {
	RunningState GuardRunningState
	PID          int
}

type Secrets

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

func NewSecrets

func NewSecrets(path string, pwd string) (*Secrets, error)

func (*Secrets) Delete

func (scs *Secrets) Delete(key string)

func (*Secrets) Expanded

func (scs *Secrets) Expanded(s string) string

func (*Secrets) Find

func (scs *Secrets) Find(key string) (string, bool)

func (*Secrets) Keys

func (scs *Secrets) Keys() []string

func (*Secrets) Save

func (scs *Secrets) Save() error

func (*Secrets) Set

func (scs *Secrets) Set(key, value string)

type Service

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

func NewService

func NewService(bind string, controller *Controller, apiKey string) (*Service, error)

func (*Service) RunCtx

func (s *Service) RunCtx(ctx context.Context) error

type StatsDescriptor

type StatsDescriptor struct {
	Name         string
	Enabled      bool
	Started      bool
	PID          int
	RSS          uint64
	VM           uint64
	CPUPerc      float64
	MEMPerc      float64
	RLimitSoftFD uint64
	RLimitHardFD uint64
	NumFD        uint64
	StartedAt    time.Time
}

Stats is a collection of typical process stats

func (StatsDescriptor) RSSH

func (s StatsDescriptor) RSSH() string

RSSH returns RSS in a human-readable format

func (StatsDescriptor) String

func (s StatsDescriptor) String() string

String outputs the stats as string

func (StatsDescriptor) VMH

func (s StatsDescriptor) VMH() string

VMH returns VM in a human-readable format

type Unit

type Unit struct {
	Dir    string
	Name   string
	Config UnitConfig
}

type UnitConfig

type UnitConfig struct {
	//Name            string   `json:"name"`
	Enabled         bool     `json:"enabled"`
	Program         string   `json:"program"`
	Args            []string `json:"args,omitempty"`
	Env             []string `json:"env,omitempty"`
	RestartAfterSec int      `json:"restart-after-sec"`
}

Unit represenst on Service/Program, considered to reside in one directory

type UnitStatsCache

type UnitStatsCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewUnitStatsCache

func NewUnitStatsCache() *UnitStatsCache

type Units

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

func LoadUnits

func LoadUnits(dir string, secs *Secrets) (*Units, error)

func (*Units) Create

func (us *Units) Create(unit string, dir string) (Unit, error)

func (*Units) Load

func (us *Units) Load() error

func (*Units) SaveUnit

func (us *Units) SaveUnit(u Unit) error

func (*Units) Update

func (us *Units) Update(unit string, dir string) (Unit, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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