process

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
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()

func Reap

func Reap()

Reap Normal entry point for the reaper code. Start reaping children in the

background inside a goroutine.

func ReapZombie

func ReapZombie()

ReapZombie 回收僵尸进程

func Start

func Start(config Config)

Start Entry point for invoking the reaper code with a specific configuration.

The config allows you to bypass the pid 1 checks, so handle with care.
The child processes are reaped in the background inside a goroutine.

Types

type Config

type Config struct {
	Pid              int
	Options          int
	DisablePid1Check bool
}

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 NewManager

func NewManager() *Manager

NewManager 创建进程管理器

func (*Manager) Add

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

Add 添加进程到Manager

func (*Manager) Clear

func (that *Manager) Clear()

Clear 清除进程

func (*Manager) Find

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

Find 根据进程名查询进程

func (*Manager) ForEachProcess

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

ForEachProcess 迭代进程列表

func (*Manager) GetAllProcessInfo

func (that *Manager) GetAllProcessInfo() ([]*Info, error)

GetAllProcessInfo 获取所有进程信息

func (*Manager) GetProcessInfo

func (that *Manager) GetProcessInfo(name string) (*Info, error)

GetProcessInfo 获取指定进程名的进程信息

func (*Manager) NewProcess

func (that *Manager) NewProcess(path string, args []string, environment []string) (*Process, error)

NewProcess 创建进程 path: 可执行文件路径 args: 参数 environment: 环境变量

func (*Manager) NewProcessByEntry

func (that *Manager) NewProcessByEntry(entry *Entry) (*Process, error)

NewProcessByEntry 创建进程 entry: 配置对象

func (*Manager) NewProcessCmd

func (that *Manager) NewProcessCmd(cmd string, environment ...[]string) (*Process, error)

NewProcessCmd 创建进程 path: shell命令 environment: 环境变量

func (*Manager) Remove

func (that *Manager) Remove(name string) *Process

Remove 从Manager移除进程

func (*Manager) StartProcess

func (that *Manager) StartProcess(name string, wait bool) (bool, error)

StartProcess 启动指定进程

func (*Manager) StopAllProcesses

func (that *Manager) StopAllProcesses()

StopAllProcesses 关闭所有进程

func (*Manager) StopProcess

func (that *Manager) StopProcess(name string, wait bool) (bool, error)

StopProcess 停止指定进程

type ProcEntry added in v0.0.8

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

func NewProcEntry added in v0.0.8

func NewProcEntry(command string, args ...[]string) *ProcEntry

NewProcEntry 创建进程启动配置

func NewProcEntryByConfigEntry added in v0.0.8

func NewProcEntryByConfigEntry(entry *config.Entry) *ProcEntry

NewProcEntryByConfigEntry 通过配置文件解析生成proc entry对象

func (*ProcEntry) Args added in v0.0.8

func (that *ProcEntry) Args() []string

Args 获取参数

func (*ProcEntry) AutoReStart added in v0.0.8

func (that *ProcEntry) AutoReStart(defVal string) string

AutoReStart 值为 true,false,unexpected

func (*ProcEntry) AutoStart added in v0.0.8

func (that *ProcEntry) AutoStart() bool

AutoStart 判断程序是否需要自动启动

func (*ProcEntry) Command added in v0.0.8

func (that *ProcEntry) Command() string

Command 获取启动命令

func (*ProcEntry) CreateCommand added in v0.0.8

func (that *ProcEntry) CreateCommand() (*exec.Cmd, error)

CreateCommand 根据就配置生成cmd对象

func (*ProcEntry) Directory added in v0.0.8

func (that *ProcEntry) Directory() string

Directory 程序运行目录

func (*ProcEntry) Environment added in v0.0.8

func (that *ProcEntry) Environment() []string

Environment 获取当前进程的环境变量

func (*ProcEntry) ExitCodes added in v0.0.8

func (that *ProcEntry) ExitCodes(defaultVal string) string

ExitCodes 退出code的值列表,格式为 1,2,3,4

func (*ProcEntry) Extend added in v0.0.8

func (that *ProcEntry) Extend(key string, defVal string) string

Extend 获取扩展配置

func (*ProcEntry) KillAsGroup added in v0.0.8

func (that *ProcEntry) KillAsGroup() bool

KillAsGroup 强制杀死进程的时候,是否向该进程的进程组发送kill信号

func (*ProcEntry) KillWaitSecs added in v0.0.8

func (that *ProcEntry) KillWaitSecs(defaultVal int) int

KillWaitSecs 强杀进程等待秒数

func (*ProcEntry) Name added in v0.0.8

func (that *ProcEntry) Name() string

Name 获取进程名称

func (*ProcEntry) Priority added in v0.0.8

func (that *ProcEntry) Priority() int

Priority 进程启动的优先级

func (*ProcEntry) RedirectStderr added in v0.0.8

func (that *ProcEntry) RedirectStderr() bool

RedirectStderr 是否重写标准错误输出到标准输出

func (*ProcEntry) RestartPause added in v0.0.8

func (that *ProcEntry) RestartPause() int

RestartPause 进程重启间隔秒数,默认是0,表示不间隔

