service

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package service 提供 Windows 服务生命周期实现与控制命令。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetServiceStatus

func GetServiceStatus(name string) (svc.State, error)

GetServiceStatus 获取服务当前状态。

func Install

func Install(name, displayName, description string) error

Install 以默认选项安装服务。

func InstallWithOptions

func InstallWithOptions(name, displayName, description string, opts InstallOptions) error

InstallWithOptions 按选项安装服务并配置崩溃恢复。

func IsServiceExist

func IsServiceExist(name string) (bool, error)

IsServiceExist 检查服务是否存在;连接失败返回错误而非误报不存在。

func Restart

func Restart(name string) error

Restart 重启服务(未运行时直接启动)。

func Run

func Run(name string)

Run 以 Windows 服务模式运行。

func RunWithHook added in v0.13.0

func RunWithHook(name string, h TraceHook)

RunWithHook 以服务模式运行并注入链路追踪钩子。

func SetStopTimeout

func SetStopTimeout(d time.Duration) error

SetStopTimeout 设置停止等待超时(必须大于 0)。

func Start

func Start(name string) error

Start 启动服务。

func Stop

func Stop(name string) error

Stop 停止服务并等待其完全停止。

func Uninstall

func Uninstall(name string) error

Uninstall 卸载服务。

Types

type InstallOptions

type InstallOptions struct {
	// StartType 启动类型(mgr.Start* 常量),0 使用自动启动。
	StartType uint32
	// RecoveryActions 崩溃恢复动作,nil 使用默认三次重启。
	RecoveryActions []mgr.RecoveryAction
	// RecoveryResetPeriod 恢复计数重置秒数,0 使用 60。
	RecoveryResetPeriod uint32
	// EventLogTypes 事件日志类别,0 使用错误+警告+信息。
	EventLogTypes uint32
}

InstallOptions 安装服务选项。

func DefaultInstallOptions

func DefaultInstallOptions() InstallOptions

DefaultInstallOptions 返回默认安装选项。

type Service

type Service struct {
	// StopFlag 标记服务是否收到停止命令。
	StopFlag bool
	// Name 服务名(RunWithHook 注入,用于链路属性)。
	Name string
	// TraceHook 链路追踪钩子(可选)。
	TraceHook TraceHook
}

Service 实现 svc.Handler 接口。

func (*Service) Execute

func (s *Service) Execute(_ []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32)

Execute 处理服务状态变化与业务启动/停止。

type TraceAttr added in v0.13.0

type TraceAttr = contract.TraceAttr

TraceAttr 链路追踪属性(家族统一契约,定义见 tracex/contract)。

type TraceHook added in v0.13.0

type TraceHook = contract.TraceHook

TraceHook 链路追踪钩子(家族统一契约,定义见 tracex/contract)。

Jump to

Keyboard shortcuts

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