svc

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2022 License: GPL-3.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(name string, f Handler) error

Run executes service name by calling the appropriate handler function.

This function will block until complete. Any errors returned indicate that bootstrappping of the service failed.

Types

type Accepted

type Accepted uint32

Accepted is used to describe commands accepted by the service.

Interrogate is always accepted.

const (
	AcceptStop Accepted = 1 << iota
	AcceptPauseAndContinue
	AcceptShutdown
	AcceptParamChange
	AcceptNetBindChange
	AcceptHardwareProfileChange
	AcceptPowerEvent
	AcceptSessionChange
	AcceptPreShutdown
)

Standard Windows Service Accepted values

DO NOT REORDER

type Change

type Change struct {
	Command   Command
	EventType uint32
	EventData uintptr
	Status    Status
	Context   uintptr
}

Change is sent to the service Handler to request service status changes and updates to the service control manager.

type Command

type Command uint32

Command represents a service state change request. It is sent to a service by the service manager, and should be acted upon by the service.

const (
	Stop Command = 1 + iota
	Pause
	Continue
	Interrogate
	Shutdown
	ParamChange
	NetBindAdd
	NetBindRemove
	NetBindEnable
	NetBindDisable
	DeviceEvent
	HardwareProfileChange
	PowerEvent
	SessionChange
	PreShutdown
)

Standard Windows Service Command values

DO NOT REORDER

type Handler

type Handler func(context.Context, Service, []string) uint32

Handler is a function interface that must be implemented to run as a Windows service.

This function will be called by the package code at the start of the service, and the service will exit once Execute completes.

Inside the function, you may use the context or read service change requests using the 's.Requests()' channel and act accordingly.

You must keep service control manager up to date about state of your service by using the 'Update' or 'UpdateState' functions.

The supplied string list contains the service name followed by argument strings passed to the service.

You can provide service exit code in the return parameter, with 0 being "no error".

type Reason

type Reason uint32

Reason is the reason that the service was started.

const (
	ReasonDemand Reason = 1 << iota
	ReasonAuto
	ReasonTrigger
	ReasonRestartOnFailure
	ReasonDelayedAuto
)

Standard Windows Service Reason values

DO NOT REORDER

type Service

type Service interface {
	Update(Status)
	Handle() uintptr
	Requests() <-chan Change
	UpdateState(State, ...Accepted)
	DynamicStartReason() (Reason, error)
}

Service is an interface that is passed to the Handler function and can be used to receive and send updates to the service control manager.

NOTE(dij): The function 'DynamicStartReason' is only avaliable on Windows >7 and will return an error if it does not exist.

type State

type State uint32

State describes the current service execution state (Stopped, Running, etc.)

const (
	Stopped State = 1 + iota
	StartPending
	StopPending
	Running
	ContinuePending
	PausePending
	Paused
)

Standard Windows Service State values

DO NOT REORDER

type Status

type Status struct {
	State      State
	Accepts    Accepted
	CheckPoint uint32
	WaitHint   uint32
	ProcessID  uint32
	ExitCode   uint32
}

Status combines State and Accepted commands to fully describe running service.

Jump to

Keyboard shortcuts

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