func (*ProcEntry) SetArgs added in v0.0.8

func (that *ProcEntry) SetArgs(args []string)

SetArgs 设置参数

func (*ProcEntry) SetAutoReStart added in v0.0.8

func (that *ProcEntry) SetAutoReStart(val string)

SetAutoReStart 设置自动重启 值为 true,false,unexpected

func (*ProcEntry) SetAutoStart added in v0.0.8

func (that *ProcEntry) SetAutoStart(autoStart bool)

SetAutoStart 设置程序是否需要自动启动

func (*ProcEntry) SetCommand added in v0.0.8

func (that *ProcEntry) SetCommand(command string)

SetCommand 设置启动命令

func (*ProcEntry) SetDirectory added in v0.0.8

func (that *ProcEntry) SetDirectory(directory string)

SetDirectory 设置程序运行目录

func (*ProcEntry) SetEnvironment added in v0.0.8

func (that *ProcEntry) SetEnvironment(environment []string)

SetEnvironment 设置当前进程的环境变量

func (*ProcEntry) SetExitCodes added in v0.0.8

func (that *ProcEntry) SetExitCodes(val string)

SetExitCodes 设置退出code的值列表,格式为 1,2,3,4

func (*ProcEntry) SetExtend added in v0.0.8

func (that *ProcEntry) SetExtend(key string, val string)

SetExtend Extend 设置扩展配置信息

func (*ProcEntry) SetKillAsGroup added in v0.0.8

func (that *ProcEntry) SetKillAsGroup(killAsGroup bool)

SetKillAsGroup 强制杀死进程的时候,是否向该进程的进程组发送kill信号

func (*ProcEntry) SetKillWaitSecs added in v0.0.8

func (that *ProcEntry) SetKillWaitSecs(killWaitSecs int)

SetKillWaitSecs 强杀进程等待秒数

func (*ProcEntry) SetName added in v0.0.8

func (that *ProcEntry) SetName(name string)

SetName 设置进程名

func (*ProcEntry) SetPriority added in v0.0.8

func (that *ProcEntry) SetPriority(priority int)

SetPriority 设置进程启动优先级

func (*ProcEntry) SetRedirectStderr added in v0.0.8

func (that *ProcEntry) SetRedirectStderr(v bool)

SetRedirectStderr 是否重写标准错误输出到标准输出

func (*ProcEntry) SetRestartPause added in v0.0.8

func (that *ProcEntry) SetRestartPause(restartPause int)

SetRestartPause 设置进程重启间隔秒数

func (*ProcEntry) SetStartRetries added in v0.0.8

func (that *ProcEntry) SetStartRetries(startRetries int)

SetStartRetries 设置启动失败自动重试次数

func (*ProcEntry) SetStartSecs added in v0.0.8

func (that *ProcEntry) SetStartSecs(startSecs int)

SetStartSecs 指定启动多少秒后没有异常退出,则表示启动成功 未设置该值,则表示cmd.Start方法调用为出错,则表示启动成功, 设置了该值,则表示程序启动后需稳定运行指定的秒数后才算启动成功

func (*ProcEntry) SetStderrLogFileBackups added in v0.0.8

func (that *ProcEntry) SetStderrLogFileBackups(v int)

SetStderrLogFileBackups 设置标准错误输出的log文件如果达到了最大容量

func (*ProcEntry) SetStderrLogFileMaxBytes added in v0.0.8

func (that *ProcEntry) SetStderrLogFileMaxBytes(v string)

SetStderrLogFileMaxBytes 设置标准错误输出的log文件最大容量,格式:5KB,10MB,2GB,默认是50MB

func (*ProcEntry) SetStderrLogfile added in v0.0.8

func (that *ProcEntry) SetStderrLogfile(v string)

SetStderrLogfile 设置标准错误输出的log文件地址

func (*ProcEntry) SetStdoutLogFileBackups added in v0.0.8

func (that *ProcEntry) SetStdoutLogFileBackups(v int)

SetStdoutLogFileBackups 标准输出的log文件如果达到了最大容量,会自动分包,这个值是设置它的最大分包份数

func (*ProcEntry) SetStdoutLogFileMaxBytes added in v0.0.8

func (that *ProcEntry) SetStdoutLogFileMaxBytes(v string)

SetStdoutLogFileMaxBytes 设置标准输出的log文件最大容量,格式:5KB,10MB,2GB,默认是50MB

func (*ProcEntry) SetStdoutLogfile added in v0.0.8

func (that *ProcEntry) SetStdoutLogfile(v string)

SetStdoutLogfile 设置标准输出的log文件地址

func (*ProcEntry) SetStopAsGroup added in v0.0.8

func (that *ProcEntry) SetStopAsGroup(stopAsGroup bool)

SetStopAsGroup 停止进程的时候,是否向该进程组发送停止信号

func (*ProcEntry) SetStopSignal added in v0.0.8

func (that *ProcEntry) SetStopSignal(stopSignal string)

SetStopSignal 正常结束进程是否需要发送的信号

func (*ProcEntry) SetStopWaitSecs added in v0.0.8

func (that *ProcEntry) SetStopWaitSecs(stopWaitSecs int)

