proc

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 16 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 MaskURLPaths added in v0.6.4

func MaskURLPaths(line string) string

MaskURLPaths 把一行输出中网址的路径与查询部分换成 ********,只保留协议与主机。 用于 tailscale up、netbird up 等只会输出登录链接的命令:日志对只读身份可见, 登录链接(含设备码)可用于把本机登记到他人的网络,完整链接只通过需要写权限的状态接口提供。

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 查找可执行文件:优先使用配置的路径,其次是配置目录下的 bin 子目录,最后是 PATH。 bin 放在 PATH 之前:界面中在线安装、更新或回滚的程序都在 bin 下,应当优先生效。 返回绝对路径:子进程可能在其他工作目录启动(如 File Browser),相对路径会按该目录解析而找不到。

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 Managed added in v0.6.5

type Managed struct {
	Module   string    `json:"module"`
	Name     string    `json:"name"`
	Program  string    `json:"program"`
	PID      int       `json:"pid"`
	Since    time.Time `json:"since"`
	Restarts int       `json:"restarts"`
}

Managed 是一个正在运行的托管进程。只包含归属与可执行文件名,不含路径、参数与环境变量: 参数里可能有配置文件路径,环境变量里可能有令牌,这些信息不应出现在只读的概览接口中。

func Running added in v0.6.5

func Running() []Managed

Running 返回当前正在运行的托管进程,按模块、名称、程序排序,结果稳定便于前端展示。

type Spec

type Spec struct {
	Path string
	Args []string
	// Env 追加到当前进程环境变量之后,用于传递令牌等不宜出现在命令行的参数
	Env []string
	Dir string
	// OnLine 在每行输出(已去除颜色码与时间戳)到达时调用,可为 nil
	OnLine func(line string)
	// OnStart 在进程每次成功启动后调用,可为 nil
	OnStart func()
	// LogLine 在写入日志前改写一行输出(如隐藏登录链接),可为 nil;OnLine 收到的仍是原始内容
	LogLine func(line string) string
	// Module 与 Name 标明进程属于哪个模块的哪个实例,用于在概览与性能监控中列出托管进程的资源占用。
	// Name 为空时使用日志来源。只由 Supervisor 使用,一次性命令(Run)不登记。
	Module string
	Name   string
}

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