process

package
v0.0.0-...-dcf77fd Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddConfigChangeMonitor

func AddConfigChangeMonitor(path, filePattern string, fileChangeCb func(path string, mode filechangemonitor.FileChangeMode))

AddConfigChangeMonitor add a program change listener to monitor if any one of its configuration files is changed

func AddProgramChangeMonitor

func AddProgramChangeMonitor(path string, fileChangeCb func(path string, mode filechangemonitor.FileChangeMode))

AddProgramChangeMonitor add a program change listener to monitor if the program binary

func SetShellArgs

func SetShellArgs(s []string)

Types

type Manager

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

Manager manage all the process in the supervisor

func NewManager

func NewManager() *Manager

NewManager create a new Manager object

func (*Manager) Add

func (pm *Manager) Add(name string, proc *Process)

Add add the process to this process manager

func (*Manager) AsyncForEachProcess

func (pm *Manager) AsyncForEachProcess(procFunc func(p *Process), done chan *Process) int

AsyncForEachProcess handle each process in async mode Args: - procFunc, the function to handle the process - done, signal the process is completed Returns: number of total processes

func (*Manager) Clear

func (pm *Manager) Clear()

Clear clear all the processes

func (*Manager) CreateOrUpdateProcess

func (pm *Manager) CreateOrUpdateProcess(supervisorID string, after *config.Process) *Process

CreateOrUpdateProcess creates a new process and adds it to the manager or updates an existing process.

func (*Manager) Find

func (pm *Manager) Find(name string) *Process

Find find process by program name return process if found or nil if not found

func (*Manager) FindMatch

func (pm *Manager) FindMatch(name string) []*Process

FindMatch find the program with one of following format: - group.program - group.* - program

func (*Manager) FindMatchWithLabels

func (pm *Manager) FindMatchWithLabels(name string, labels map[string]string) []*Process

FindMatchWithLabels matches Processes by name and labels.

func (*Manager) ForEachProcess

func (pm *Manager) ForEachProcess(procFunc func(p *Process))

ForEachProcess process each process in sync mode

func (*Manager) RemoveProcess

func (pm *Manager) RemoveProcess(name string) *Process

RemoveProcess remove the process from the manager and stops it, if it was running. Returns the removed process.

func (*Manager) StartAutoStartPrograms

func (pm *Manager) StartAutoStartPrograms()

StartAutoStartPrograms start all the program if its autostart is true

func (*Manager) StopAllProcesses

func (pm *Manager) StopAllProcesses()

StopAllProcesses stop all the processes managed by this manager

type Process

type Process struct {
	StdoutLog *logger.CompositeLogger
	StderrLog *logger.CompositeLogger

	StdoutBacklog *RingBuffer
	StderrBacklog *RingBuffer
	// contains filtered or unexported fields
}

Process the program process management data

func NewProcess

func NewProcess(supervisorID string, cfg *config.Process) *Process

NewProcess create a new Process

func (*Process) Config

func (p *Process) Config() *config.Process

func (*Process) Description

func (p *Process) Description() string

Description get the process status description

func (*Process) Destroy

func (p *Process) Destroy(wait bool)

Destroy stops the process and removes it from cron

func (*Process) ExitStatus

func (p *Process) ExitStatus() int

GetExitStatus get the exit status of the process if the program exit

func (*Process) GetStatus

func (p *Process) GetStatus() string

GetStatus get the status of program in string

func (*Process) Group

func (p *Process) Group() string

Group which group the program belongs to

func (*Process) MatchLabels

func (p *Process) MatchLabels(labels map[string]string) bool

MatchLabels sees if a Process's label-set matches some search set.

func (*Process) Name

func (p *Process) Name() string

Name returns the name of program

func (*Process) Pid

func (p *Process) Pid() int

GetPid get the pid of running process or 0 it is not in running status

func (*Process) SendProcessStdin

func (p *Process) SendProcessStdin(chars string) error

SendProcessStdin send data to process stdin

func (*Process) Signal

func (p *Process) Signal(sig os.Signal, sigChildren bool) error

Signal send signal to the process

Args:

sig - the signal to the process
sigChildren - true: send the signal to the process and its children proess

func (*Process) Start

func (p *Process) Start(wait bool)

Start start the process Args:

wait - true, wait the program started or failed

func (*Process) StartTime

func (p *Process) StartTime() time.Time

GetStartTime get the process start time

func (*Process) State

func (p *Process) State() State

GetState Get the process state

func (*Process) StderrLogfile

func (p *Process) StderrLogfile() string

GetStderrLogfile get the program stderr log file

func (*Process) StdoutLogfile

func (p *Process) StdoutLogfile() string

GetStdoutLogfile get the program stdout log file

func (*Process) Stop

func (p *Process) Stop(wait bool)

Stop send signal to process to stop it

func (*Process) StopTime

func (p *Process) StopTime() time.Time

GetStopTime get the process stop time

func (*Process) UpdateConfig

func (p *Process) UpdateConfig(config *config.Process)

type ResourceUsage

type ResourceUsage struct {
	CPU      float64
	Memory   float64
	Resident int
}

ResourceUsage describes the system resource usage of a process.

func Stat

func Stat(pid int) (*ResourceUsage, error)

Stat gets the resource usage of a pid using `ps`.

func (ResourceUsage) HumanResident

func (r ResourceUsage) HumanResident() string

HumanResident returns a human readable version of the memory usage.

type RingBuffer

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

RingBuffer is a ring-buffer.

func NewRingBuffer

func NewRingBuffer(maxSize int) *RingBuffer

NewRingBuffer creates a new RingBuffer with the given maximum size in bytes.

func (*RingBuffer) Bytes

func (l *RingBuffer) Bytes() (int64, []byte)

Bytes returns a byte slice containing all data written to the buffer and the number of bytes before it that have been discarded because of the buffer's size limit.

We trim the output to the first newline character (if we can find one) in order to keep the output looking nice.

func (*RingBuffer) Empty

func (l *RingBuffer) Empty()

Empty zeroes the buffer.

func (*RingBuffer) Write

func (l *RingBuffer) Write(b []byte) (int, error)

Write writes data to the RingBuffer.

type StatError

type StatError struct {
	PID int
	Err error
}

StatError is returned when Stat-ing a PID.

func (StatError) Error

func (e StatError) Error() string

Error implements error

func (StatError) Unwrap

func (e StatError) Unwrap() error

Unwrap allows StatError to be used with errors.Is/As.

type State

type State int

State the state of process

const (
	// Stopped the stopped state
	Stopped State = 0

	// Starting the starting state
	Starting State = 10

	// Running the running state
	Running State = 20

	// Backoff the backoff state
	Backoff State = 30

	// Stopping the stopping state
	Stopping State = 40

	// Exited the Exited state
	Exited State = 100

	// Fatal the Fatal state
	Fatal State = 200

	// Unknown the unknown state
	Unknown State = 1000
)

func (State) String

func (p State) String() string

String convert State to human readable string

Jump to

Keyboard shortcuts

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