mirror of
https://github.com/docker/docs.git
synced 2026-04-05 02:38:52 +07:00
Add a command line option for swam join delay.
Signed-off-by: Dong Chen <dongluo.chen@docker.com>
This commit is contained in:
@@ -36,7 +36,7 @@ var (
|
||||
Name: "join",
|
||||
ShortName: "j",
|
||||
Usage: "join a docker cluster",
|
||||
Flags: []cli.Flag{flJoinAdvertise, flHeartBeat, flTTL, flDiscoveryOpt},
|
||||
Flags: []cli.Flag{flJoinAdvertise, flHeartBeat, flTTL, flJoinRandomDelay, flDiscoveryOpt},
|
||||
Action: join,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -32,6 +32,11 @@ var (
|
||||
Usage: "Address of the Docker Engine joining the cluster. Swarm manager(s) MUST be able to reach the Docker Engine at this address.",
|
||||
EnvVar: "SWARM_ADVERTISE",
|
||||
}
|
||||
flJoinRandomDelay = cli.StringFlag{
|
||||
Name: "joindelay",
|
||||
Value: "0s",
|
||||
Usage: "add a random delay in [0s,joindelay] to avoid synchronized registration",
|
||||
}
|
||||
flManageAdvertise = cli.StringFlag{
|
||||
Name: "advertise, addr",
|
||||
Usage: "Address of the swarm manager joining the cluster. Other swarm manager(s) MUST be able to reach the swarm manager at this address.",
|
||||
|
||||
17
cli/join.go
17
cli/join.go
@@ -29,6 +29,11 @@ func join(c *cli.Context) {
|
||||
log.Fatal("--advertise should be of the form ip:port or hostname:port")
|
||||
}
|
||||
|
||||
joinDelay, err := time.ParseDuration(c.String("joindelay"))
|
||||
if err != nil {
|
||||
log.Fatalf("invalid --joindelay: %v", err)
|
||||
}
|
||||
|
||||
hb, err := time.ParseDuration(c.String("heartbeat"))
|
||||
if err != nil {
|
||||
log.Fatalf("invalid --heartbeat: %v", err)
|
||||
@@ -49,11 +54,13 @@ func join(c *cli.Context) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// add a random delay [0,hb) at start to avoid synchronized registration
|
||||
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
|
||||
delay := time.Duration(r.Int63n(int64(hb)))
|
||||
log.Infof("Add a random delay %s to avoid synchronized registration", delay)
|
||||
time.Sleep(delay)
|
||||
// add a random delay between 0s and joinDelay at start to avoid synchronized registration
|
||||
if joinDelay > 0 {
|
||||
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
|
||||
delay := time.Duration(r.Int63n(int64(joinDelay)))
|
||||
log.Infof("Add a random delay %s to avoid synchronized registration", delay)
|
||||
time.Sleep(delay)
|
||||
}
|
||||
|
||||
for {
|
||||
log.WithFields(log.Fields{"addr": addr, "discovery": dflag}).Infof("Registering on the discovery service every %s...", hb)
|
||||
|
||||
Reference in New Issue
Block a user