-
Notifications
You must be signed in to change notification settings - Fork 13
/
daemon.go
75 lines (56 loc) · 1.8 KB
/
daemon.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package daemon
import "strings"
// Status constants.
const (
statNotInstalled = "Service not installed"
)
// Daemon interface has a standard set of methods/commands
type Daemon interface {
// GetTemplate - gets service config template
GetTemplate() string
// SetTemplate - sets service config template
SetTemplate(string) error
// Install the service into the system
Install(args ...string) (string, error)
// Update the service definition on the system
Update(args ...string) (string, error)
// Remove the service and all corresponding files from the system
Remove() (string, error)
// Start the service
Start() (string, error)
// Stop the service
Stop() (string, error)
// Status - check the service status
Status() (string, error)
// Enable - sets the service to persist reboots
Enable() (string, error)
// Logs - gets the service logs
Logs() (string, error)
// Run - run executable service
Run(e Executable) (string, error)
// SetEnvFile - sets the environment file argument for generating the agent command
SetEnvFile(string) error
// SetUser - sets the user that executes the service
SetUser(string) error
// setGroup - sets the group that executes the service
SetGroup(string) error
// GetServiceName - gets the name of the service
GetServiceName() string
}
// Executable interface defines controlling methods of executable service
type Executable interface {
// Start - non-blocking start service
Start()
// Stop - non-blocking stop service
Stop()
// Run - blocking run service
Run()
}
// New - Create a new daemon
//
// name: name of the service
//
// description: any explanation, what is the service, its purpose
func New(name, description string, dependencies ...string) (Daemon, error) {
return newDaemon(strings.Join(strings.Fields(name), "_"), description, dependencies)
}