proc

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package proc 托管外部可执行文件(frpc、cloudflared、tailscaled 等): 查找二进制、后台运行、异常退出自动重启、把输出写入模块日志。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean(line string) string

Clean 去除颜色码、回车与行首时间戳。

func Output

func Output(timeout time.Duration, path string, args, env []string) ([]byte, error)

Output 运行命令并返回合并后的输出,超时后强制结束。

func Resolve

func Resolve(configured, configDir string, names ...string) (string, error)

Resolve 查找可执行文件:优先使用配置的路径,其次 PATH,最后是配置目录下的 bin 子目录。

func Run

func Run(ctx context.Context, spec Spec, log *logbuf.Logger) error

Run 运行一次命令并把输出写入日志,进程退出后返回。ctx 取消时先发送终止信号。

func Version

func Version(path string, args ...string) string

Version 返回 `<path> <args...>` 输出的第一行,失败时返回空串。

Types

type Spec

type Spec struct {
	Path string
	Args []string
	// Env 追加到当前进程环境变量之后,用于传递令牌等不宜出现在命令行的参数
	Env []string
	Dir string
	// OnLine 在每行输出(已去除颜色码与时间戳)到达时调用,可为 nil
	OnLine func(line string)
	// OnStart 在进程每次成功启动后调用,可为 nil
	OnStart func()
}

Spec 描述要运行的进程。

type State

type State struct {
	Running  bool      `json:"running"`
	PID      int       `json:"pid,omitempty"`
	Since    time.Time `json:"since,omitempty"`
	Restarts int       `json:"restarts"`
	// LastExit 记录最近一次退出原因
	LastExit string `json:"lastExit,omitempty"`
	// Error 非空表示无法启动(例如二进制不存在),不会自动重试
	Error string `json:"error,omitempty"`
}

State 是进程运行状态。

type Supervisor

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

Supervisor 托管一个长期运行的进程。

func New

func New(log *logbuf.Logger) *Supervisor

New 创建托管器,log 接收进程输出与托管事件。

func (*Supervisor) Start

func (s *Supervisor) Start(spec Spec)

Start 启动进程;已在运行时先停止旧进程。

func (*Supervisor) State

func (s *Supervisor) State() State

State 返回当前状态快照。

func (*Supervisor) Stop

func (s *Supervisor) Stop()

Stop 停止进程并等待其退出,未运行时无操作。

Jump to

Keyboard shortcuts

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