2026-08-17 10:10:14 +08:00
|
|
|
|
// Package systemd 定义原生执行器所依赖的精确 systemd 边界。
|
|
|
|
|
|
//
|
|
|
|
|
|
// 该包声明 systemd 操作所需的最小抽象,具体实现见 systemctl.go,
|
|
|
|
|
|
// 它直接调用 systemctl 可执行文件,绝不经过 shell。
|
2026-08-16 01:27:30 +08:00
|
|
|
|
package systemd
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
"errors"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2026-08-17 10:10:14 +08:00
|
|
|
|
// ErrUnitNotFound 表示未找到指定的 systemd 单元。
|
2026-08-16 01:27:30 +08:00
|
|
|
|
var ErrUnitNotFound = errors.New("systemd unit not found")
|
|
|
|
|
|
|
2026-08-17 10:10:14 +08:00
|
|
|
|
// Unit 执行幂等启停检查所需的 systemd 状态。
|
2026-08-16 01:27:30 +08:00
|
|
|
|
type Unit struct {
|
2026-08-17 10:10:14 +08:00
|
|
|
|
// Name 表示单元名称。
|
|
|
|
|
|
Name string
|
|
|
|
|
|
// LoadState 表示单元的加载状态。
|
|
|
|
|
|
LoadState string
|
|
|
|
|
|
// ActiveState 表示单元的活动状态。
|
2026-08-16 01:27:30 +08:00
|
|
|
|
ActiveState string
|
2026-08-17 10:10:14 +08:00
|
|
|
|
// SubState 表示单元的子状态。
|
|
|
|
|
|
SubState string
|
2026-08-16 01:27:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-17 10:10:14 +08:00
|
|
|
|
// Manager 在不调用 shell 的前提下直接执行 systemd 操作。
|
2026-08-16 01:27:30 +08:00
|
|
|
|
type Manager interface {
|
2026-08-17 10:10:14 +08:00
|
|
|
|
// Inspect 检查指定单元并返回其状态。
|
2026-08-16 01:27:30 +08:00
|
|
|
|
Inspect(context.Context, string) (Unit, error)
|
2026-08-17 10:10:14 +08:00
|
|
|
|
// Start 启动指定单元。
|
2026-08-16 01:27:30 +08:00
|
|
|
|
Start(context.Context, string) error
|
2026-08-17 10:10:14 +08:00
|
|
|
|
// Stop 停止指定单元。
|
2026-08-16 01:27:30 +08:00
|
|
|
|
Stop(context.Context, string) error
|
|
|
|
|
|
}
|