mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 00:43:58 +08:00
removing peer cache
This commit is contained in:
@@ -3,6 +3,7 @@ package daemon
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gravitl/netmaker/netclient/config"
|
"github.com/gravitl/netmaker/netclient/config"
|
||||||
)
|
)
|
||||||
@@ -29,3 +30,22 @@ func InstallDaemon(cfg config.ClientConfig) error {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Restart() error {
|
||||||
|
os := runtime.GOOS
|
||||||
|
var err error
|
||||||
|
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
|
switch os {
|
||||||
|
case "windows":
|
||||||
|
RestartWindowsDaemon()
|
||||||
|
case "darwin":
|
||||||
|
RestartLaunchD()
|
||||||
|
case "linux":
|
||||||
|
RestartSystemD()
|
||||||
|
default:
|
||||||
|
err = errors.New("this os is not yet supported for daemon mode. Run join cmd with flag '--daemon off'")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gravitl/netmaker/netclient/ncutils"
|
"github.com/gravitl/netmaker/netclient/ncutils"
|
||||||
)
|
)
|
||||||
@@ -54,6 +55,12 @@ func CleanupMac() {
|
|||||||
os.Remove(EXEC_DIR + "netclient")
|
os.Remove(EXEC_DIR + "netclient")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RestartLaunchD() {
|
||||||
|
ncutils.RunCmd("launchctl unload /Library/LaunchDaemons/"+MAC_SERVICE_NAME+".plist", true)
|
||||||
|
time.Sleep(time.Second >> 2)
|
||||||
|
ncutils.RunCmd("launchctl load /Library/LaunchDaemons/"+MAC_SERVICE_NAME+".plist", true)
|
||||||
|
}
|
||||||
|
|
||||||
// CreateMacService - Creates the mac service file for LaunchDaemons
|
// CreateMacService - Creates the mac service file for LaunchDaemons
|
||||||
func CreateMacService(servicename string, interval string) error {
|
func CreateMacService(servicename string, interval string) error {
|
||||||
_, err := os.Stat("/Library/LaunchDaemons")
|
_, err := os.Stat("/Library/LaunchDaemons")
|
||||||
|
@@ -73,6 +73,10 @@ WantedBy=multi-user.target
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RestartSystemD() {
|
||||||
|
_, _ = ncutils.RunCmd("systemctl start netclient.service", true)
|
||||||
|
}
|
||||||
|
|
||||||
func CleanupLinux() {
|
func CleanupLinux() {
|
||||||
if err := os.RemoveAll(ncutils.GetNetclientPath()); err != nil {
|
if err := os.RemoveAll(ncutils.GetNetclientPath()); err != nil {
|
||||||
ncutils.PrintLog("Removing netclient configs: "+err.Error(), 1)
|
ncutils.PrintLog("Removing netclient configs: "+err.Error(), 1)
|
||||||
|
@@ -34,6 +34,13 @@ func SetupWindowsDaemon() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RestartWindowsDaemon() {
|
||||||
|
StopWindowsDaemon()
|
||||||
|
// start daemon, will not restart or start another
|
||||||
|
ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, false)
|
||||||
|
ncutils.Log(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1) + `winsw.exe start`)
|
||||||
|
}
|
||||||
|
|
||||||
// CleanupWindows - cleans up windows files
|
// CleanupWindows - cleans up windows files
|
||||||
func CleanupWindows() {
|
func CleanupWindows() {
|
||||||
if !ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "winsw.xml") {
|
if !ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "winsw.xml") {
|
||||||
|
@@ -43,20 +43,21 @@ func getPrivateAddr() (string, error) {
|
|||||||
|
|
||||||
var local string
|
var local string
|
||||||
conn, err := net.Dial("udp", "8.8.8.8:80")
|
conn, err := net.Dial("udp", "8.8.8.8:80")
|
||||||
if err != nil {
|
if err == nil {
|
||||||
log.Fatal(err)
|
defer conn.Close()
|
||||||
}
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
||||||
localIP := localAddr.IP
|
localIP := localAddr.IP
|
||||||
local = localIP.String()
|
local = localIP.String()
|
||||||
|
}
|
||||||
if local == "" {
|
if local == "" {
|
||||||
local, err = getPrivateAddrBackup()
|
local, err = getPrivateAddrBackup()
|
||||||
}
|
}
|
||||||
|
|
||||||
if local == "" {
|
if local == "" {
|
||||||
err = errors.New("could not find local ip")
|
err = errors.New("could not find local ip")
|
||||||
}
|
}
|
||||||
|
|
||||||
return local, err
|
return local, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -357,7 +357,7 @@ func MonitorKeepalive(ctx context.Context, client mqtt.Client, cfg *config.Clien
|
|||||||
ncutils.Log("unable to parse timestamp " + keepalivetime.String())
|
ncutils.Log("unable to parse timestamp " + keepalivetime.String())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if time.Since(keepalivetime) > time.Second*200 { // more than 3+ minutes
|
if time.Since(keepalivetime) > time.Second*120 { // more than 2+ minutes
|
||||||
ncutils.Log("server keepalive not recieved recently, resubscribe to message queue")
|
ncutils.Log("server keepalive not recieved recently, resubscribe to message queue")
|
||||||
err := Resubscribe(client, cfg)
|
err := Resubscribe(client, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -69,6 +69,11 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
|
|||||||
if cfg.Node.LocalRange != "" && cfg.Node.LocalAddress == "" {
|
if cfg.Node.LocalRange != "" && cfg.Node.LocalAddress == "" {
|
||||||
log.Println("local vpn, getting local address from range: " + cfg.Node.LocalRange)
|
log.Println("local vpn, getting local address from range: " + cfg.Node.LocalRange)
|
||||||
cfg.Node.LocalAddress = getLocalIP(cfg.Node)
|
cfg.Node.LocalAddress = getLocalIP(cfg.Node)
|
||||||
|
} else if cfg.Node.LocalAddress == "" {
|
||||||
|
intIP, err := getPrivateAddr()
|
||||||
|
if err == nil {
|
||||||
|
cfg.Node.LocalAddress = intIP
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set endpoint if blank. set to local if local net, retrieve from function if not
|
// set endpoint if blank. set to local if local net, retrieve from function if not
|
||||||
@@ -233,6 +238,8 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
|
|||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else {
|
||||||
|
daemon.Restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
Reference in New Issue
Block a user