2020-11-30 09:37:17 +00:00
|
|
|
package csconfig
|
|
|
|
|
2021-03-24 17:16:17 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
2020-11-30 09:37:17 +00:00
|
|
|
|
|
|
|
/*daemonization/service related stuff*/
|
|
|
|
type CommonCfg struct {
|
2022-06-17 14:12:49 +00:00
|
|
|
Daemonize bool
|
|
|
|
PidDir string `yaml:"pid_dir,omitempty"` // TODO: This is just for backward compat. Remove this later
|
|
|
|
LogMedia string `yaml:"log_media"`
|
|
|
|
LogDir string `yaml:"log_dir,omitempty"` //if LogMedia = file
|
|
|
|
LogLevel *log.Level `yaml:"log_level"`
|
2023-11-24 14:57:32 +00:00
|
|
|
WorkingDir string `yaml:"working_dir,omitempty"` // TODO: This is just for backward compat. Remove this later
|
2022-06-17 14:12:49 +00:00
|
|
|
CompressLogs *bool `yaml:"compress_logs,omitempty"`
|
|
|
|
LogMaxSize int `yaml:"log_max_size,omitempty"`
|
|
|
|
LogMaxAge int `yaml:"log_max_age,omitempty"`
|
|
|
|
LogMaxFiles int `yaml:"log_max_files,omitempty"`
|
|
|
|
ForceColorLogs bool `yaml:"force_color_logs,omitempty"`
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
2021-03-24 17:16:17 +00:00
|
|
|
|
2023-11-24 14:57:32 +00:00
|
|
|
func (c *Config) loadCommon() error {
|
2021-03-24 17:16:17 +00:00
|
|
|
var err error
|
|
|
|
if c.Common == nil {
|
2023-11-24 14:57:32 +00:00
|
|
|
c.Common = &CommonCfg{}
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Common.LogMedia == "" {
|
|
|
|
c.Common.LogMedia = "stdout"
|
2021-03-24 17:16:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var CommonCleanup = []*string{
|
|
|
|
&c.Common.LogDir,
|
|
|
|
}
|
|
|
|
for _, k := range CommonCleanup {
|
|
|
|
if *k == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
*k, err = filepath.Abs(*k)
|
|
|
|
if err != nil {
|
2023-06-23 12:04:58 +00:00
|
|
|
return fmt.Errorf("failed to get absolute path of '%s': %w", *k, err)
|
2021-03-24 17:16:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|