diff --git a/config.go b/config.go index 5058e99..4eb2846 100644 --- a/config.go +++ b/config.go @@ -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)"` diff --git a/main.go b/main.go index 14e2ae4..0188c96 100644 --- a/main.go +++ b/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()