Rejoin join nodes automatically
This adds a --rejoin setting for rejoining cluter nodes automatically when gone.
This commit is contained in:
parent
62d9c44c11
commit
da04afe24b
|
@ -13,6 +13,7 @@ import (
|
|||
type config struct {
|
||||
ClusterKey []byte `id:"cluster-key" desc:"shared key for cluster membership; must be 32 bytes base64 encoded; will be generated if not provided"`
|
||||
Join []string `desc:"comma separated list of hostnames or IP addresses to existing cluster members; if not provided, will attempt resuming any known state or otherwise wait for further members."`
|
||||
Rejoin int `desc:"interval at which join nodes are joined again if away, 0 disables rejoining altogether" default:"0"`
|
||||
Init bool `desc:"whether to explicitly (re)initialize the cluster; any known state from previous runs will be forgotten"`
|
||||
BindAddr string `id:"bind-addr" desc:"IP address to bind to for cluster membership traffic (cannot be used with --bind-iface)"`
|
||||
BindIface string `id:"bind-iface" desc:"Interface to bind to for cluster membership traffic (cannot be used with --bind-addr)"`
|
||||
|
|
9
main.go
9
main.go
|
@ -50,6 +50,12 @@ func main() {
|
|||
Logger: logrus.StandardLogger(),
|
||||
}
|
||||
|
||||
// Prepare the rejoin timer
|
||||
rejoin := make(<-chan time.Time)
|
||||
if config.Rejoin > 0 {
|
||||
rejoin = time.Tick(time.Duration(1000000000 * config.Rejoin))
|
||||
}
|
||||
|
||||
// Join the cluster
|
||||
cluster.Update(localNode)
|
||||
nodec := cluster.Members() // avoid deadlocks by starting before join
|
||||
|
@ -96,6 +102,9 @@ func main() {
|
|||
logrus.Info("announcing new routes...")
|
||||
localNode.Routes = routes
|
||||
cluster.Update(localNode)
|
||||
case <-rejoin:
|
||||
logrus.Debug("rejoining missing join nodes...")
|
||||
cluster.Join(config.Join)
|
||||
case <-incomingSigs:
|
||||
logrus.Info("terminating...")
|
||||
cluster.Leave()
|
||||
|
|
Loading…
Reference in New Issue