procwatch

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: MIT Imports: 34 Imported by: 1

README

Procwatch

GoDoc

Overview

Procwatch is a Golang program that aims to be a Supervisor-compatible process launcher and monitor. The intention is to provide process management as reliable and robust as Supervisor, but in a single compiled binary with no external dependencies.

Installation

go get -u github.com/ghetzel/procwatch/cmd/procwatch

Documentation

Index

Constants

View Source
const MaxProcessKillWaitTime = (5 * time.Second)
View Source
const ProcessStateSettleInterval = (250 * time.Millisecond)

Variables

View Source
var DefaultAddress = `:9001`
View Source
var DefaultLogFileMaxBytes = 50 * convutil.Megabyte
View Source
var Version = `0.6.1`

Functions

func LoadGlobalConfig

func LoadGlobalConfig(data []byte, manager *Manager) error

func LoadProgramsFromConfig

func LoadProgramsFromConfig(data []byte, manager *Manager) (map[string]*Program, error)

func Respond

func Respond(w http.ResponseWriter, data any)

Types

type Event

type Event struct {
	Names      []string
	Label      string
	Timestamp  time.Time
	Error      error
	Arguments  []string
	SourceType EventSource
	Source     any
}

func NewEvent

func NewEvent(names []string, label string, sourceType EventSource, source any, args ...string) *Event

func (*Event) HasName

func (event *Event) HasName(name string) bool

func (*Event) String

func (event *Event) String() string

type EventHandler

type EventHandler func(*Event)

type EventSource

type EventSource int
const (
	ProgramSource EventSource = iota
)

func (EventSource) String

func (src EventSource) String() string

type LogLine

type LogLine struct {
	Timestamp  time.Time
	Text       string
	Filename   string
	LineNumber int
	Program    *Program
}

func (LogLine) IsEmpty

func (line LogLine) IsEmpty() bool

func (LogLine) String

func (line LogLine) String() string

type Manager

type Manager struct {
	ConfigFile            string
	Version               string      `json:"version"                 ini:"-"`
	LogFile               string      `json:"logfile"                 ini:"logfile"`
	LogFileMaxBytes       string      `json:"logfile_maxbytes"        ini:"logfile_maxbytes"`
	LogFileBackups        int         `json:"logfile_backups"         ini:"logfile_backups"`
	LogLevel              string      `json:"loglevel"                ini:"loglevel"`
	ChildLogDir           string      `json:"childlogdir"             ini:"childlogdir"`
	RedirectStderr        bool        `json:"redirect_stderr"         ini:"redirect_stderr,omitempty"`
	StdoutLogfileMaxBytes string      `json:"stdout_logfile_maxbytes" ini:"stdout_logfile_maxbytes"`
	StderrLogfileMaxBytes string      `json:"stderr_logfile_maxbytes" ini:"stderr_logfile_maxbytes"`
	StderrLogfileBackups  int         `json:"stderr_logfile_backups"  ini:"stderr_logfile_backups"`
	StdoutLogfileBackups  int         `json:"stdout_logfile_backups"  ini:"stdout_logfile_backups"`
	DefaultStdoutLogfile  string      `json:"stdout_logfile"          ini:"stdout_logfile"`
	DefaultStderrLogfile  string      `json:"stderr_logfile"          ini:"stderr_logfile"`
	Server                *Server     `json:"server"                  ini:"server"`
	Events                chan *Event `json:"-"`
	// contains filtered or unexported fields
}

func NewManager

func NewManager() *Manager

func NewManagerFromConfig

func NewManagerFromConfig(configFile string) *Manager

func (*Manager) AddEventHandler

func (manager *Manager) AddEventHandler(handler EventHandler)

func (*Manager) AddProgram

func (manager *Manager) AddProgram(program *Program) error

func (*Manager) GetProgramsByState

func (manager *Manager) GetProgramsByState(states ...ProgramState) []*Program

func (*Manager) Initialize

func (manager *Manager) Initialize() error

func (*Manager) Log

func (manager *Manager) Log(level log.Level, line string, stack log.StackItems)

func (*Manager) Program

func (manager *Manager) Program(name string) (*Program, bool)

func (*Manager) Programs

func (manager *Manager) Programs() []*Program

func (*Manager) Run

func (manager *Manager) Run()

func (*Manager) Stop

func (manager *Manager) Stop(force bool)

func (*Manager) Tail

func (manager *Manager) Tail(ctx context.Context) <-chan LogLine

func (*Manager) Wait

func (manager *Manager) Wait()

type Program

