mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
This commit adds reload command to ctrld for re-fetch new config from ContorlD API or re-read the current config on disk.
35 lines
675 B
Go
35 lines
675 B
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/vishvananda/netlink"
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func (p *prog) watchLinkState(ctx context.Context) {
|
|
ch := make(chan netlink.LinkUpdate)
|
|
done := make(chan struct{})
|
|
defer close(done)
|
|
if err := netlink.LinkSubscribe(ch, done); err != nil {
|
|
mainLog.Load().Warn().Err(err).Msg("could not subscribe link")
|
|
return
|
|
}
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case lu := <-ch:
|
|
if lu.Change == 0xFFFFFFFF {
|
|
continue
|
|
}
|
|
if lu.Change&unix.IFF_UP != 0 {
|
|
mainLog.Load().Debug().Msgf("link state changed, re-bootstrapping")
|
|
for _, uc := range p.cfg.Upstream {
|
|
uc.ReBootstrap()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|