cleaning logs, fixing mac apply

This commit is contained in:
afeiszli
2022-02-08 20:54:02 -05:00
parent 03f37b14f1
commit d5bae019b3
5 changed files with 44 additions and 36 deletions

View File

@@ -112,10 +112,8 @@ func PublishPeerUpdate(newNode *models.Node) error {
for _, node := range networkNodes { for _, node := range networkNodes {
if node.IsServer == "yes" || node.ID == newNode.ID { if node.IsServer == "yes" || node.ID == newNode.ID {
log.Println("skipping update on " + node.Name + " : " + node.ID)
continue continue
} }
log.Println("running update on " + node.Name + " : " + node.ID)
peerUpdate, err := logic.GetPeerUpdate(&node) peerUpdate, err := logic.GetPeerUpdate(&node)
if err != nil { if err != nil {
logger.Log(1, "error getting peer update for node", node.ID, err.Error()) logger.Log(1, "error getting peer update for node", node.ID, err.Error())

View File

@@ -95,7 +95,7 @@ func MacDaemonString(interval string) string {
<key>Label</key><string>com.gravitl.netclient</string> <key>Label</key><string>com.gravitl.netclient</string>
<key>ProgramArguments</key> <key>ProgramArguments</key>
<array> <array>
<string>/sbin/netclient</string> <string>/usr/local/bin/netclient</string>
<string>daemon</string> <string>daemon</string>
</array> </array>
<key>StandardOutPath</key><string>/etc/netclient/com.gravitl.netclient.log</string> <key>StandardOutPath</key><string>/etc/netclient/com.gravitl.netclient.log</string>

View File

@@ -53,7 +53,7 @@ func read(network, which string) string {
if readMessage.LastSeen.IsZero() { if readMessage.LastSeen.IsZero() {
return "" return ""
} }
if time.Now().After(readMessage.LastSeen.Add(time.Minute)) { // check if message has been there over a minute if time.Now().After(readMessage.LastSeen.Add(time.Minute * 10)) { // check if message has been there over a minute
messageCache.Delete(fmt.Sprintf("%s%s", network, which)) // remove old message if expired messageCache.Delete(fmt.Sprintf("%s%s", network, which)) // remove old message if expired
return "" return ""
} }
@@ -134,6 +134,7 @@ func SetupMQTT(cfg *config.ClientConfig, publish bool) mqtt.Client {
if err != nil { if err != nil {
ncutils.Log("could not run pull, please restart daemon or examine network connectivity --- " + err.Error()) ncutils.Log("could not run pull, please restart daemon or examine network connectivity --- " + err.Error())
} }
ncutils.Log("connection re-established with mqtt server")
}) })
client := mqtt.NewClient(opts) client := mqtt.NewClient(opts)
@@ -173,32 +174,35 @@ func MessageQueue(ctx context.Context, network string) {
ncutils.Log("netclient go routine started for " + network) ncutils.Log("netclient go routine started for " + network)
var cfg config.ClientConfig var cfg config.ClientConfig
cfg.Network = network cfg.Network = network
var configPath = fmt.Sprintf("%snetconfig-%s", ncutils.GetNetclientPathSpecific(), network) /*
fileInfo, err := os.Stat(configPath) var configPath = fmt.Sprintf("%snetconfig-%s", ncutils.GetNetclientPathSpecific(), network)
if err != nil { fileInfo, err := os.Stat(configPath)
ncutils.Log("could not stat config file: " + configPath) if err != nil {
} ncutils.Log("could not stat config file: " + configPath)
// speed up UDP rest
if time.Now().After(fileInfo.ModTime().Add(time.Minute)) {
sleepTime := 2
ncutils.Log("pulling latest config for " + cfg.Network)
for {
_, err := Pull(network, true)
if err == nil {
break
} else {
ncutils.PrintLog("error pulling config for "+network+": "+err.Error(), 1)
} }
if sleepTime > 3600 { // speed up UDP rest
sleepTime = 3600 if time.Now().After(fileInfo.ModTime().Add(time.Minute)) {
} sleepTime := 2
ncutils.Log("failed to pull for network " + network) ncutils.Log("pulling latest config for " + cfg.Network)
ncutils.Log(fmt.Sprintf("waiting %d seconds to retry...", sleepTime)) for {
time.Sleep(time.Second * time.Duration(sleepTime)) _, err := Pull(network, true)
sleepTime = sleepTime * 2 if err == nil {
} break
} } else {
time.Sleep(time.Second << 1) ncutils.PrintLog("error pulling config for "+network+": "+err.Error(), 1)
}
if sleepTime > 3600 {
sleepTime = 3600
}
ncutils.Log("failed to pull for network " + network)
ncutils.Log(fmt.Sprintf("waiting %d seconds to retry...", sleepTime))
time.Sleep(time.Second * time.Duration(sleepTime))
sleepTime = sleepTime * 2
}
}
time.Sleep(time.Second << 1)
*/
cfg.ReadConfig() cfg.ReadConfig()
ncutils.Log("daemon started for network: " + network) ncutils.Log("daemon started for network: " + network)
client := SetupMQTT(&cfg, false) client := SetupMQTT(&cfg, false)
@@ -365,12 +369,19 @@ func UpdatePeers(client mqtt.Client, msg mqtt.Message) {
return return
} }
//err = wireguard.SyncWGQuickConf(cfg.Node.Interface, file) //err = wireguard.SyncWGQuickConf(cfg.Node.Interface, file)
err = wireguard.SetPeers(cfg.Node.Interface, cfg.Node.Address, cfg.Node.PersistentKeepalive, peerUpdate.Peers) var iface = cfg.Node.Interface
if ncutils.IsMac() {
iface, err = local.GetMacIface(cfg.Node.Address)
if err != nil {
ncutils.Log("error retrieving mac iface: " + err.Error())
return
}
}
err = wireguard.SetPeers(iface, cfg.Node.Address, cfg.Node.PersistentKeepalive, peerUpdate.Peers)
if err != nil { if err != nil {
ncutils.Log("error syncing wg after peer update " + err.Error()) ncutils.Log("error syncing wg after peer update: " + err.Error())
return return
} }
ncutils.Log(fmt.Sprintf("received peer update on network, %s", cfg.Network))
} }
// MonitorKeepalive - checks time last server keepalive received. If more than 3+ minutes, notify and resubscribe // MonitorKeepalive - checks time last server keepalive received. If more than 3+ minutes, notify and resubscribe

View File

@@ -570,9 +570,9 @@ func CheckWG() {
PrintLog(err.Error(), 0) PrintLog(err.Error(), 0)
log.Fatal("WireGuard not installed. Please install WireGuard (wireguard-tools) and try again.") log.Fatal("WireGuard not installed. Please install WireGuard (wireguard-tools) and try again.")
} }
PrintLog("Running with userspace wireguard: "+uspace, 0) PrintLog("running with userspace wireguard: "+uspace, 0)
} else if uspace != "wg" { } else if uspace != "wg" {
log.Println("running userspace WireGuard with " + uspace) PrintLog("running userspace WireGuard with "+uspace, 0)
} }
} }

View File

@@ -174,7 +174,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
time.Sleep(time.Second >> 2) time.Sleep(time.Second >> 2)
d, _ = wgclient.Device(deviceiface) d, _ = wgclient.Device(deviceiface)
} }
ApplyConf(node, deviceiface, confPath) // Apply initially ApplyConf(node, ifacename, confPath) // Apply initially
ncutils.PrintLog("waiting for interface...", 1) // ensure interface is created ncutils.PrintLog("waiting for interface...", 1) // ensure interface is created
output, _ := ncutils.RunCmd("wg", false) output, _ := ncutils.RunCmd("wg", false)
starttime := time.Now() starttime := time.Now()
@@ -355,7 +355,6 @@ func UpdateWgPeers(file string, peers []wgtypes.PeerConfig) error {
AllowNonUniqueSections: true, AllowNonUniqueSections: true,
AllowShadows: true, AllowShadows: true,
} }
ncutils.Log("updating " + file)
wireguard, err := ini.LoadSources(options, file) wireguard, err := ini.LoadSources(options, file)
if err != nil { if err != nil {
return err return err