-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
101 lines (82 loc) · 1.71 KB
/
config.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
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
package main
import (
"github.com/BurntSushi/toml"
"github.com/google/shlex"
)
var (
defaultStartupScript = &StartupScript{
cmd: "/sbin/agetty",
args: []string{
"-L",
"-8",
"--autologin",
"root",
"115200",
"tty1",
"linux",
},
}
)
type StartupScript struct {
cmd string
args []string
}
func (s *StartupScript) UnmarshalText(text []byte) (err error) {
if len(text) == 0 {
*s = *defaultStartupScript
return
}
ss, err := shlex.Split(string(text))
if err != nil {
return
}
switch len(ss) {
case 0:
*s = *defaultStartupScript
case 1:
s.cmd = ss[0]
default:
s.cmd = ss[0]
s.args = ss[1:]
}
return
}
type Config struct {
Groups []string `toml:"groups"`
GroupOverrides map[string][]string `toml:"group_overrides"`
StartupScript *StartupScript `toml:"startup_script"`
}
func LoadConfig(fn string) (c Config, err error) {
_, err = toml.DecodeFile(fn, &c)
if err != nil {
return
}
if c.StartupScript == nil {
c.StartupScript = defaultStartupScript
}
return
}
// HasOverride returns an optional 'override group' for a service.
//
// An override group is a local configuration option which allows the owner
// of a system to override which group a service belongs to, even (effectively)
// creating a brand new group and moving services into it.
//
// This allows users to tweak the order in which boot
func (c Config) ReconcileOverride(svc, initialGroup string) (group string) {
var members []string
for group, members = range c.GroupOverrides {
if contains(members, svc) {
return
}
}
return initialGroup
}
func contains(ss []string, s string) bool {
for _, elem := range ss {
if elem == s {
return true
}
}
return false
}