-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
51 lines (44 loc) · 1.23 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
package service
import (
"time"
)
// Env variables type alias
type Env map[string]string
// Service represents particular service configuration
type Service struct {
Command string `mapstructure:"command"`
UseServiceName bool `mapstructure:"service_name_in_log"`
ProcessNum int `mapstructure:"process_num"`
ExecTimeout time.Duration `mapstructure:"exec_timeout"`
RemainAfterExit bool `mapstructure:"remain_after_exit"`
RestartSec uint64 `mapstructure:"restart_sec"`
TimeoutStopSec uint64 `mapstructure:"timeout_stop_sec"`
Env Env `mapstructure:"env"`
User string `mapstructure:"user"`
}
// Config for the services
type Config struct {
Services map[string]*Service `mapstructure:"service"`
}
func (c *Config) InitDefault() {
if len(c.Services) > 0 {
for k, v := range c.Services {
val := c.Services[k]
c.Services[k] = val
if v.ProcessNum <= 0 {
val := c.Services[k]
val.ProcessNum = 1
c.Services[k] = val
}
if v.RestartSec == 0 {
val := c.Services[k]
val.RestartSec = 30
c.Services[k] = val
}
// default 5 seconds
if v.TimeoutStopSec == 0 {
v.TimeoutStopSec = 5
}
}
}
}