diff --git a/CHANGELOG.md b/CHANGELOG.md index 543ff82c..8ed6782a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ -## 6.7.1 (unreleased) +## 6.8.0 (unreleased) +### New features +- [PR #921](https://github.com/rqlite/rqlite/pull/921): Support fetching `/readyz` via CLI. + ### Implementation changes and bug fixes - [PR #920](https://github.com/rqlite/rqlite/pull/920): Minor log message fixes. diff --git a/cmd/rqlite/main.go b/cmd/rqlite/main.go index f33a971c..0828ac61 100644 --- a/cmd/rqlite/main.go +++ b/cmd/rqlite/main.go @@ -41,6 +41,7 @@ var cliHelp = []string{ `.expvar Show expvar (Go runtime) information for connected node`, `.help Show this message`, `.indexes Show names of all indexes`, + `.ready Show ready status for connected node`, `.restore Restore the database from a SQLite dump file`, `.nodes Show connection status of all nodes in cluster`, `.schema Show CREATE statements for all tables`, @@ -130,6 +131,8 @@ func main() { err = toggleTimer(line[index+1:], &timer) case ".STATUS": err = status(ctx, cmd, line, argv) + case ".READY": + err = ready(ctx, client, argv) case ".NODES": err = nodes(ctx, cmd, line, argv) case ".EXPVAR": @@ -213,6 +216,39 @@ func status(ctx *cli.Context, cmd, line string, argv *argT) error { return cliJSON(ctx, cmd, line, url, argv) } +func ready(ctx *cli.Context, client *http.Client, argv *argT) error { + u := url.URL{ + Scheme: argv.Protocol, + Host: fmt.Sprintf("%s:%d", argv.Host, argv.Port), + Path: fmt.Sprintf("%s/readyz", argv.Prefix), + } + urlStr := u.String() + + req, err := http.NewRequest("GET", urlStr, nil) + if err != nil { + return err + } + if argv.Credentials != "" { + creds := strings.Split(argv.Credentials, ":") + if len(creds) != 2 { + return fmt.Errorf("invalid Basic Auth credentials format") + } + req.SetBasicAuth(creds[0], creds[1]) + } + + resp, err := client.Do(req) + if err != nil { + return err + } + if resp.StatusCode == 200 { + ctx.String("ready\n") + } else { + ctx.String("not ready\n") + } + + return nil +} + func nodes(ctx *cli.Context, cmd, line string, argv *argT) error { url := fmt.Sprintf("%s://%s:%d/nodes", argv.Protocol, argv.Host, argv.Port) return cliJSON(ctx, cmd, line, url, argv)