SetStopWaitSecs 发送结束进程的信号后等待的秒数

func (*ProcEntry) SetUser added in v0.0.8

func (that *ProcEntry) SetUser(user string)

SetUser 设置启动进程的用户

func (*ProcEntry) StartRetries added in v0.0.8

func (that *ProcEntry) StartRetries() int

StartRetries 启动失败自动重试次数

func (*ProcEntry) StartSecs added in v0.0.8

func (that *ProcEntry) StartSecs() int

StartSecs 指定启动多少秒后没有异常退出,则表示启动成功

func (*ProcEntry) StderrLogFileBackups added in v0.0.8

func (that *ProcEntry) StderrLogFileBackups(defaultVal int) int

StderrLogFileBackups 标准错误输出的log文件如果达到了最大容量,会自动分包,这个值是设置它的最大分包份数

func (*ProcEntry) StderrLogFileMaxBytes added in v0.0.8

func (that *ProcEntry) StderrLogFileMaxBytes(defaultVal int) int

StderrLogFileMaxBytes 标准错误输出的log文件最大容量,大于这个容量会分包

func (*ProcEntry) StderrLogfile added in v0.0.8

func (that *ProcEntry) StderrLogfile(defaultVal string) string

StderrLogfile 标准错误输出的log文件地址

func (*ProcEntry) StdoutLogFileBackups added in v0.0.8

func (that *ProcEntry) StdoutLogFileBackups(defaultVal int) int

StdoutLogFileBackups 标准输出的log文件如果达到了最大容量,会自动分包,这个值是设置它的最大分包份数

func (*ProcEntry) StdoutLogFileMaxBytes added in v0.0.8

func (that *ProcEntry) StdoutLogFileMaxBytes(defaultVal int) int

StdoutLogFileMaxBytes 标准输出的log文件最大容量,大于这个容量会分包

func (*ProcEntry) StdoutLogfile added in v0.0.8

func (that *ProcEntry) StdoutLogfile(defaultVal string) string

StdoutLogfile 标准输出的log文件地址

func (*ProcEntry) StopAsGroup added in v0.0.8

func (that *ProcEntry) StopAsGroup() bool

StopAsGroup 停止进程的时候,是否向该进程组发送停止信号

func (*ProcEntry) StopSignal added in v0.0.8

func (that *ProcEntry) StopSignal() string

StopSignal 正常结束进程是否需要发送的信号

func (*ProcEntry) StopWaitSecs added in v0.0.8

func (that *ProcEntry) StopWaitSecs(defaultVal int) int

StopWaitSecs 发送结束进程的信号后等待的秒数

func (*ProcEntry) User added in v0.0.8

func (that *ProcEntry) User() string

User 启动进程的用户

type Process

type Process struct {
	// 进程管理对象
	Manager *Manager

	StdoutLog proclog.Logger
	StderrLog proclog.Logger
	// contains filtered or unexported fields
}

func NewProcess

func NewProcess(path string, args []string, environment ...[]string) *Process

NewProcess 创建进程对象

func NewProcessByEntry

func NewProcessByEntry(entry *ProcEntry) *Process

NewProcessByEntry 通过详细配置,创建进程对象

func NewProcessCmd

func NewProcessCmd(cmd string, environment ...[]string) *Process

NewProcessCmd 按命令启动

func (*Process) GetDescription

func (that *Process) GetDescription() string

GetDescription 获取进程描述

func (*Process) GetExitStatus

func (that *Process) GetExitStatus() int

GetExitStatus 获取进程退出状态

func (*Process) GetName

func (that *Process) GetName() string

GetName 获取进程名

func (*Process) GetProcessInfo

func (that *Process) GetProcessInfo() *Info

GetProcessInfo 获取进程的详情

func (*Process) GetStartTime

func (that *Process) GetStartTime() time.Time

GetStartTime 获取进程启动时间

func (*Process) GetState

func (that *Process) GetState() State

GetState 获取进程状态

func (*Process) GetStatus

func (that *Process) GetStatus() string

GetStatus 获取进程当前状态

func (*Process) GetStderrLogfile

func (that *Process) GetStderrLogfile() string

GetStderrLogfile 获取标准错误将要写入的日志文件

func (*Process) GetStdoutLogfile

func (that *Process) GetStdoutLogfile() string

GetStdoutLogfile 获取标准输出将要写入的日志文件

func (*Process) GetStopTime

func (that *Process) GetStopTime() time.Time

GetStopTime 获取进程结束时间

func (*Process) Pid

func (that *Process) Pid() int

Pid 获取进程pid,返回0表示进程未启动

func (*Process) Signal

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

Signal 向进程发送信号 sig: 要发送的信号 sigChildren: 如果为true,则信号会发送到该进程的子进程

func (*Process) Start

func (that *Process) Start(wait bool)

Start 启动进程,wait表示阻塞等待进程启动成功

func (*Process) Stop

func (that *Process) Stop(wait bool)

Stop 主动停止进程

type State

type State int

func (State) String

func (p State) String() string

String 把进程状态转换成可识别的字符串

Jump to

Keyboard shortcuts

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