|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2017 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | +// Author Ewout Prangsma |
| 21 | +// |
| 22 | + |
| 23 | +package main |
| 24 | + |
| 25 | +import ( |
| 26 | + "context" |
| 27 | + "fmt" |
| 28 | + "net/url" |
| 29 | + "time" |
| 30 | + |
| 31 | + "github.com/arangodb-helper/arangodb/client" |
| 32 | + "github.com/spf13/cobra" |
| 33 | +) |
| 34 | + |
| 35 | +var ( |
| 36 | + cmdStop = &cobra.Command{ |
| 37 | + Use: "stop", |
| 38 | + Short: "Stop a ArangoDB starter", |
| 39 | + Run: cmdStopRun, |
| 40 | + } |
| 41 | +) |
| 42 | + |
| 43 | +func init() { |
| 44 | + cmdMain.AddCommand(cmdStop) |
| 45 | +} |
| 46 | + |
| 47 | +func cmdStopRun(cmd *cobra.Command, args []string) { |
| 48 | + // Setup logging |
| 49 | + configureLogging() |
| 50 | + |
| 51 | + // Create starter client |
| 52 | + scheme := "http" |
| 53 | + if sslAutoKeyFile || sslKeyFile != "" { |
| 54 | + scheme = "https" |
| 55 | + } |
| 56 | + starterURL, err := url.Parse(fmt.Sprintf("%s://127.0.0.1:%d", scheme, masterPort)) |
| 57 | + if err != nil { |
| 58 | + log.Fatalf("Failed to create starter URL: %#v", err) |
| 59 | + } |
| 60 | + client, err := client.NewArangoStarterClient(*starterURL) |
| 61 | + if err != nil { |
| 62 | + log.Fatalf("Failed to create starter client: %#v", err) |
| 63 | + } |
| 64 | + |
| 65 | + // Shutdown starter |
| 66 | + rootCtx := context.Background() |
| 67 | + ctx, cancel := context.WithTimeout(rootCtx, time.Minute) |
| 68 | + err = client.Shutdown(ctx, false) |
| 69 | + cancel() |
| 70 | + if err != nil { |
| 71 | + log.Fatalf("Failed to shutdown starter: %#v", err) |
| 72 | + } |
| 73 | + |
| 74 | + // Wait for starter to be really gone |
| 75 | + for { |
| 76 | + ctx, cancel := context.WithTimeout(rootCtx, time.Second) |
| 77 | + _, err := client.Version(ctx) |
| 78 | + cancel() |
| 79 | + if err != nil { |
| 80 | + break |
| 81 | + } |
| 82 | + time.Sleep(time.Millisecond * 100) |
| 83 | + } |
| 84 | +} |
0 commit comments