type Program struct {
	Name                  string        `json:"name"                              ini:"-"`
	LoadIndex             int           `json:"index"                             ini:"-"`
	State                 ProgramState  `json:"state"                             ini:"-"`
	ProcessID             int           `json:"pid"                               ini:"-"`
	Command               any           `json:"command"                           ini:"-"`
	ProcessName           string        `json:"process_name,omitempty"            ini:"process_name,omitempty"`
	NumProcs              int           `json:"numprocs,omitempty"                ini:"numprocs,omitempty"`
	Directory             string        `json:"directory,omitempty"               ini:"directory,omitempty"`
	UMask                 int           `json:"umask,omitempty"                   ini:"umask,omitempty"`
	Priority              int           `json:"priority,omitempty"                ini:"priority,omitempty"`
	AutoStart             bool          `json:"autostart,omitempty"               ini:"autostart,omitempty"`
	AutoRestart           string        `json:"autorestart,omitempty"             ini:"autorestart,omitempty"`
	StartSeconds          int           `json:"startsecs,omitempty"               ini:"startsecs,omitempty"`
	StartRetries          int           `json:"startretries,omitempty"            ini:"startretries,omitempty"`
	ExitCodes             []int         `json:"exitcodes,omitempty"               delim:"," ini:"exitcodes,omitempty"`
	StopSignal            ProgramSignal `json:"stopsignal,omitempty"              ini:"stopsignal,omitempty"`
	StopWaitSeconds       int           `json:"stopwaitsecs,omitempty"            ini:"stopwaitsecs,omitempty"`
	StopAsGroup           bool          `json:"stopasgroup,omitempty"             ini:"stopasgroup,omitempty"`
	KillAsGroup           bool          `json:"killasgroup,omitempty"             ini:"killasgroup,omitempty"`
	User                  string        `json:"user,omitempty"                    ini:"user,omitempty"`
	RedirectStderr        bool          `json:"redirect_stderr,omitempty"         ini:"redirect_stderr,omitempty"`
	StdoutLogfile         string        `json:"stdout_logfile,omitempty"          ini:"stdout_logfile,omitempty"`
	StdoutLogfileMaxBytes string        `json:"stdout_logfile_maxbytes,omitempty" ini:"stdout_logfile_maxbytes,omitempty"`
	StdoutLogfileBackups  int           `json:"stdout_logfile_backups,omitempty"  ini:"stdout_logfile_backups,omitempty"`
	StdoutCaptureMaxBytes string        `json:"stdout_capture_maxbytes,omitempty" ini:"stdout_capture_maxbytes,omitempty"`
	StdoutEventsEnabled   bool          `json:"stdout_events_enabled,omitempty"   ini:"stdout_events_enabled,omitempty"`
	StderrLogfile         string        `json:"stderr_logfile,omitempty"          ini:"stderr_logfile,omitempty"`
	StderrLogfileMaxBytes string        `json:"stderr_logfile_maxbytes,omitempty" ini:"stderr_logfile_maxbytes,omitempty"`
	StderrLogfileBackups  int           `json:"stderr_logfile_backups,omitempty"  ini:"stderr_logfile_backups,omitempty"`
	StderrCaptureMaxBytes string        `json:"stderr_capture_maxbytes,omitempty" ini:"stderr_capture_maxbytes,omitempty"`
	StderrEventsEnabled   bool          `json:"stderr_events_enabled,omitempty"   ini:"stderr_events_enabled,omitempty"`
	Environment           []string      `json:"environment,omitempty"             delim:"," ini:"environment,omitempty"`
	ServerUrl             string        `json:"serverurl,omitempty"               ini:"serverurl,omitempty"`
	Schedule              string        `json:"schedule,omitempty"                ini:"schedule,omitempty"`
	CommandString         string        `json:"-"                                 ini:"command"`
	LastExitStatus        int           `json:"last_exit_status,omitempty"        ini:"-"`
	LastStartedAt         time.Time     `json:"last_started_at,omitempty"         ini:"-"`
	LastExitedAt          time.Time     `json:"last_exited_at,omitempty"          ini:"-"`
	LastTriggeredAt       time.Time     `json:"last_triggered_at,omitempty"       ini:"-"`
	NextScheduledAt       time.Time     `json:"next_scheduled_at,omitempty"       ini:"-"`
	// contains filtered or unexported fields
}

func NewProgram

func NewProgram(name string, manager *Manager) *Program

func (*Program) ForceStop

func (program *Program) ForceStop()

func (*Program) GetState

func (program *Program) GetState() ProgramState

func (*Program) HasEverBeenStarted

func (program *Program) HasEverBeenStarted() bool

func (*Program) InState

func (program *Program) InState(states ...ProgramState) bool

func (*Program) InTerminalState

func (program *Program) InTerminalState() bool

func (*Program) IsExpectedStatus

func (program *Program) IsExpectedStatus(code int) bool

func (*Program) Log

func (program *Program) Log(line string, stdout bool)

func (*Program) PID

func (program *Program) PID() int

func (*Program) Restart

func (program *Program) Restart()

func (*Program) ShouldAutoRestart

func (program *Program) ShouldAutoRestart() bool

func (*Program) Start

func (program *Program) Start() int

func (*Program) Stop

func (program *Program) Stop()

func (*Program) StopFatal

func (program *Program) StopFatal()

func (*Program) String

func (program *Program) String() string

type ProgramSignal

type ProgramSignal string
const (
	SIGKILL ProgramSignal = `KILL`
	SIGINT  ProgramSignal = `INT`
	SIGTERM ProgramSignal = `TERM`
	SIGHUP  ProgramSignal = `HUP`
	SIGQUIT ProgramSignal = `QUIT`
	SIGUSR1 ProgramSignal = `USR1`
	SIGUSR2 ProgramSignal = `USR2`
)

func (ProgramSignal) Signal

func (signal ProgramSignal) Signal() os.Signal

type ProgramState

type ProgramState string
const (
	ProgramStopped  ProgramState = `STOPPED`
	ProgramStarting ProgramState = `STARTING`
	ProgramRunning  ProgramState = `RUNNING`
	ProgramBackoff  ProgramState = `BACKOFF`
	ProgramStopping ProgramState = `STOPPING`
	ProgramExited   ProgramState = `EXITED`
	ProgramFatal    ProgramState = `FATAL`
	ProgramUnknown  ProgramState = `UNKNOWN`
)

type Server

type Server struct {
	Address     string `json:"address"                ini:"address"`
	UiDirectory string `json:"ui_directory,omitempty" ini:"ui_directory"`
	// contains filtered or unexported fields
}

func (*Server) Initialize

func (server *Server) Initialize(manager *Manager) error

func (*Server) Start

func (server *Server) Start() error

Directories

Path Synopsis
cmd
procwatch command

Jump to

Keyboard shortcuts

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