supervisor

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package supervisor 管理本项目的服务进程、控制通道和监听资源。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attach added in v0.1.1

func Attach(ctx context.Context, socket string, specs map[string]Spec, output *Display) (bool, error)

Attach transfers local terminal ownership after the requested services are ready. Closing the current owner stops the manager; closing a replaced owner has no effect.

func ConfigureHorizon

func ConfigureHorizon()

ConfigureHorizon 通过公开扩展接口限定本代服务的停机范围,队列和监控数据仍由原 Store 管理。

func Frontend

func Frontend(ctx context.Context, spec Spec) error

Frontend 与 Go 服务使用同样的子进程回收逻辑,由外层管理器决定是否重启。

func Parse

func Parse(selection, action string) ([]string, error)

Parse 供 CLI 和本地控制通道共用同一套服务选择规则。

func Pending added in v0.1.3

func Pending(message string) error

Pending 报告外部依赖准备中,管理器保留进程并继续接收就绪通知。

func Ready

func Ready() error

Ready 通过父进程提供的管道报告本服务已经就绪。

func ReportRuntime added in v0.1.3

func ReportRuntime(ctx context.Context, socket string)

ReportRuntime 向项目的本地控制通道上报当前Go进程的协程数,随context退出。

func Run

func Run(ctx context.Context, socket string, specs map[string]Spec, names []string, watch bool, display *Display) error

Run 持有排他锁和本地控制入口,直到收到停止命令或应用退出信号。

func Terminal added in v0.1.1

func Terminal(ctx context.Context, socket string, launcher Spec, specs map[string]Spec, output *Display) (result error)

Terminal starts an independent local manager when absent, then owns its control connection.

func Wait added in v0.1.3

func Wait(ctx context.Context, check func(context.Context) error) error

Wait 在依赖尚未就绪时保持进程和控制通道存活,恢复后继续启动。

func Watch added in v0.1.1

func Watch(ctx context.Context, directory, runtime string, output io.Writer, reload func(string) error) error

Watch 监听应用及本地模块源码,编译成功后更新运行中的 Go 服务。

func WatchParent

func WatchParent(ctx context.Context, shutdown func(error)) (func(), error)

WatchParent 在管理器异常消失时通知当前 Application 收尾。

Types

type Display added in v0.1.3

type Display struct {
	Out         io.Writer
	Options     console.OutputOptions
	Locale      string
	Environment string
	JSON        bool
	Log         string
	// contains filtered or unexported fields
}

Display 是Dawn命令共用的终端输出,串行写入状态表与服务日志。

func NewDisplay added in v0.1.3

func NewDisplay(output console.IO, locale string, json bool) *Display

NewDisplay 复用Console的输出目标、语言和终端选项。

func (*Display) Buffer added in v0.1.3

func (d *Display) Buffer()

func (*Display) Flush added in v0.1.3

func (d *Display) Flush()

func (*Display) Heading added in v0.1.3

func (d *Display) Heading(title string)

Heading 与 Result 供安装、模型检查和GeoIP等维护命令共用。

func (*Display) Render added in v0.1.3

func (d *Display) Render(title string, response Response)

func (*Display) Result added in v0.1.3

func (d *Display) Result(start time.Time, err error)

func (*Display) Write added in v0.1.3

func (d *Display) Write(p []byte) (int, error)

type ProcessStats added in v0.1.3

type ProcessStats struct {
	Name       string         `json:"name"`
	PID        int            `json:"pid"`
	User       string         `json:"user"`
	RSS        *uint64        `json:"rss_bytes,omitempty"`
	CPU        *float64       `json:"cpu_percent,omitempty"`
	Threads    *int32         `json:"threads,omitempty"`
	Goroutines *int           `json:"goroutines,omitempty"`
	StartedAt  int64          `json:"started_at"`
	Children   []ProcessStats `json:"children,omitempty"`
}

ProcessStats 是操作系统采样的进程指标;不可用的指标省略。

type Response

type Response struct {
	PID         int          `json:"pid"`
	TerminalPID int          `json:"terminal_pid,omitempty"`
	Replaced    bool         `json:"replaced,omitempty"`
	Services    []Status     `json:"services"`
	Error       string       `json:"error,omitempty"`
	Manager     ProcessStats `json:"manager"`
}

func Control

func Control(ctx context.Context, socket, selection, action string) (Response, bool, error)

Control 向已经运行的本地管理器提交操作并等待结果。

type RuntimeStats added in v0.1.3

type RuntimeStats struct {
	PID        int `json:"pid"`
	Goroutines int `json:"goroutines"`
}

RuntimeStats 是Go进程通过本地控制通道上报的运行时指标。

type Spec

type Spec struct {
	Command             []string
	Dir, Address, Probe string
	URL                 string
	Env                 []string
	Timeout             time.Duration
	JoinGroup           bool
}

Spec 声明服务的执行入口;Address 用于继承监听器,Probe 用于前端就绪检查。

type Status

type Status struct {
	Name      string        `json:"name"`
	State     string        `json:"state"`
	Wanted    bool          `json:"wanted"`
	PID       int           `json:"pid"`
	Restarts  int           `json:"restarts"`
	StartedAt int64         `json:"started_at"`
	LastError string        `json:"last_error,omitempty"`
	Address   string        `json:"address,omitempty"`
	Process   *ProcessStats `json:"process,omitempty"`
}

Jump to

Keyboard shortcuts

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