mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 07:16:38 +00:00
Added host configurators for Linux, Windows, and macOS. The host configurator will update the peer system configuration directing DNS queries according to its capabilities. Some Linux distributions don't support split (match) DNS or custom ports, and that will be reported to our management system in another PR
96 lines
1.8 KiB
Go
96 lines
1.8 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"runtime"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var installCmd = &cobra.Command{
|
|
Use: "install",
|
|
Short: "installs Netbird service",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
SetFlagsFromEnvVars()
|
|
|
|
cmd.SetOut(cmd.OutOrStdout())
|
|
|
|
err := handleRebrand(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
svcConfig := newSVCConfig()
|
|
|
|
svcConfig.Arguments = []string{
|
|
"service",
|
|
"run",
|
|
"--config",
|
|
configPath,
|
|
"--log-level",
|
|
logLevel,
|
|
}
|
|
|
|
if managementURL != "" {
|
|
svcConfig.Arguments = append(svcConfig.Arguments, "--management-url", managementURL)
|
|
}
|
|
|
|
if logFile != "console" {
|
|
svcConfig.Arguments = append(svcConfig.Arguments, "--log-file", logFile)
|
|
svcConfig.Option["LogOutput"] = true
|
|
svcConfig.Option["LogDirectory"] = filepath.Dir(logFile)
|
|
}
|
|
|
|
if runtime.GOOS == "linux" {
|
|
// Respected only by systemd systems
|
|
svcConfig.Dependencies = []string{"After=network.target syslog.target"}
|
|
}
|
|
|
|
ctx, cancel := context.WithCancel(cmd.Context())
|
|
|
|
s, err := newSVC(newProgram(ctx, cancel), svcConfig)
|
|
if err != nil {
|
|
cmd.PrintErrln(err)
|
|
return err
|
|
}
|
|
|
|
err = s.Install()
|
|
if err != nil {
|
|
cmd.PrintErrln(err)
|
|
return err
|
|
}
|
|
cmd.Println("Netbird service has been installed")
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var uninstallCmd = &cobra.Command{
|
|
Use: "uninstall",
|
|
Short: "uninstalls Netbird service from system",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
SetFlagsFromEnvVars()
|
|
|
|
cmd.SetOut(cmd.OutOrStdout())
|
|
|
|
err := handleRebrand(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
ctx, cancel := context.WithCancel(cmd.Context())
|
|
|
|
s, err := newSVC(newProgram(ctx, cancel), newSVCConfig())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = s.Uninstall()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cmd.Println("Netbird has been uninstalled")
|
|
return nil
|
|
},
|
|
}
|