Documentation ¶
Index ¶
- Constants
- func Reap()
- func ReapZombie()
- func Start(config Config)
- type AutoReStart
- type Config
- type Info
- type Logger
- type Manager
- func (m *Manager) Add(name string, proc *Process)
- func (m *Manager) Clear()
- func (m *Manager) Find(name string) *Process
- func (m *Manager) ForEachProcess(procFunc func(p *Process))
- func (m *Manager) GetAllProcessInfo() ([]*Info, error)
- func (m *Manager) GetProcessInfo(name string) (*Info, error)
- func (m *Manager) GracefulReload(name string, wait bool) (bool, error)
- func (m *Manager) NewProcess(opts ...WithOption) (*Process, error)
- func (m *Manager) NewProcessByOptions(opts Options) (*Process, error)
- func (m *Manager) NewProcessByProcess(proc *Process) (*Process, error)
- func (m *Manager) NewProcessCmd(cmd string, environment map[string]string) (*Process, error)
- func (m *Manager) Remove(name string) *Process
- func (m *Manager) StartProcess(name string, wait bool) (bool, error)
- func (m *Manager) StopAllProcesses()
- func (m *Manager) StopProcess(name string, wait bool) (bool, error)
- type Options
- type Process
- func (that *Process) Clone() (*Process, error)
- func (that *Process) GetDescription() string
- func (that *Process) GetExitStatus() int
- func (that *Process) GetName() string
- func (that *Process) GetProcessInfo() *Info
- func (that *Process) GetStartTime() time.Time
- func (that *Process) GetState() State
- func (that *Process) GetStatus() string
- func (that *Process) GetStderrLogfile() string
- func (that *Process) GetStdoutLogfile() string
- func (that *Process) GetStopTime() time.Time
- func (that *Process) IsAutoStart() bool
- func (that *Process) Pid() int
- func (that *Process) Signal(sig os.Signal, sigChildren bool) error
- func (that *Process) Start(wait bool)
- func (that *Process) Stop(wait bool)
- type State
- type WithOption
- func WithArgs(opt ...string) WithOption
- func WithAutoReStart(opt AutoReStart) WithOption
- func WithAutoStart(opt bool) WithOption
- func WithCommand(opt string) WithOption
- func WithDirectory(opt string) WithOption
- func WithEnvironment(opt map[string]string) WithOption
- func WithExitCodes(opt ...int) WithOption
- func WithExtraFiles(opt []*os.File) WithOption
- func WithKillAsGroup(opt bool) WithOption
- func WithKillWaitSecs(opt int) WithOption
- func WithName(opt string) WithOption
- func WithPriority(opt int) WithOption
- func WithRedirectStderr(opt bool) WithOption
- func WithRestartPause(opt int) WithOption
- func WithRestartWhenBinaryChanged(opt bool) WithOption
- func WithSetEnvironment(key, val string) WithOption
- func WithSetExtend(key, val interface{}) WithOption
- func WithStartRetries(opt int) WithOption
- func WithStartSecs(opt int) WithOption
- func WithStderrLog(file string, maxBytes string, backups ...int) WithOption
- func WithStdoutLog(file string, maxBytes string, backups ...int) WithOption
- func WithStopAsGroup(opt bool) WithOption
- func WithStopSignal(opt ...string) WithOption
- func WithStopWaitSecs(opt int) WithOption
- func WithUser(opt string) WithOption
Constants ¶
const ( Stopped State = iota // Stopped 已停止 Starting = 10 // Starting 启动中 Running = 20 // Running 运行中 Backoff = 30 // Backoff 已挂起 Stopping = 40 // Stopping 停止中 Exited = 100 // Exited 已退出 Fatal = 200 // Fatal 启动失败 Unknown = 1000 // Unknown 未知状态 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AutoReStart ¶
type AutoReStart uint8
AutoReStart 定义自动重启类型
const ( AutoReStartUnexpected AutoReStart = iota AutoReStartTrue AutoReStart = iota // 1 AutoReStartFalse AutoReStart = iota // 0 )
type Info ¶
type Info struct { Name string `json:"name"` Description string `json:"description"` Start int `json:"start"` Stop int `json:"stop"` Now int `json:"now"` State int `json:"state"` StateName string `json:"statename"` SpawnErr string `json:"spawnerr"` ExitStatus int `json:"exitstatus"` Logfile string `json:"logfile"` StdoutLogfile string `json:"stdout_logfile"` StderrLogfile string `json:"stderr_logfile"` Pid int `json:"pid"` }
Info 进程的运行状态
type Logger ¶
type Logger interface { Infof(format string, args ...any) Debugf(format string, args ...any) Warnf(format string, args ...any) Errorf(format string, args ...any) }
Logger 日志记录器接口
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) ForEachProcess ¶
ForEachProcess 迭代进程列表
func (*Manager) GetAllProcessInfo ¶
GetAllProcessInfo 获取所有进程列表
func (*Manager) GetProcessInfo ¶
GetProcessInfo 获取所有进程信息
func (*Manager) GracefulReload ¶
GracefulReload 停止指定进程
func (*Manager) NewProcess ¶
func (m *Manager) NewProcess(opts ...WithOption) (*Process, error)
NewProcess 创建新的进程实例 opts: 配置对象
func (*Manager) NewProcessByOptions ¶
NewProcessByOptions 创建进程 opts: 配置对象
func (*Manager) NewProcessByProcess ¶
NewProcessByProcess 创建进程 proc: Process对象
func (*Manager) NewProcessCmd ¶
NewProcessCmd 创建进程 cmd: 可执行文件路径及参数 environment: 环境变量
func (*Manager) StartProcess ¶
StartProcess 启动指定进程
type Options ¶
type Options struct { Name string // 进程名称 Command string // 启动命令 Args []string // 启动参数 Directory string // 进程运行目录 AutoStart bool // 启动的时候自动该进程启动 StartSecs int // 启动10秒后没有异常退出,就表示进程正常启动了,默认为1秒 AutoReStart AutoReStart // 程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启 ExitCodes []int // 进程退出的code值 StartRetries int // 启动失败自动重试次数,默认是3 RestartPause int // 进程重启间隔秒数,默认是0,表示不间隔 User string // 用哪个用户启动进程,默认是父进程的所属用户 Priority int // 进程启动优先级,默认999,值小的优先启动 StdoutLogfile string // 日志文件,不存在时 supervisord 会自动创建日志文件) StdoutLogFileMaxBytes int // stdout 日志文件大小,默认50MB StdoutLogFileBackups int // stdout 日志文件备份数,默认是10 RedirectStderr bool // 把stderr重定向到stdout,默认false StderrLogfile string // 日志文件,进程启动后的标准错误写入该文件 StderrLogFileMaxBytes int // stderr 日志文件大小,默认50MB StderrLogFileBackups int // stderr 日志文件备份数,默认是10 StopAsGroup bool // 默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程 KillAsGroup bool // 默认为false,向进程组发送kill信号,包括子进程 StopSignal []string // 结束进程发送的信号 StopWaitSecs int // 发送结束进程的信号后等待的秒数 KillWaitSecs int // 强杀进程等待秒数 Environment *utils.StrStrMap // 环境变量 RestartWhenBinaryChanged bool // 当进程的二进制文件有修改,是否需要重启,默认false ExtraFiles []*os.File // 继承主进程已经打开的文件列表 Extend *utils.AnyAnyMap // 扩展参数 }
Options 进程配置选项
type Process ¶
type Process struct { Manager *Manager // 进程管理对象 // contains filtered or unexported fields }
func NewProcessByOptions ¶
NewProcessByOptions 通过详细配置,创建进程对象
func NewProcessCmd ¶
NewProcessCmd 按命令启动
func (*Process) GetStderrLogfile ¶
GetStderrLogfile 获取标准错误将要写入的日志文件
func (*Process) GetStdoutLogfile ¶
GetStdoutLogfile 获取标准输出将要写入的日志文件
type WithOption ¶
type WithOption func(*Options)
WithOption 定义选项函数类型
func WithAutoReStart ¶
func WithAutoReStart(opt AutoReStart) WithOption
WithAutoReStart 程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启
func WithEnvironment ¶
func WithEnvironment(opt map[string]string) WithOption
func WithExitCodes ¶
func WithExitCodes(opt ...int) WithOption
WithExitCodes 进程退出的code值列表,该列表中的值表示已知
func WithKillAsGroup ¶
func WithKillAsGroup(opt bool) WithOption
WithKillAsGroup 默认为false,向进程组发送kill信号,包括子进程
func WithRedirectStderr ¶
func WithRedirectStderr(opt bool) WithOption
WithRedirectStderr 错误输出是否与标准输入一起
func WithRestartPause ¶
func WithRestartPause(opt int) WithOption
WithRestartPause 进程重启间隔秒数,默认是0,表示不间隔
func WithRestartWhenBinaryChanged ¶
func WithRestartWhenBinaryChanged(opt bool) WithOption
WithRestartWhenBinaryChanged 当进程的二进制文件有修改,是否需要重启
func WithSetEnvironment ¶
func WithSetEnvironment(key, val string) WithOption
WithSetEnvironment 环境变量
func WithStartSecs ¶
func WithStartSecs(opt int) WithOption
WithStartSecs 指定启动多少秒后没有异常退出,则表示启动成功 // 未设置该值,则表示cmd.Start方法调用为出错,则表示启动成功, // 设置了该值,则表示程序启动后需稳定运行指定的秒数后才算启动成功
func WithStderrLog ¶
func WithStderrLog(file string, maxBytes string, backups ...int) WithOption
WithStderrLog 设置stderrlog的存放配置
func WithStdoutLog ¶
func WithStdoutLog(file string, maxBytes string, backups ...int) WithOption
WithStdoutLog 设置stdoutlog的存放配置
func WithStopAsGroup ¶
func WithStopAsGroup(opt bool) WithOption
WithStopAsGroup 默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程