process

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2021 License: Apache-2.0 Imports: 21 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 Entry

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

func NewEntry

func NewEntry(command string, args ...[]string) *Entry

NewEntry 创建进程启动配置

func (*Entry) Args

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

Args 获取参数

func (*Entry) AutoReStart

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

AutoReStart 值为 true,false,unexpected

func (*Entry) AutoStart

func (that *Entry) AutoStart() bool

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

func (*Entry) Command

func (that *Entry) Command() string

Command 获取启动命令

func (*Entry) CreateCommand

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

CreateCommand 根据就配置生成cmd对象

func (*Entry) Directory

func (that *Entry) Directory() string

Directory 程序运行目录

func (*Entry) Environment

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

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

func (*Entry) ExitCodes

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

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

func (*Entry) Extend

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

Extend 获取扩展配置

func (*Entry) KillAsGroup

func (that *Entry) KillAsGroup() bool

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

func (*Entry) KillWaitSecs

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

KillWaitSecs 强杀进程等待秒数

func (*Entry) Name

func (that *Entry) Name() string

Name 获取进程名称

func (*Entry) Priority

func (that *Entry) Priority() int

Priority 进程启动的优先级

func (*Entry) RedirectStderr

func (that *Entry) RedirectStderr() bool

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

func (*Entry) RestartPause

func (that *Entry) RestartPause() int

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

func (*Entry) SetArgs

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

SetArgs 设置参数

func (*Entry) SetAutoReStart

func (that *Entry) SetAutoReStart(val string)

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

func (*Entry) SetAutoStart

func (that *Entry) SetAutoStart(autoStart bool)

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

func (*Entry) SetCommand

func (that *Entry) SetCommand(command string)

SetCommand 设置启动命令

func (*Entry) SetDirectory

func (that *Entry) SetDirectory(directory string)

SetDirectory 设置程序运行目录

func (*Entry) SetEnvironment

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

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

func (*Entry) SetExitCodes

func (that *Entry) SetExitCodes(val string)

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

func (*Entry) SetExtend

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

SetExtend Extend 设置扩展配置信息

func (*Entry) SetKillAsGroup

func (that *Entry) SetKillAsGroup(killAsGroup bool)

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

func (*Entry) SetKillWaitSecs

func (that *Entry) SetKillWaitSecs(killWaitSecs int)

SetKillWaitSecs 强杀进程等待秒数

func (*Entry) SetName

func (that *Entry) SetName(name string)

SetName 设置进程名

func (*Entry) SetPriority

func (that *Entry) SetPriority(priority int)

SetPriority 设置进程启动优先级

func (*Entry) SetRedirectStderr

func (that *Entry) SetRedirectStderr(v bool)

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

func (*Entry) SetRestartPause

func (that *Entry) SetRestartPause(restartPause int)

SetRestartPause 设置进程重启间隔秒数

func (*Entry) SetStartRetries

func (that *Entry) SetStartRetries(startRetries int)

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

func (*Entry) SetStartSecs

func (that *Entry) SetStartSecs(startSecs int)

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

func (*Entry) SetStderrLogFileBackups

func (that *Entry) SetStderrLogFileBackups(v int)

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

func (*Entry) SetStderrLogFileMaxBytes

func (that *Entry) SetStderrLogFileMaxBytes(v string)

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

func (*Entry) SetStderrLogfile

func (that *Entry) SetStderrLogfile(v string)

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

func (*Entry) SetStdoutLogFileBackups

func (that *Entry) SetStdoutLogFileBackups(v int)

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

func (*Entry) SetStdoutLogFileMaxBytes

func (that *Entry) SetStdoutLogFileMaxBytes(v string)

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

func (*Entry) SetStdoutLogfile

func (that *Entry) SetStdoutLogfile(v string)

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

func (*Entry) SetStopAsGroup

func (that *Entry) SetStopAsGroup(stopAsGroup bool)

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

func (*Entry) SetStopSignal

func (that *Entry) SetStopSignal(stopSignal string)

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

func (*Entry) SetStopWaitSecs

func (that *Entry) SetStopWaitSecs(stopWaitSecs int)

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

func (*Entry) SetUser

func (that *Entry) SetUser(user string)

SetUser 设置启动进程的用户

func (*Entry) StartRetries

func (that *Entry) StartRetries() int

StartRetries 启动失败自动重试次数

func (*Entry) StartSecs

func (that *Entry) StartSecs() int

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

func (*Entry) StderrLogFileBackups

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

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

func (*Entry) StderrLogFileMaxBytes

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

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

func (*Entry) StderrLogfile

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

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

func (*Entry) StdoutLogFileBackups

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

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

func (*Entry) StdoutLogFileMaxBytes

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

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

func (*Entry) StdoutLogfile

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

StdoutLogfile 标准输出的log文件地址

func (*Entry) StopAsGroup

func (that *Entry) StopAsGroup() bool

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

func (*Entry) StopSignal

func (that *Entry) StopSignal() string

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

func (*Entry) StopWaitSecs

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

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

func (*Entry) User

func (that *Entry) User() string

User 启动进程的用户

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 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 *Entry) *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