Skip to content

Commit

Permalink
Merge pull request #71 from hmrc/BDOG-2663-1
Browse files Browse the repository at this point in the history
BDOG-2663 add -latest flag to be used in conjunction with -restart
  • Loading branch information
jordanrowe authored Jun 30, 2023
2 parents 104e212 + 2810ac4 commit a90a920
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)")
Expand Down
9 changes: 9 additions & 0 deletions servicemanager/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions servicemanager/stopservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand Down

0 comments on commit a90a920

Please sign in to comment.