Files
yms-daemon/internal/systemd/manager.go
T

36 lines
1.0 KiB
Go
Raw Normal View History

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