Documentation
¶
Overview ¶
Package service 提供 Windows 服务生命周期实现与控制命令。
Index ¶
- func GetServiceStatus(name string) (svc.State, error)
- func Install(name, displayName, description string) error
- func InstallWithOptions(name, displayName, description string, opts InstallOptions) error
- func IsServiceExist(name string) (bool, error)
- func Restart(name string) error
- func Run(name string)
- func RunWithHook(name string, h TraceHook)
- func SetStopTimeout(d time.Duration) error
- func Start(name string) error
- func Stop(name string) error
- func Uninstall(name string) error
- type InstallOptions
- type Service
- type TraceAttr
- type TraceHook
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetServiceStatus ¶
GetServiceStatus 获取服务当前状态。
func InstallWithOptions ¶
func InstallWithOptions(name, displayName, description string, opts InstallOptions) error
InstallWithOptions 按选项安装服务并配置崩溃恢复。
func IsServiceExist ¶
IsServiceExist 检查服务是否存在;连接失败返回错误而非误报不存在。
func RunWithHook ¶ added in v0.13.0
RunWithHook 以服务模式运行并注入链路追踪钩子。
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 接口。
Click to show internal directories.
Click to hide internal directories.