xrayproc

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package xrayproc 托管 xray-core 子进程:启动/停止/配置校验重启/看门狗拉起。 结论依据《知识状态清单》A 类实测:SIGTERM 优雅退出(exit 0)、SIGKILL(137)、 `-test` 配置错误 exit 23、启动失败 exit 255、watchdog 2s 拉起。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureBootstrapConfig

func EnsureBootstrapConfig(configPath string) (bool, error)

EnsureBootstrapConfig 配置缺失时落盘自举最小模板,返回是否实际写入。 只在文件不存在时写入,绝不覆盖已有配置;首个 push_config 到达后 RestartWithConfig 原子替换,本模板天然充当"上一份好配置"的回滚兜底(-test 失败时回滚到的就是它, xray 至少保持最小配置运行、gRPC 可连,而不是裸死)。

Types

type Proc

type Proc struct {
	Bin        string
	ConfigPath string
	LogPath    string
	PidFile    string

	OnRestart func() // 崩溃后被 Watchdog 成功拉起时的回调
	// contains filtered or unexported fields
}

Proc 管理单个 xray 实例。

func New

func New(bin, configPath, logPath, pidFile string) *Proc

New 构造托管器。

func (*Proc) CleanupStale

func (p *Proc) CleanupStale()

CleanupStale 停止同配置路径的残留 xray 实例(agent 异常退出遗留的孤儿进程)。

func (*Proc) IsRunning

func (p *Proc) IsRunning() bool

IsRunning 通过 pid 文件 + isProcessAlive 判断进程存活;僵尸(Z)视为不在运行。

func (*Proc) Logs

func (p *Proc) Logs(n int) (string, error)

Logs 读取最近 n 行日志。

func (*Proc) RestartWithConfig

func (p *Proc) RestartWithConfig(configJSON string) error

RestartWithConfig 写配置 → 校验 → 重启。

func (*Proc) Start

func (p *Proc) Start() error

Start 启动 xray 子进程(配置已存在时使用)。

func (*Proc) Status

func (p *Proc) Status() (running bool, pid int, startedAt time.Time, uptimeSec int64)

Status 返回运行状态。

func (*Proc) Stop

func (p *Proc) Stop() error

Stop 停止 xray(SIGTERM 优雅退出,超时后 SIGKILL)。

func (*Proc) TestConfig

func (p *Proc) TestConfig(path string) error

TestConfig 用 `xray -test` 校验配置(exit 0 = 通过)。

func (*Proc) Watchdog

func (p *Proc) Watchdog(stop <-chan struct{})

Watchdog 崩溃自动拉起(每 2s 检测)。

Jump to

Keyboard shortcuts

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