Skip to content

Commit

Permalink
BDOG-3097 remove --delay-seconds, make --start exit with non-zero whe…
Browse files Browse the repository at this point in the history
…n errors encountered
  • Loading branch information
jordanrowe committed Apr 10, 2024
1 parent 339c88c commit bc8b84e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 40 deletions.
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ If you'd prefer to carry out these steps manually, then follow these steps:

**Linux Intel**
```shell
curl -L -O https://github.com/hmrc/sm2/releases/download/v1.2.0/sm2-1.2.0-linux-intel.zip && unzip sm2-1.2.0-linux-intel.zip && rm sm2-1.2.0-linux-intel.zip && chmod +x sm2
curl -L -O https://github.com/hmrc/sm2/releases/download/v2.0.0/sm2-2.0.0-linux-intel.zip && unzip sm2-2.0.0-linux-intel.zip && rm sm2-2.0.0-linux-intel.zip && chmod +x sm2
```

**Linux Arm64**
```shell
curl -L -O https://github.com/hmrc/sm2/releases/download/v1.2.0/sm2-1.2.0-linux-arm64.zip && unzip sm2-1.2.0-linux-arm64.zip && rm sm2-1.2.0-linux-arm64.zip && chmod +x sm2
curl -L -O https://github.com/hmrc/sm2/releases/download/v2.0.0/sm2-2.0.0-linux-arm64.zip && unzip sm2-2.0.0-linux-arm64.zip && rm sm2-2.0.0-linux-arm64.zip && chmod +x sm2
```

**OSX/Apple (latest M1/M2 cpus)**

```shell
curl -L -O https://github.com/hmrc/sm2/releases/download/v1.2.0/sm2-1.2.0-apple-arm64.zip && unzip sm2-1.2.0-apple-arm64.zip && rm sm2-1.2.0-apple-arm64.zip && chmod +x sm2
curl -L -O https://github.com/hmrc/sm2/releases/download/v2.0.0/sm2-2.0.0-apple-arm64.zip && unzip sm2-2.0.0-apple-arm64.zip && rm sm2-2.0.0-apple-arm64.zip && chmod +x sm2
```

**OSX/Apple (older Intel cpus)**

```shell
curl -L -O https://github.com/hmrc/sm2/releases/download/v1.2.0/sm2-1.2.0-apple-intel.zip && unzip sm2-1.2.0-apple-intel.zip && rm sm2-1.2.0-apple-intel.zip && chmod +x sm2
curl -L -O https://github.com/hmrc/sm2/releases/download/v2.0.0/sm2-2.0.0-apple-intel.zip && unzip sm2-2.0.0-apple-intel.zip && rm sm2-2.0.0-apple-intel.zip && chmod +x sm2
```

