-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
couchdb-cluster-config.go
97 lines (88 loc) · 2.22 KB
/
couchdb-cluster-config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
"log"
"os"
"time"
"github.com/urfave/cli/v2"
"github.com/gesellix/couchdb-cluster-config/v17/pkg"
)
var (
version = "dev"
commit = "none"
date = "unknown"
)
func main() {
app := cli.NewApp()
app.Name = "CouchDB Cluster Config"
app.Usage = ""
app.Description = "Setup a CouchDB 2.x cluster"
app.Version = fmt.Sprintf("%s (%s, %s)", version, commit, date)
app.Commands = []*cli.Command{
{
Name: "setup",
Usage: "perform a cluster setup",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "nodes",
Usage: "list of node ip addresses to participate in the CouchDB cluster",
},
&cli.DurationFlag{
Name: "delay",
Usage: "time to wait before the cluster setup will be started",
Value: 5 * time.Second,
},
&cli.DurationFlag{
Name: "timeout",
Usage: "time until all nodes need to be available",
Value: 20 * time.Second,
},
&cli.StringFlag{
Name: "username",
Usage: "admin username - admin will be created, if missing",
},
&cli.StringFlag{
Name: "password",
Usage: "admin password",
},
},
Action: func(c *cli.Context) error {
nodes := c.StringSlice("nodes")
if len(nodes) == 0 {
return fmt.Errorf("please pass a list of node ip addresses")
}
if c.String("username") == "" {
return fmt.Errorf("please provide an admin username")
}
if c.String("password") == "" {
return fmt.Errorf("please provide an admin password")
}
ips := cluster_config.ToIpAddresses(nodes)
delay := c.Duration("delay")
timeout := c.Duration("timeout")
fmt.Printf("Going to setup the following nodes as cluster, delayed by %fs\n%v\n", delay.Seconds(), ips)
return cluster_config.SetupClusterNodes(
cluster_config.ClusterSetupConfig{
IpAddresses: ips,
Delay: delay,
Timeout: timeout,
},
cluster_config.BasicAuth{
Username: c.String("username"),
Password: c.String("password")},
c.Bool("insecure"))
},
},
}
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "insecure",
Usage: "ignore server certificate if using https",
Value: true,
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}