service

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 11 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 把 Gately 注册为系统服务,实现开机自启与异常退出后自动拉起: Linux 使用 systemd,macOS 使用 launchd,Windows 使用服务控制管理器(SCM)。 入口是命令 gately service install|uninstall|start|stop|restart|status。

Index

Constants

View Source
const (
	// Name 是服务名:systemd 单元名、Windows 服务名
	Name = "gately"
	// Label 是 macOS launchd 的标识
	Label = "cn.gately.gately"
)

Variables

This section is empty.

Functions

func DefaultConfigDir

func DefaultConfigDir(user bool) string

DefaultConfigDir 返回服务模式下默认的配置目录,与 deploy/systemd 的约定一致。

func IsWindowsService

func IsWindowsService() bool

IsWindowsService 在 Windows 以外的系统上恒为 false。

func Run

func Run(args []string, out io.Writer) int

Run 实现 gately service 子命令,返回进程退出码。

func RunAsWindowsService

func RunAsWindowsService(run func(ctx context.Context)) int

RunAsWindowsService 在 Windows 以外的系统上不会被调用。

Types

type Spec

type Spec struct {
	// Exe 是 Gately 可执行文件的绝对路径,服务直接引用它,在线升级替换该文件即可
	Exe string
	// ConfigDir 是配置目录的绝对路径
	ConfigDir string
	// Listen 非空时作为 -listen 参数传给服务
	Listen string
	// User 表示 macOS 上注册为当前用户的登录项(LaunchAgent),默认注册为开机启动的系统服务(LaunchDaemon)
	User bool
	// NoStart 表示只注册,不立即启动
	NoStart bool
}

Spec 描述要注册的服务。

Jump to

Keyboard shortcuts

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