-
Notifications
You must be signed in to change notification settings - Fork 6
/
service.go
43 lines (37 loc) · 1.62 KB
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Package service provides a simple way to create a system service.
// Currently supports Windows and Linux/Upstart.
package service
// 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 NewService(name, displayName, description string) (Service, error) {
return newService(name, displayName, description)
}
// Represents a generic way to interact with the system's service.
type Service 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
// 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
// Basic log functions in the context of the service.
LogError(format string, a ...interface{}) error
LogWarning(format string, a ...interface{}) error
LogInfo(format string, a ...interface{}) error
}
// Returns the full path of the running executable
// as reported by the system. Includes the executable
// image name.
func GetExePath() (exePath string, err error) {
return getExePath()
}