Documentation
¶
Index ¶
- type AutoReStart
- type IProc
- type Info
- type Manager
- func (that *Manager) Add(name string, process IProc)
- func (that *Manager) GetAllProcs() []IProc
- func (that *Manager) GetAllProcsInfo() ([]*Info, error)
- func (that *Manager) GracefulReload(name string, wait bool) (bool, error)
- func (that *Manager) NewProcess(name string, options ...Option) (p *ProcessPlus, err error)
- func (that *Manager) Remove(name string) (value IProc)
- func (that *Manager) SearchProc(name string) (value IProc, found bool)
- func (that *Manager) StopAllProcs()
- type Option
- func ProcArgs(args []string) Option
- func ProcAutoReStart(a AutoReStart) Option
- func ProcDirectory(dir string) Option
- func ProcEnvVar(key, value string) Option
- func ProcEnvVarByMap(envs map[string]string) Option
- func ProcExitCodes(codes ...int) Option
- func ProcExtraFiles(fList []*os.File) Option
- func ProcKillAsGroup(kag bool) Option
- func ProcKillWaitSecs(t int) Option
- func ProcName(name string) Option
- func ProcPath(path string) Option
- func ProcPriority(pri int) Option
- func ProcRedirectStderr(r bool) Option
- func ProcRestartPause(t int) Option
- func ProcRestartWhenBinaryChanged(rwc bool) Option
- func ProcSetExtend(key, value interface{}) Option
- func ProcStartRetries(rts int) Option
- func ProcStartSecs(t int) Option
- func ProcStderrLog(file, maxBytes string, backups ...int) Option
- func ProcStdoutLog(file, maxBytes string, backups ...int) Option
- func ProcStopAsGroup(sag bool) Option
- func ProcStopSignal(sigs ...string) Option
- func ProcStopWaitSecs(t int) Option
- func ProcUser(user string) Option
- type ProcSettings
- type ProcState
- type ProcessPlus
- func (that *ProcessPlus) Clone() (IProc, error)
- func (that *ProcessPlus) CreateStderrLogger() proclog.Logger
- func (that *ProcessPlus) CreateStdoutLogger() proclog.Logger
- func (that *ProcessPlus) FailToStartProgram(reason string, finishCb func())
- func (that *ProcessPlus) GetDescription() string
- func (that *ProcessPlus) GetExitCode() (int, error)
- func (that *ProcessPlus) GetExitCodes() []int
- func (that *ProcessPlus) GetExitStatus() int
- func (that *ProcessPlus) GetProcessInfo() *Info
- func (that *ProcessPlus) GetStatus() string
- func (that *ProcessPlus) GetStderrLogfile() string
- func (that *ProcessPlus) GetStdoutLogfile() string
- func (that *ProcessPlus) InExitCodes(exitCode int) bool
- func (that *ProcessPlus) Init() (err error)
- func (that *ProcessPlus) IsAutoRestart() bool
- func (that *ProcessPlus) IsRunning() bool
- func (that *ProcessPlus) MonitorProgramIsRunning(endTime time.Time, monitorExited *int32, programExited *int32)
- func (that *ProcessPlus) Pid() int
- func (that *ProcessPlus) RunProc(finishCb func())
- func (that *ProcessPlus) SendSignal(sig os.Signal, sigChildren bool) error
- func (that *ProcessPlus) SendSignals(sigs []string, sigChildren bool)
- func (that *ProcessPlus) SetUser() error
- func (that *ProcessPlus) Signal(sig os.Signal, sigChildren bool) error
- func (that *ProcessPlus) StartProc(wait bool)
- func (that *ProcessPlus) StopProc(wait bool)
- func (that *ProcessPlus) WaitForExit(_ int64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AutoReStart ¶
type AutoReStart string
const ( AutoReStartUnexpected AutoReStart = "unexpected" // 默认为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 ¶ added in v1.0.1
func NewManager ¶ added in v1.0.1
func NewManager() *Manager
func (*Manager) GetAllProcs ¶ added in v1.0.1
GetAllProcs 获取所有进程的列表
func (*Manager) GetAllProcsInfo ¶ added in v1.0.1
GetAllProcsInfo 获取所有进程的信息列表
func (*Manager) GracefulReload ¶ added in v1.0.1
GracefulReload 平滑重启
func (*Manager) NewProcess ¶ added in v1.0.1
func (that *Manager) NewProcess(name string, options ...Option) (p *ProcessPlus, err error)
func (*Manager) SearchProc ¶ added in v1.0.2
Search 查找进程
func (*Manager) StopAllProcs ¶ added in v1.0.1
func (that *Manager) StopAllProcs()
StopAllProcs 停止所有进程
type Option ¶
type Option func(p *ProcessPlus)
func ProcEnvVarByMap ¶
SetProcEnvVarByMap 设置进程的环境变量,通过map的方式
func ProcExitCodes ¶
SetProcExitCodes 设置进程退出的code值列表,该列表中的值表示已知
func ProcExtraFiles ¶
SetProcExtraFiles 设置子进程从父进程继承的文件句柄
func ProcKillAsGroup ¶
SetProcKillAsGroup 默认为false,向进程组发送kill信号,包括子进程
func ProcRedirectStderr ¶
SetProcRedirectStderr 设置错误输出与标准输出一起
func ProcRestartPause ¶
SetProcRestartPause 设置进程重启间隔秒数,默认是0,表示不间隔
func ProcRestartWhenBinaryChanged ¶
SetProcRestartWhenBinaryChanged 当进程的二进制文件有修改,是否需要重启
func ProcStderrLog ¶
ProcStderrLog 设置stderrlog的存放配置
func ProcStdoutLog ¶
SetProcStdoutLog 设置进程标准日志输出的文件
func ProcStopAsGroup ¶
SetProcStopAsGroup 默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
type ProcSettings ¶
type ProcSettings struct { Environment *gmap.StrStrMap // 环境变量 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 // 强制杀死进程等待秒数 RestartWhenBinaryChanged bool // 当进程的二进制文件有修改,是否需要重启,默认false Extend *gmap.AnyAnyMap // 扩展参数 }
type ProcState ¶
type ProcState int
======================= 进程状态:
描述进程状态的类型
const ( Stopped ProcState = 1 // Stopped 已停止 Starting ProcState = 2 // Starting 启动中 Running ProcState = 4 // Running 运行中 Suspend ProcState = 8 // Suspend 已挂起 Stopping ProcState = 16 // Stopping 停止中 Exited ProcState = 32 // Exited 已退出 Fatal ProcState = 64 // Fatal 启动失败 Unknown ProcState = 128 // Unknown 未知状态 Failure ProcState = Stopped | Fatal | Unknown | Exited | Suspend Exist ProcState = Running | Starting | Stopping )
type ProcessPlus ¶
type ProcessPlus struct { *exec.Cmd *ProcSettings ProcManager *Manager // 进程管理器 Name string // 进程名称 State ProcState // 进程的当前状态 Starting bool // 正在启动的时候,该值为true StopByUser bool // 用户主动关闭的时候,该值为true RetryTimes *int32 // 启动重试的次数 StartTime time.Time // 启动时间 StopTime time.Time // 停止时间 Lock sync.RWMutex Stdin io.WriteCloser StdoutLog proclog.Logger StderrLog proclog.Logger }
func NewProcess ¶
func NewProcess(path, name string) (p *ProcessPlus)
NewProcess 创建进程: path, 可执行文件绝对路径;name, 进程名称
func (*ProcessPlus) CreateStderrLogger ¶
func (that *ProcessPlus) CreateStderrLogger() proclog.Logger
创建标准错误日志
func (*ProcessPlus) CreateStdoutLogger ¶
func (that *ProcessPlus) CreateStdoutLogger() proclog.Logger
创建标准输出日志
func (*ProcessPlus) FailToStartProgram ¶
func (that *ProcessPlus) FailToStartProgram(reason string, finishCb func())
设置程序启动失败状态
func (*ProcessPlus) GetDescription ¶
func (that *ProcessPlus) GetDescription() string
GetDescription 获取进程描述
func (*ProcessPlus) GetExitStatus ¶
func (that *ProcessPlus) GetExitStatus() int
GetExitStatus 获取进程退出状态
func (*ProcessPlus) GetProcessInfo ¶
func (that *ProcessPlus) GetProcessInfo() *Info
GetProcessInfo 获取进程的详情
func (*ProcessPlus) GetStderrLogfile ¶
func (that *ProcessPlus) GetStderrLogfile() string
GetStderrLogfile 获取标准错误将要写入的日志文件
func (*ProcessPlus) GetStdoutLogfile ¶
func (that *ProcessPlus) GetStdoutLogfile() string
GetStdoutLogfile 获取标准输出将要写入的日志文件
func (*ProcessPlus) InExitCodes ¶
func (that *ProcessPlus) InExitCodes(exitCode int) bool
进程的退出code值是否在设置中的codes列表中
func (*ProcessPlus) Init ¶
func (that *ProcessPlus) Init() (err error)
func (*ProcessPlus) MonitorProgramIsRunning ¶
func (that *ProcessPlus) MonitorProgramIsRunning(endTime time.Time, monitorExited *int32, programExited *int32)
监控进程是否正在运行中
func (*ProcessPlus) RunProc ¶
func (that *ProcessPlus) RunProc(finishCb func())
运行进程,finishCb是进程创建过程结束之后的回调,用于解除父goroutine的阻塞
func (*ProcessPlus) SendSignal ¶
func (that *ProcessPlus) SendSignal(sig os.Signal, sigChildren bool) error
sendSignal 向进程发送信号 sig: 要发送的信号 sigChildren: 如果为true,则信号会发送到该进程的子进程
func (*ProcessPlus) SendSignals ¶
func (that *ProcessPlus) SendSignals(sigs []string, sigChildren bool)
发送多个信号到进程 sig: 要发送的信号列表 sigChildren: 如果为true,则信号会发送到该进程的子进程
func (*ProcessPlus) Signal ¶
func (that *ProcessPlus) Signal(sig os.Signal, sigChildren bool) error
Signal 向进程发送信号 sig: 要发送的信号 sigChildren: 如果为true,则信号会发送到该进程的子进程
func (*ProcessPlus) StartProc ¶
func (that *ProcessPlus) StartProc(wait bool)
Start 启动进程,wait表示阻塞等待进程成功启动