From 5a75bc5a37f9106acb1afc5d5f8689a76e8f465a Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Thu, 30 Jun 2022 09:48:10 +0200 Subject: [PATCH] Try 07 --- pkg/templater/files.go | 10 ---------- pkg/templater/services.go | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pkg/templater/files.go b/pkg/templater/files.go index 4385235..cc95268 100644 --- a/pkg/templater/files.go +++ b/pkg/templater/files.go @@ -53,16 +53,6 @@ func (cf *ConfigFile) Generate(root string, templateDir string, values []byte) e return fmt.Errorf("Process templates failed with error: %v", err) } log.Printf("\tFile %s generated\n", dest) - - if cf.Service != "" { - sv := SystemService{ - Name: cf.Service, - Enabled: true, - Type: "", - ToStart: true, - } - return sv.Restart() - } return nil } diff --git a/pkg/templater/services.go b/pkg/templater/services.go index 9a17278..db30e44 100644 --- a/pkg/templater/services.go +++ b/pkg/templater/services.go @@ -81,6 +81,7 @@ func processConfigFiles(tpls []ConfigFile, variables map[string]interface{}, tem return fmt.Errorf("Error unmarshaling values on template process; %v", err) } + var servicesToRestart []string for _, tpl := range tpls { fileExt := filepath.Ext(tpl.Source) if fileExt == ".hcl" { @@ -94,6 +95,19 @@ func processConfigFiles(tpls []ConfigFile, variables map[string]interface{}, tem return fmt.Errorf("Template %s generation failed with error %v", tpl.Source, err) } + if len(tpl.Service) != 0 { + servicesToRestart = append(servicesToRestart, tpl.Service) + } + } + + for _, srv := range servicesToRestart { + sv := SystemService{ + Name: srv, + Enabled: true, + Type: "", + ToStart: true, + } + return sv.Restart() } return nil }