svc

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2019 License: MIT Imports: 4 Imported by: 3

Documentation

Overview

Package svc helps you write Windows Service executables without getting in the way of other target platforms.

To get started, implement the Init, Start, and Stop methods to do any work needed during these steps.

Init and Start cannot block. Launch long-running code in a new Goroutine.

Stop may block for a short amount of time to attempt clean shutdown.

Call svc.Run() with a reference to your svc.Service implementation to start your program.

When running in console mode Ctrl+C is treated like a Stop Service signal.

For a full guide visit https://github.com/judwhite/go-svc

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Notify added in v1.1.3

func Notify(sig os.Signal, receive SignalReceive) error

Notify register signal to receive specify receive func implement by yourself

func Run

func Run(service Service, sig ...os.Signal) error

Run runs your Service.

Run will block until one of the signals specified in sig is received. If sig is empty syscall.SIGINT and syscall.SIGTERM are used by default.

Types

type Environment

type Environment interface {
	// IsWindowsService reports whether the program is running as a Windows Service.
	IsWindowsService() bool
}

Environment contains information about the environment your application is running in.

type Service

type Service interface {
	// Init is called before the program/service is started and after it's
	// determined if the program is running as a Windows Service. This method must
	// be non-blocking.
	Init(Environment) error

	// Start is called after Init. This method must be non-blocking.
	Start() error

	// Stop is called in response to syscall.SIGINT, syscall.SIGTERM, or when a
	// Windows Service is stopped.
	Stop() error
}

Service interface contains Start and Stop methods which are called when the service is started and stopped. The Init method is called before the service is started, and after it's determined if the program is running as a Windows Service.

The Start and Init methods must be non-blocking.

Implement this interface and pass it to the Run function to start your program.

type SignalReceive added in v1.1.3

type SignalReceive func(signal os.Signal)

SignalReceive signal information to process implement case by case

Jump to

Keyboard shortcuts

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