Merge pull request #663 from gravitl/feature_v0.10.0_windows_adapt

edited windows to new daemon
This commit is contained in:
dcarns 2022-02-02 09:17:06 -05:00 committed by GitHub
commit 147cc18be0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 22 deletions

View file

@ -34,6 +34,7 @@ func SetupWindowsDaemon() error {
return nil return nil
} }
// RestartWindowsDaemon - restarts windows service
func RestartWindowsDaemon() { func RestartWindowsDaemon() {
StopWindowsDaemon() StopWindowsDaemon()
// start daemon, will not restart or start another // start daemon, will not restart or start another
@ -59,6 +60,7 @@ func writeServiceConfig() error {
<name>Netclient</name> <name>Netclient</name>
<description>Connects Windows nodes to one or more Netmaker networks.</description> <description>Connects Windows nodes to one or more Netmaker networks.</description>
<executable>%v</executable> <executable>%v</executable>
<arguments>daemon</arguments>
<log mode="roll"></log> <log mode="roll"></log>
</service> </service>
`, strings.Replace(ncutils.GetNetclientPathSpecific()+"netclient.exe", `\\`, `\`, -1)) `, strings.Replace(ncutils.GetNetclientPathSpecific()+"netclient.exe", `\\`, `\`, -1))

View file

@ -8,7 +8,6 @@ import (
"runtime/debug" "runtime/debug"
"github.com/gravitl/netmaker/netclient/cli_options" "github.com/gravitl/netmaker/netclient/cli_options"
"github.com/gravitl/netmaker/netclient/command"
"github.com/gravitl/netmaker/netclient/ncutils" "github.com/gravitl/netmaker/netclient/ncutils"
"github.com/gravitl/netmaker/netclient/ncwindows" "github.com/gravitl/netmaker/netclient/ncwindows"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -31,15 +30,12 @@ func main() {
ncutils.CheckUID() ncutils.CheckUID()
ncutils.CheckWG() ncutils.CheckWG()
} }
if len(os.Args) == 1 && ncutils.IsWindows() {
command.RunUserspaceDaemon()
} else {
err := app.Run(os.Args) err := app.Run(os.Args)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }
}
func setGarbageCollection() { func setGarbageCollection() {
_, gcset := os.LookupEnv("GOGC") _, gcset := os.LookupEnv("GOGC")

View file

@ -18,17 +18,22 @@ func InitWindows() {
if wdErr != nil { if wdErr != nil {
log.Fatal("failed to get current directory..") log.Fatal("failed to get current directory..")
} }
_, dataNetclientErr := os.Stat(ncutils.GetNetclientPathSpecific() + "netclient.exe")
_, currentNetclientErr := os.Stat(wdPath + "\\netclient.exe")
if os.IsNotExist(dataNetclientErr) { // check and see if netclient.exe is in appdata dataPath := ncutils.GetNetclientPathSpecific() + "netclient.exe"
currentPath := wdPath + "\\netclient.exe"
_, dataNetclientErr := os.Stat(dataPath)
_, currentNetclientErr := os.Stat(currentPath)
if currentPath == dataPath && currentNetclientErr == nil {
ncutils.Log("netclient.exe is in proper location, " + currentPath)
} else if os.IsNotExist(dataNetclientErr) { // check and see if netclient.exe is in appdata
if currentNetclientErr == nil { // copy it if it exists locally if currentNetclientErr == nil { // copy it if it exists locally
input, err := os.ReadFile(wdPath + "\\netclient.exe") input, err := os.ReadFile(currentPath)
if err != nil { if err != nil {
log.Println("failed to find netclient.exe") log.Println("failed to find netclient.exe")
return return
} }
if err = os.WriteFile(ncutils.GetNetclientPathSpecific()+"netclient.exe", input, 0600); err != nil { if err = os.WriteFile(dataPath, input, 0700); err != nil {
log.Println("failed to copy netclient.exe to", ncutils.GetNetclientPath()) log.Println("failed to copy netclient.exe to", ncutils.GetNetclientPath())
return return
} }

View file

@ -53,6 +53,9 @@ func SetWGKeyConfig(network string, serveraddr string) error {
// ApplyWGQuickConf - applies wg-quick commands if os supports // ApplyWGQuickConf - applies wg-quick commands if os supports
func ApplyWGQuickConf(confPath string, ifacename string) error { func ApplyWGQuickConf(confPath string, ifacename string) error {
if ncutils.IsWindows() {
return ApplyWindowsConf(confPath)
} else {
_, err := os.Stat(confPath) _, err := os.Stat(confPath)
if err != nil { if err != nil {
ncutils.Log(confPath + " does not exist " + err.Error()) ncutils.Log(confPath + " does not exist " + err.Error())
@ -62,9 +65,9 @@ func ApplyWGQuickConf(confPath string, ifacename string) error {
ncutils.RunCmd("wg-quick down "+confPath, true) ncutils.RunCmd("wg-quick down "+confPath, true)
} }
_, err = ncutils.RunCmd("wg-quick up "+confPath, true) _, err = ncutils.RunCmd("wg-quick up "+confPath, true)
return err return err
} }
}
// ApplyMacOSConf - applies system commands similar to wg-quick using golang for MacOS // ApplyMacOSConf - applies system commands similar to wg-quick using golang for MacOS
func ApplyMacOSConf(node models.Node, ifacename string, confPath string) error { func ApplyMacOSConf(node models.Node, ifacename string, confPath string) error {