forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplan.go
More file actions
120 lines (100 loc) · 4 KB
/
Copy pathplan.go
File metadata and controls
120 lines (100 loc) · 4 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2023 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package plan
type Layer struct {
Order int `yaml:"-"`
Label string `yaml:"-"`
Summary string `yaml:"summary,omitempty"`
Description string `yaml:"description,omitempty"`
Services map[string]*Service `yaml:"services,omitempty"`
Checks map[string]*Check `yaml:"checks,omitempty"`
}
type Service struct {
// Basic details
Name string `yaml:"-"`
Summary string `yaml:"summary,omitempty"`
Description string `yaml:"description,omitempty"`
Startup ServiceStartup `yaml:"startup,omitempty"`
Override Override `yaml:"override,omitempty"`
Command string `yaml:"command,omitempty"`
// Service dependencies
After []string `yaml:"after,omitempty"`
Before []string `yaml:"before,omitempty"`
Requires []string `yaml:"requires,omitempty"`
// Options for command execution
Environment map[string]string `yaml:"environment,omitempty"`
UserID *int `yaml:"user-id,omitempty"`
User string `yaml:"user,omitempty"`
GroupID *int `yaml:"group-id,omitempty"`
Group string `yaml:"group,omitempty"`
// Auto-restart and backoff functionality
KillDelay OptionalDuration `yaml:"kill-delay,omitempty"`
OnSuccess ServiceAction `yaml:"on-success,omitempty"`
OnFailure ServiceAction `yaml:"on-failure,omitempty"`
OnCheckFailure map[string]ServiceAction `yaml:"on-check-failure,omitempty"`
BackoffDelay OptionalDuration `yaml:"backoff-delay,omitempty"`
BackoffFactor OptionalFloat `yaml:"backoff-factor,omitempty"`
BackoffLimit OptionalDuration `yaml:"backoff-limit,omitempty"`
}
type ServiceStartup string
const (
StartupUnknown ServiceStartup = ""
StartupEnabled ServiceStartup = "enabled"
StartupDisabled ServiceStartup = "disabled"
)
// Override specifies the layer override mechanism (for services and checks).
type Override string
const (
UnknownOverride Override = ""
MergeOverride Override = "merge"
ReplaceOverride Override = "replace"
)
type ServiceAction string
const (
ActionUnset ServiceAction = ""
ActionRestart ServiceAction = "restart"
ActionShutdown ServiceAction = "shutdown"
ActionIgnore ServiceAction = "ignore"
)
// Check specifies configuration for a single health check.
type Check struct {
// Basic details
Name string `yaml:"-"`
Override Override `yaml:"override,omitempty"`
Level CheckLevel `yaml:"level,omitempty"`
// Common check settings
Period OptionalDuration `yaml:"period,omitempty"`
Timeout OptionalDuration `yaml:"timeout,omitempty"`
Threshold int `yaml:"threshold,omitempty"`
// Type-specific check settings (only one of these can be set)
HTTP *HTTPCheck `yaml:"http,omitempty"`
TCP *TCPCheck `yaml:"tcp,omitempty"`
Exec *ExecCheck `yaml:"exec,omitempty"`
}
// CheckLevel specifies the optional check level.
type CheckLevel string
const (
UnsetLevel CheckLevel = ""
AliveLevel CheckLevel = "alive"
ReadyLevel CheckLevel = "ready"
)
// HTTPCheck holds the configuration for an HTTP health check.
type HTTPCheck struct {
URL string `yaml:"url,omitempty"`
Headers map[string]string `yaml:"headers,omitempty"`
}
// TCPCheck holds the configuration for an HTTP health check.
type TCPCheck struct {
Port int `yaml:"port,omitempty"`
Host string `yaml:"host,omitempty"`
}
// ExecCheck holds the configuration for an exec health check.
type ExecCheck struct {
Command string `yaml:"command,omitempty"`
Environment map[string]string `yaml:"environment,omitempty"`
UserID *int `yaml:"user-id,omitempty"`
User string `yaml:"user,omitempty"`
GroupID *int `yaml:"group-id,omitempty"`
Group string `yaml:"group,omitempty"`
WorkingDir string `yaml:"working-dir,omitempty"`
}