Documentation ¶
Overview ¶
Package process 是一个进程管理器,类似于supervisor,能够监控进程的运行状态,自动重启失败进程。
manager := NewManager(3*time.Second, func(logType OutputType, line string, process *Process) { color.Green("%s[%s] => %s\n", process.GetName(), logType, line) }) manager.AddProgram("test", "/bin/sleep 1", 5, "") manager.AddProgram("prometheus", "/bin/echo Hello", 1, "") ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() manager.Watch(ctx)
Index ¶
- Constants
- type Manager
- type OutputFunc
- type OutputType
- type Process
- func (process *Process) GetArgs() []string
- func (process *Process) GetCommand() string
- func (process *Process) GetLastErrorMessage() string
- func (process *Process) GetName() string
- func (process *Process) GetPID() int
- func (process *Process) GetUser() string
- func (process *Process) SetLastErrorMessage(msg string)
- func (process *Process) SetPID(pid int)
- type Program
Constants ¶
View Source
const ( // LogTypeStderr stderr output LogTypeStderr = OutputType("stderr") // LogTypeStdout stdout output LogTypeStdout = OutputType("stdout") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is process manager
func NewManager ¶
func NewManager(closeTimeout time.Duration, processOutputFunc OutputFunc) *Manager
NewManager create a new process manager
func (*Manager) AddProgram ¶
AddProgram add a new program to manager
type OutputFunc ¶
type OutputFunc func(logType OutputType, line string, process *Process)
OutputFunc process output handler
type Process ¶
Process is a program instance
func NewProcess ¶
NewProcess create a new process
func (*Process) GetLastErrorMessage ¶
GetLastErrorMessage get last error message
func (*Process) SetLastErrorMessage ¶
SetLastErrorMessage update last error message
type Program ¶
type Program struct { Name string `json:"name,omitempty"` Command string `json:"command,omitempty"` User string `json:"user,omitempty"` ProcNum int `json:"proc_num,omitempty"` // contains filtered or unexported fields }
Program is the program we want to execute
func NewProgram ¶
NewProgram create a new Program
Click to show internal directories.
Click to hide internal directories.