Skip to content

Commit

Permalink
Merge #28198
Browse files Browse the repository at this point in the history
28198: cli: hint client flags in the output of `cockroach start` r=knz a=knz

Fixes #14325.
Requested by @sploiselle.

When one starts a node with the --host/--advertise flag, all future
clients commands require the same value in --host. However, there is
no in-app messaging that communicates this requirement, nor is there a
command that you can run to find out what the --host flag was set to.

Ditto for --certs-dir.

This patch enhances the situation by announcing the command prefix to
use for client commands in the output of `cockroach start`. For
example:

```
% ./cockroach start --certs-dir=certs --host=localhost
CockroachDB node starting [...]
...
client flags:        ./cockroach --host=localhost --port=26257 --certs-dir=certs
...
```

```
% ./cockroach start --certs-dir=certs --host=localhost --advertise-host=kenax
CockroachDB node starting [...]
...
client flags:        ./cockroach --host=kenax --port=26257 --certs-dir=certs
...
```

Release note (cli change): `cockroach start` now informs the user of
which command-line flags to use to access the newly started node in
client commands (e.g. `cockroach quit` etc.).

Co-authored-by: Raphael 'kena' Poss <[email protected]>
  • Loading branch information
craig[bot] and knz committed Aug 2, 2018
2 parents 226ec67 + 39d8b03 commit 2e4952d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ func runStart(cmd *cobra.Command, args []string) error {
fmt.Fprintf(tw, "build:\t%s %s @ %s (%s)\n", info.Distribution, info.Tag, info.Time, info.GoVersion)
fmt.Fprintf(tw, "webui:\t%s\n", serverCfg.AdminURL())
fmt.Fprintf(tw, "sql:\t%s\n", pgURL)
fmt.Fprintf(tw, "client flags:\t%s\n", clientFlags())
if len(serverCfg.SocketFile) != 0 {
fmt.Fprintf(tw, "socket:\t%s\n", serverCfg.SocketFile)
}
Expand Down Expand Up @@ -787,6 +788,22 @@ func runStart(cmd *cobra.Command, args []string) error {
return returnErr
}

func clientFlags() string {
flags := []string{os.Args[0]}
host, port, err := net.SplitHostPort(serverCfg.AdvertiseAddr)
if err == nil {
flags = append(flags,
"--host="+host,
"--port="+port)
}
if startCtx.serverInsecure {
flags = append(flags, "--insecure")
} else {
flags = append(flags, "--certs-dir="+startCtx.serverSSLCertsDir)
}
return strings.Join(flags, " ")
}

func reportConfiguration(ctx context.Context) {
serverCfg.Report(ctx)
if envVarsUsed := envutil.GetEnvVarsUsed(); len(envVarsUsed) > 0 {
Expand Down

0 comments on commit 2e4952d

Please sign in to comment.