mirror of
https://github.com/gravitl/netmaker.git
synced 2025-02-27 09:36:08 +08:00
edited windows to new daemon
This commit is contained in:
parent
03a30b6bbc
commit
f279245f9e
4 changed files with 28 additions and 22 deletions
|
@ -34,6 +34,7 @@ func SetupWindowsDaemon() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// RestartWindowsDaemon - restarts windows service
|
||||
func RestartWindowsDaemon() {
|
||||
StopWindowsDaemon()
|
||||
// start daemon, will not restart or start another
|
||||
|
@ -59,6 +60,7 @@ func writeServiceConfig() error {
|
|||
<name>Netclient</name>
|
||||
<description>Connects Windows nodes to one or more Netmaker networks.</description>
|
||||
<executable>%v</executable>
|
||||
<arguments>daemon</arguments>
|
||||
<log mode="roll"></log>
|
||||
</service>
|
||||
`, strings.Replace(ncutils.GetNetclientPathSpecific()+"netclient.exe", `\\`, `\`, -1))
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"runtime/debug"
|
||||
|
||||
"github.com/gravitl/netmaker/netclient/cli_options"
|
||||
"github.com/gravitl/netmaker/netclient/command"
|
||||
"github.com/gravitl/netmaker/netclient/ncutils"
|
||||
"github.com/gravitl/netmaker/netclient/ncwindows"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
@ -31,13 +30,10 @@ func main() {
|
|||
ncutils.CheckUID()
|
||||
ncutils.CheckWG()
|
||||
}
|
||||
if len(os.Args) == 1 && ncutils.IsWindows() {
|
||||
command.RunUserspaceDaemon()
|
||||
} else {
|
||||
err := app.Run(os.Args)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err := app.Run(os.Args)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,17 +18,22 @@ func InitWindows() {
|
|||
if wdErr != nil {
|
||||
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
|
||||
input, err := os.ReadFile(wdPath + "\\netclient.exe")
|
||||
input, err := os.ReadFile(currentPath)
|
||||
if err != nil {
|
||||
log.Println("failed to find netclient.exe")
|
||||
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())
|
||||
return
|
||||
}
|
||||
|
|
|
@ -53,17 +53,20 @@ func SetWGKeyConfig(network string, serveraddr string) error {
|
|||
|
||||
// ApplyWGQuickConf - applies wg-quick commands if os supports
|
||||
func ApplyWGQuickConf(confPath string, ifacename string) error {
|
||||
_, err := os.Stat(confPath)
|
||||
if err != nil {
|
||||
ncutils.Log(confPath + " does not exist " + err.Error())
|
||||
if ncutils.IsWindows() {
|
||||
return ApplyWindowsConf(confPath)
|
||||
} else {
|
||||
_, err := os.Stat(confPath)
|
||||
if err != nil {
|
||||
ncutils.Log(confPath + " does not exist " + err.Error())
|
||||
return err
|
||||
}
|
||||
if ncutils.IfaceExists(ifacename) {
|
||||
ncutils.RunCmd("wg-quick down "+confPath, true)
|
||||
}
|
||||
_, err = ncutils.RunCmd("wg-quick up "+confPath, true)
|
||||
return err
|
||||
}
|
||||
if ncutils.IfaceExists(ifacename) {
|
||||
ncutils.RunCmd("wg-quick down "+confPath, true)
|
||||
}
|
||||
_, err = ncutils.RunCmd("wg-quick up "+confPath, true)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// ApplyMacOSConf - applies system commands similar to wg-quick using golang for MacOS
|
||||
|
|
Loading…
Reference in a new issue