Documentation ¶
Index ¶
- Constants
- func DisableDebug()
- func EnableDebug()
- func Reap()
- func ReapZombie()
- func Start(config Config)
- type AutoReStart
- type Config
- type Info
- type Manager
- func (that *Manager) Add(name string, proc *Process)
- func (that *Manager) Clear()
- func (that *Manager) Find(name string) *Process
- func (that *Manager) ForEachProcess(procFunc func(p *Process))
- func (that *Manager) GetAllProcessInfo() ([]*Info, error)
- func (that *Manager) GetProcessInfo(name string) (*Info, error)
- func (that *Manager) GracefulReload(name string, wait bool) (bool, error)
- func (that *Manager) NewProcess(path string, args []string, environment map[string]string, opts ...ProcOption) (*Process, error)
- func (that *Manager) NewProcessByOptions(opts ProcOptions) (*Process, error)
- func (that *Manager) NewProcessByProcess(proc *Process) (*Process, error)
- func (that *Manager) NewProcessCmd(cmd string, environment map[string]string) (*Process, error)
- func (that *Manager) Remove(name string) *Process
- func (that *Manager) StartProcess(name string, wait bool) (bool, error)
- func (that *Manager) StopAllProcesses()
- func (that *Manager) StopProcess(name string, wait bool) (bool, error)
- type ProcOption
- func ProcArgs(opt ...string) ProcOption
- func ProcAutoReStart(opt AutoReStart) ProcOption
- func ProcAutoStart(opt bool) ProcOption
- func ProcCommand(opt string) ProcOption
- func ProcDirectory(opt string) ProcOption
- func ProcEnvironment(opt map[string]string) ProcOption
- func ProcExitCodes(opt ...int) ProcOption
- func ProcExtraFiles(opt []*os.File) ProcOption
- func ProcKillAsGroup(opt bool) ProcOption
- func ProcKillWaitSecs(opt int) ProcOption
- func ProcName(opt string) ProcOption
- func ProcPriority(opt int) ProcOption
- func ProcRedirectStderr(opt bool) ProcOption
- func ProcRestartPause(opt int) ProcOption
- func ProcRestartWhenBinaryChanged(opt bool) ProcOption
- func ProcSetEnvironment(key, val string) ProcOption
- func ProcSetExtend(key, val interface{}) ProcOption
- func ProcStartRetries(opt int) ProcOption
- func ProcStartSecs(opt int) ProcOption
- func ProcStderrLog(file string, maxBytes string, backups ...int) ProcOption
- func ProcStdoutLog(file string, maxBytes string, backups ...int) ProcOption
- func ProcStopAsGroup(opt bool) ProcOption
- func ProcStopSignal(opt ...string) ProcOption
- func ProcStopWaitSecs(opt int) ProcOption
- func ProcUser(opt string) ProcOption
- type ProcOptions
- 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) 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
Constants ¶
const ( // Stopped 已停止 Stopped State = iota // Starting 启动中 Starting = 10 // Running 运行中 Running = 20 // Backoff 已挂起 Backoff = 30 // Stopping 停止中 Stopping = 40 // Exited 已退出 Exited = 100 // Fatal 启动失败 Fatal = 200 // Unknown 未知状态 Unknown = 1000 )
Variables ¶
This section is empty.
Functions ¶
func DisableDebug ¶
func DisableDebug()
func EnableDebug ¶
func EnableDebug()
Types ¶
type AutoReStart ¶ added in v1.0.0
type AutoReStart string
const ( AutoReStartUnexpected AutoReStart = "unexpected" AutoReStartTrue AutoReStart = "true" AutoReStartFalse AutoReStart = "false" )
程序退出后自动重启
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 Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) ForEachProcess ¶
ForEachProcess 迭代进程列表
func (*Manager) GetAllProcessInfo ¶
GetAllProcessInfo 获取所有进程信息
func (*Manager) GetProcessInfo ¶
GetProcessInfo 获取指定进程名的进程信息
func (*Manager) GracefulReload ¶ added in v1.0.0
GracefulReload 停止指定进程
func (*Manager) NewProcess ¶
func (that *Manager) NewProcess(path string, args []string, environment map[string]string, opts ...ProcOption) (*Process, error)
NewProcess 创建进程 path: 可执行文件路径 args: 参数 environment: 环境变量
func (*Manager) NewProcessByOptions ¶ added in v1.0.0
func (that *Manager) NewProcessByOptions(opts ProcOptions) (*Process, error)
NewProcessByOptions 创建进程 entry: 配置对象
func (*Manager) NewProcessByProcess ¶ added in v1.0.0
NewProcessByProcess 创建进程 proc: Process对象
func (*Manager) NewProcessCmd ¶
NewProcessCmd 创建进程 path: shell命令 environment: 环境变量
func (*Manager) StartProcess ¶
StartProcess 启动指定进程
type ProcOption ¶ added in v1.0.0
type ProcOption func(*ProcOptions)
func ProcAutoReStart ¶ added in v1.0.0
func ProcAutoReStart(opt AutoReStart) ProcOption
ProcAutoReStart 程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启
func ProcAutoStart ¶ added in v1.0.0
func ProcAutoStart(opt bool) ProcOption
ProcAutoStart 启动的时候自动该进程启动
func ProcEnvironment ¶ added in v1.0.0
func ProcEnvironment(opt map[string]string) ProcOption
func ProcExitCodes ¶ added in v1.0.0
func ProcExitCodes(opt ...int) ProcOption
ProcExitCodes 进程退出的code值列表,该列表中的值表示已知
func ProcExtraFiles ¶ added in v1.0.0
func ProcExtraFiles(opt []*os.File) ProcOption
ProcExtraFiles 设置打开的文件句柄列表
func ProcKillAsGroup ¶ added in v1.0.0
func ProcKillAsGroup(opt bool) ProcOption
ProcKillAsGroup 默认为false,向进程组发送kill信号,包括子进程
func ProcKillWaitSecs ¶ added in v1.0.0
func ProcKillWaitSecs(opt int) ProcOption
ProcKillWaitSecs 强杀进程等待秒数
func ProcPriority ¶ added in v1.0.0
func ProcPriority(opt int) ProcOption
ProcPriority 进程启动优先级,默认999,值小的优先启动
func ProcRedirectStderr ¶ added in v1.0.0
func ProcRedirectStderr(opt bool) ProcOption
ProcRedirectStderr 错误输出是否与标准输入一起
func ProcRestartPause ¶ added in v1.0.0
func ProcRestartPause(opt int) ProcOption
ProcRestartPause 进程重启间隔秒数,默认是0,表示不间隔
func ProcRestartWhenBinaryChanged ¶ added in v1.0.0
func ProcRestartWhenBinaryChanged(opt bool) ProcOption
ProcRestartWhenBinaryChanged 当进程的二进制文件有修改,是否需要重启
func ProcSetEnvironment ¶ added in v1.0.0
func ProcSetEnvironment(key, val string) ProcOption
ProcSetEnvironment 环境变量
func ProcSetExtend ¶ added in v1.0.0
func ProcSetExtend(key, val interface{}) ProcOption
ProcSetExtend 扩展参数
func ProcStartRetries ¶ added in v1.0.0
func ProcStartRetries(opt int) ProcOption
ProcStartRetries 启动失败自动重试次数,默认是3
func ProcStartSecs ¶ added in v1.0.0
func ProcStartSecs(opt int) ProcOption
ProcStartSecs 指定启动多少秒后没有异常退出,则表示启动成功 // 未设置该值,则表示cmd.Start方法调用为出错,则表示启动成功, // 设置了该值,则表示程序启动后需稳定运行指定的秒数后才算启动成功
func ProcStderrLog ¶ added in v1.0.0
func ProcStderrLog(file string, maxBytes string, backups ...int) ProcOption
ProcStderrLog 设置stderrlog的存放配置
func ProcStdoutLog ¶ added in v1.0.0
func ProcStdoutLog(file string, maxBytes string, backups ...int) ProcOption
ProcStdoutLog 设置stdoutlog的存放配置
func ProcStopAsGroup ¶ added in v1.0.0
func ProcStopAsGroup(opt bool) ProcOption
ProcStopAsGroup 默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
func ProcStopSignal ¶ added in v1.0.0
func ProcStopSignal(opt ...string) ProcOption
ProcStopSignal 结束进程发送的信号列表
func ProcStopWaitSecs ¶ added in v1.0.0
func ProcStopWaitSecs(opt int) ProcOption
ProcStopWaitSecs 发送结束进程的信号后等待的秒数
type ProcOptions ¶ added in v1.0.0
type ProcOptions struct { //进程名称 Name string // 启动命令 Command string // 启动参数 Args []string //进程运行目录 Directory string //启动的时候自动该进程启动 AutoStart bool //启动10秒后没有异常退出,就表示进程正常启动了,默认为1秒 StartSecs int //程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启 AutoReStart AutoReStart // 进程退出的code值 ExitCodes []int //启动失败自动重试次数,默认是3 StartRetries int //进程重启间隔秒数,默认是0,表示不间隔 RestartPause int //用哪个用户启动进程,默认是父进程的所属用户 User string //进程启动优先级,默认999,值小的优先启动 Priority int //日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件) StdoutLogfile string //stdout 日志文件大小,默认50MB StdoutLogFileMaxBytes int //stdout 日志文件备份数,默认是10 StdoutLogFileBackups int // 把stderr重定向到stdout,默认false RedirectStderr bool // 日志文件,进程启动后的标准错误写入该文件 StderrLogfile string //stderr 日志文件大小,默认50MB StderrLogFileMaxBytes int //stderr 日志文件备份数,默认是10 StderrLogFileBackups int //默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程 StopAsGroup bool //默认为false,向进程组发送kill信号,包括子进程 KillAsGroup bool //结束进程发送的信号 StopSignal []string // 发送结束进程的信号后等待的秒数 StopWaitSecs int // 强杀进程等待秒数 KillWaitSecs int // 环境变量 Environment *gmap.StrStrMap //当进程的二进制文件有修改,是否需要重启,默认false RestartWhenBinaryChanged bool // 继承主进程已经打开的文件列表 ExtraFiles []*os.File // 扩展参数 Extend *gmap.AnyAnyMap }
func NewProcOptions ¶ added in v1.0.0
func NewProcOptions(opts ...ProcOption) ProcOptions
NewProcOptions 创建进程启动配置
func (ProcOptions) CreateCommand ¶ added in v1.0.0
func (that ProcOptions) CreateCommand() (*exec.Cmd, error)
CreateCommand 根据就配置生成cmd对象
type Process ¶
type Process struct { // 进程管理对象 Manager *Manager StdoutLog proclog.Logger StderrLog proclog.Logger // contains filtered or unexported fields }
func NewProcessByOptions ¶ added in v1.0.0
func NewProcessByOptions(options ProcOptions) *Process
NewProcessByOptions 通过详细配置,创建进程对象
func NewProcessCmd ¶
NewProcessCmd 按命令启动
func (*Process) GetStderrLogfile ¶
GetStderrLogfile 获取标准错误将要写入的日志文件
func (*Process) GetStdoutLogfile ¶
GetStdoutLogfile 获取标准输出将要写入的日志文件