This commit is contained in:
Philippe Caseiro 2022-06-29 17:26:10 +02:00
parent 57e3c0498e
commit d91faf5636
4 changed files with 21 additions and 1 deletions

View File

@ -20,6 +20,7 @@
"source": "loki-local-config.pktpl.hcl", "source": "loki-local-config.pktpl.hcl",
"mode": "600", "mode": "600",
"owner": "loki", "owner": "loki",
"service": "loki",
"group": "grafana" "group": "grafana"
} }
], ],

View File

@ -25,6 +25,7 @@ type ConfigFile struct {
TemplateType string `json:"type"` // The template file type (hcl or gotemplate) TemplateType string `json:"type"` // The template file type (hcl or gotemplate)
Mode string `form:"mod" json:"mode"` // The configuration file final permissions (mode) Mode string `form:"mod" json:"mode"` // The configuration file final permissions (mode)
Owner string `json:"owner"` // The configuration file owner Owner string `json:"owner"` // The configuration file owner
Service string `json:"service"` // Service to restart after configuration generation
Group string `json:"group"` // The configuration file group owner Group string `json:"group"` // The configuration file group owner
} }
@ -52,6 +53,11 @@ func (cf *ConfigFile) Generate(root string, templateDir string, values []byte) e
return fmt.Errorf("Process templates failed with error: %v", err) return fmt.Errorf("Process templates failed with error: %v", err)
} }
log.Printf("\tFile %s generated\n", dest) log.Printf("\tFile %s generated\n", dest)
if cf.Service != "" {
sv := SystemService{Name: fmt.Sprintf("%s")}
return sv.Restart()
}
return nil return nil
} }

View File

@ -65,7 +65,7 @@ func (s *Service) Manage(templateDir string) error {
return fmt.Errorf("ProcessingTemplatesFailed with error: %v", err) return fmt.Errorf("ProcessingTemplatesFailed with error: %v", err)
} }
log.Printf("Managing services\n") log.Printf("Managing services:\n")
for _, daemon := range s.Daemons { for _, daemon := range s.Daemons {
err = daemon.Manage() err = daemon.Manage()
if err != nil { if err != nil {

View File

@ -99,6 +99,19 @@ func (sys *SystemService) Stop() error {
return nil return nil
} }
func (sys *SystemService) Restart() error {
if sys.Type == "" || sys.Type == "auto" {
sys.SetType()
}
if err := sys.Stop(); err != nil {
return err
}
if err := sys.Start(); err != nil {
return err
}
return nil
}
func (sys *SystemService) Enable() error { func (sys *SystemService) Enable() error {
if sys.Type == "systemd" { if sys.Type == "systemd" {
_, stdErr, err := utils.RunSystemCommand("systemctl", "enable", sys.Name) _, stdErr, err := utils.RunSystemCommand("systemctl", "enable", sys.Name)