From 2810ac408e6be92640469e7f6fe4aa680fece643 Mon Sep 17 00:00:00 2001 From: jordanrowe <37838443+jordanrowe@users.noreply.github.com> Date: Fri, 30 Jun 2023 12:12:42 +0100 Subject: [PATCH] BDOG-2663 add -latest flag to be used in conjunction with -restart --- cli/cli.go | 2 ++ servicemanager/commands.go | 9 +++++++++ servicemanager/stopservice.go | 8 ++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 26daed5..256c3fc 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -22,6 +22,7 @@ type UserOption struct { ExtraServices []string // ids of services to start FromSource bool // used with --start to run from source rather than bin FormatPlain bool // flag for setting enabling machine friendly/undecorated output + Latest bool // used in conjunction with --restart to check for latest version of service(s) being restarted List bool // lists all the services Logs string // prints the logs of a service, running or otherwise NoProgress bool // hides the animated download progress meter @@ -163,6 +164,7 @@ func buildFlagSet(opts *UserOption) *flag.FlagSet { flagset.BoolVar(&opts.Diagnostic, "diagnostic", false, "a suite of checks to debug issues with service manager") flagset.BoolVar(&opts.FromSource, "src", false, "run service from source (use with --start)") flagset.BoolVar(&opts.FormatPlain, "format-plain", false, "list services without formatting") + flagset.BoolVar(&opts.Latest, "latest", false, "used in conjunction with -restart to check for latest version of service(s) being restarted") flagset.BoolVar(&opts.List, "list", false, "lists all available services") flagset.StringVar(&opts.Logs, "logs", "", "shows the stdout logs for a service") flagset.BoolVar(&opts.NoProgress, "noprogress", false, "prevents download progress being shown (use with --start)") diff --git a/servicemanager/commands.go b/servicemanager/commands.go index 0e51d61..50dc28f 100644 --- a/servicemanager/commands.go +++ b/servicemanager/commands.go @@ -65,6 +65,15 @@ func (sm *ServiceManager) Run() { } else if sm.Commands.StopAll { // stops all managed services sm.StopAll() + } else if sm.Commands.Restart && sm.Commands.Latest { + // restarts service(s) or profile(s) by doing an explicit stop and start to pick up latest versions + services := sm.requestedServicesAndProfiles() + + for _, s := range services { + sm.StopService(s.service) + } + + sm.asyncStart(services) } else if sm.Commands.Restart { // restarts service(s) or profile(s) services := sm.requestedServicesAndProfiles() diff --git a/servicemanager/stopservice.go b/servicemanager/stopservice.go index 5931159..37821fb 100644 --- a/servicemanager/stopservice.go +++ b/servicemanager/stopservice.go @@ -8,9 +8,9 @@ import ( func (sm *ServiceManager) StopService(serviceName string) error { // @improve just load the state file instead and kill the listed pid? - statues := sm.findStatuses() + statuses := sm.findStatuses() - for _, status := range statues { + for _, status := range statuses { if status.service == serviceName { sm.stop(status) return nil @@ -31,9 +31,9 @@ func (sm *ServiceManager) StopAll() { fmt.Printf("Stopping ALL services!\n") - statues := sm.findStatuses() + statuses := sm.findStatuses() - for _, status := range statues { + for _, status := range statuses { sm.stop(status) }