service

package
v0.0.0-...-9e7e4f5 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2019 License: MPL-2.0, Zlib Imports: 11 Imported by: 0

README

service is a package used within MIG for service management. This includes
tasks such as installing/removing MIG components as OS services, and starting
and stopping services.

This code was originally forked from bitbucket.org/kardianos/service/ to
github.com/jvehent/service-go. Since then the code has been modified for MIG,
and as such now lives here.

Documentation

Overview

Package service provides a simple way to create a system service. Currently supports Windows, Linux/(systemd | Upstart | SysV), and OSX/Launchd.

Index

Constants

View Source
const (
	InitSystemV = initFlavor(iota)
	InitUpstart
	InitSystemd
)

Variables

This section is empty.

Functions

func GetExePath

func GetExePath() (exePath string, err error)

Depreciated. Use osext.Executable instead. Returns the full path of the running executable as reported by the system. Includes the executable image name.

func GetFlavor

func GetFlavor() (initFlavor, error)

the default flavor is InitSystemV. we lookup the command line of process 1 to detect systemd or upstart. This function returns an initFlavor value on success (e.g., InitSystemV) or an error on failure.

Types

type Config

type Config struct {
	Name, DisplayName, Description string

	DarwinIntervalJob bool // Job is an interval job in launchd
	DarwinInterval    int  // Interval to use for interval job

	UserName  string   // Run as username.
	Arguments []string // Run with arguments.

	DependsOn        []string // Other services that this depends on.
	WorkingDirectory string   // Service working directory.
	ChRoot           string
	UserService      bool // Install as a current user service.

	// System specific parameters.
	KV KeyValue
}

Alpha API. Do not yet use.

type Controller

type Controller interface {
	// Starts this service on the system.
	Start() error

	// Stops this service on the system.
	Stop() error
}

A service that implements ServiceController is able to start and stop itself.

type Installer

type Installer interface {
	// Installs this service on the system.  May return an
	// error if this service is already installed.
	Install() error

	// Removes this service from the system.  May return an
	// error if this service is not already installed.
	Remove() error
}

Simple install and remove commands.

type KeyValue

type KeyValue map[string]interface{}

type Logger

type Logger interface {
	// Basic log functions in the context of the service.
	Error(format string, a ...interface{}) error
	Warning(format string, a ...interface{}) error
	Info(format string, a ...interface{}) error
}

A service that implements ServiceLogger can perform simple system logging.

type Parameters

type Parameters interface {
	// Mark as service as an interval type service rather than a
	// persistently running service.
	//
	// XXX Only applicable for Darwin launchd services.
	IntervalMode(int) error
}

Functions that control the parameters applied to a service

type Runner

type Runner interface {
	// Call quickly after initial entry point.  Does not return until
	// service is ready to stop.  onStart is called when the service is
	// starting, returning an error will fail to start the service.
	// If an error is returned from onStop, the service will still stop.
	// An error passed from onStart or onStop will be returned as
	// an error from Run.
	// Both callbacks should return quickly and not block.
	Run(onStart, onStop func() error) error
}

A Generic way to stop and start a service.

type Service

type Service interface {
	Installer
	Controller
	Runner
	Parameters
	Logger
	String() string
}

Represents a generic way to interact with the system's service.

func NewService

func NewService(name, displayName, description string) (Service, error)

Creates a new service. name is the internal name and should not contain spaces. Display name is the pretty print name. The description is an arbitrary string used to describe the service.

func NewServiceConfig

func NewServiceConfig(c *Config) (Service, error)

Alpha API. Do not yet use.

Jump to

Keyboard shortcuts

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