If everything has worked you should have an executable called `sm2`.
Expand Down Expand Up @@ -130,14 +130,6 @@ Alternatively you can start more than one service at once by typing multiple ser
$ sm2 -start SERVICE_ONE SERVICE_TWO
```

#### Starting a large group of services
Starting a large group of services can overload the cpu of a machine and lead to services failing to start.
If this happens use the following command to start the services at a slower pace.
```shell
$ sm2 --start LARGE_PROFILE_NAME --workers 1 --delay-seconds 5
```
The workers argument starts one service at a time and the DelaySeconds argument adds a 5 second delay inbetween services.

### Starting specific versions
If you need to run a specific version of a service you can do so by adding a colon followed by the version number to the service name, e.g.
```shell
Expand Down Expand Up @@ -238,7 +230,7 @@ Sometimes a service will fail to start up. To help determine why, service manage
Before doing anything else, it’s worth running service-manager’s self-checks to ensure it is installed correctly.
```shell
$ sm2 -diagnostic
version: 1.2.0
version: 2.0.0
build: ef49b60
OS: OK (linux, amd64)
JAVA: OK (11.0.17)
Expand Down
4 changes: 1 addition & 3 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type UserOption struct {
Verify bool // checks if a given service or profile is running
Wait int // waits a given number of secs (default 30) after starting a service for it to respond to healthcheck
Workers int // sets the number of concurrent downloads/service starts
DelaySeconds int // sets the pause in seconds between starting services
}

func Parse(args []string) (*UserOption, error) {
Expand Down Expand Up @@ -197,9 +196,8 @@ func BuildFlagSet(opts *UserOption) *flag.FlagSet {
flagset.BoolVar(&opts.Verbose, "v", false, "enable verbose output")
flagset.BoolVar(&opts.Version, "version", false, "show the version of service-manager")
flagset.BoolVar(&opts.Verify, "verify", false, "for scripts, checks if a service/profile is running")
flagset.IntVar(&opts.Wait, "wait", 30, "used with --start, waits a specified number of seconds for the service to respond to a healthcheck, defaults to 30")
flagset.IntVar(&opts.Wait, "wait", 30, "used with --start, waits a specified number of seconds for each service to respond to a healthcheck, defaults to 30")
flagset.IntVar(&opts.Workers, "workers", defaultWorkers(), "how many services should be downloaded at the same time (use with --start)")
flagset.IntVar(&opts.DelaySeconds, "delay-seconds", 0, "how long to pause, in seconds, after starting a service before starting another")

return flagset
}
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ IFS=$'\n\t'

TARGET_OS="linux"
TARGET_ARCH="intel"
TARGET_VERSION="1.2.0"
TARGET_VERSION="2.0.0"

if [[ "$(uname)" == "Darwin" ]]; then
TARGET_OS="apple"
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

BINARY := sm2
VERSION := 1.2.0
VERSION := 2.0.0
BUILD := `git rev-parse HEAD`

# Setup linker flags option for build that interoperate with variable names in src code
Expand Down
3 changes: 1 addition & 2 deletions servicemanager/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ func dontComplete(previousWord string) bool {
"-ports",
"-search",
"-wait",
"-workers",
"-delay-seconds":
"-workers":
return true
}
return false
Expand Down
12 changes: 2 additions & 10 deletions servicemanager/startservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ func (sm *ServiceManager) StartService(serviceAndVersion ServiceAndVersion) erro
return err
}
err = sm.pauseTillHealthy(healthcheckUrl)

if sm.Commands.DelaySeconds > 0 {
time.Sleep(time.Duration(sm.Commands.DelaySeconds) * time.Second)
}
return err
}

Expand All @@ -113,7 +109,7 @@ func (sm *ServiceManager) pauseTillHealthy(healthcheckUrl string) error {
count++
time.Sleep(500 * time.Millisecond)
}
return fmt.Errorf("health check unsuccessful after %d seconds", sm.Commands.DelaySeconds)
return fmt.Errorf("health check unsuccessful after %d seconds", sm.Commands.Wait)
}

func (sm *ServiceManager) installService(installDir string, serviceId string, group string, artifact string, version string) (ledger.InstallFile, error) {
Expand Down Expand Up @@ -357,17 +353,13 @@ func (sm *ServiceManager) asyncStart(services []ServiceAndVersion) {
fmt.Println("Starting 1 service")
} else {
workerPlural := "workers"
delay := ""

if sm.Commands.Workers == 1 {
workerPlural = "worker"
}

if sm.Commands.DelaySeconds != 0 {
delay = fmt.Sprintf(", with a delay of %d seconds", sm.Commands.DelaySeconds)
}

fmt.Printf("Starting %d services on %d %s%s\n", len(services), sm.Commands.Workers, workerPlural, delay)
fmt.Printf("Starting %d services on %d %s\n", len(services), sm.Commands.Workers, workerPlural)
}

// start up a number of workers (controlled by --workers param)
Expand Down
12 changes: 2 additions & 10 deletions servicemanager/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (sm *ServiceManager) PrintStatus() {

longestServiceName := getLongestServiceName(append(statuses, unmanaged...))
printTable(statuses, termWidth, longestServiceName, os.Stdout)
printHelpIfRequired(statuses, sm.Commands.DelaySeconds)
printHelpIfRequired(statuses)

if len(unmanaged) > 0 {
fmt.Print("\n\033[34mAlso, the following processes are running which occupy ports of services\n")
Expand Down Expand Up @@ -332,7 +332,7 @@ func printUnmanagedTable(statuses []serviceStatus, maxWidth int, longestServiceN
fmt.Fprint(out, border)
}

func printHelpIfRequired(statuses []serviceStatus, delay int) {
func printHelpIfRequired(statuses []serviceStatus) {
for _, status := range statuses {
if status.health == FAIL && status.service != "MONGO" {
fmt.Print("\n\033[1;31mOne or more services have failed to start.\033[0m\n")
Expand All @@ -342,14 +342,6 @@ func printHelpIfRequired(statuses []serviceStatus, delay int) {
fmt.Print("Alternatively, you can remove them from this list by using:\n")
fmt.Print(" sm2 -prune\n\n")

if delay == 0 && len(statuses) >= 10 { // not already using --delay-seconds
fmt.Println("Note: If you're starting a profile that contains a lot of services,")
fmt.Println("try using `--delay-seconds 5` to add a 5 second delay after starting")
fmt.Println("each service. This will help prevent your CPU getting overloaded,")
fmt.Println("which can cause the services to take too long to respond to the healthcheck.")
fmt.Println("See `sm2 --help` for more information.")
}

return
}
}
Expand Down

0 comments on commit bc8b84e

Please sign in to comment.