service

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: GPL-3.0 Imports: 13 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 service 把 `sctl serve` 注册为当前用户的系统服务:macOS launchd LaunchAgent、Linux systemd 用户单元、Windows 登录触发的计划任务。sctl 只生成定义并调用系统自带的管理命令,守护由服务管理器负责。

Index

Constants

This section is empty.

Variables

View Source
var ErrNotInstalled = errors.New("the sctl service is not installed; run `sctl service install` first")

ErrNotInstalled 表示当前用户还没有安装 sctl 服务。

Functions

func ResolveExecutable

func ResolveExecutable() (string, error)

ResolveExecutable 返回服务应固化的 sctl 路径。

Types

type Manager

type Manager interface {
	// Location 是服务定义所在的位置(文件路径或计划任务名),用于给用户展示。
	Location() string
	// Installed 报告服务定义是否存在。
	Installed(ctx context.Context) (bool, error)
	// Enabled 报告服务是否在登录时启动。被禁用的服务也不能手动启动(launchd 与任务计划程序如此),
	// 调用方在 start / restart 前检查它。
	Enabled(ctx context.Context) (bool, error)
	// Install 写入(或覆盖)服务定义,启用登录自启并立即(重新)启动。
	Install(ctx context.Context, p Program) error
	// Uninstall 停止服务并删除定义;existed 为 false 表示本来就没装。
	Uninstall(ctx context.Context) (existed bool, err error)
	Start(ctx context.Context) error
	// Stop 停止正在运行的服务,登录自启不变。
	Stop(ctx context.Context) error
	Restart(ctx context.Context) error
	// Enable / Disable 只切换登录自启,不启停服务。
	Enable(ctx context.Context) error
	Disable(ctx context.Context) error
}

Manager 管理当前用户名下唯一的 sctl 服务。

func New

func New() (Manager, error)

New 返回当前操作系统的 Manager;不支持的系统返回错误。

type Program

type Program struct {
	Executable string
	Args       []string
	// LogDir 收服务管理器接住的 stderr(目前只有 launchd 需要文件路径)。
	LogDir string
}

Program 是服务要运行的命令行。Executable 必须是绝对路径:服务管理器不继承用户 shell 的 PATH。

type Runner

type Runner interface {
	Run(ctx context.Context, name string, args ...string) ([]byte, error)
}

Runner 执行一条外部命令并返回合并后的输出。

Jump to

Keyboard shortcuts

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