From ba33572ec9bb761491b81470f244ccdeea69bb57 Mon Sep 17 00:00:00 2001 From: Krzysztof Nazarewski Date: Tue, 12 Mar 2024 18:29:19 +0100 Subject: [PATCH] add --service/-s flag for specifying system service name (#1691) --- client/cmd/root.go | 8 ++++++++ client/cmd/service.go | 8 +------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/client/cmd/root.go b/client/cmd/root.go index b3a924016..c3ff0a3c8 100644 --- a/client/cmd/root.go +++ b/client/cmd/root.go @@ -61,6 +61,7 @@ var ( serverSSHAllowed bool interfaceName string wireguardPort uint16 + serviceName string autoConnectDisabled bool rootCmd = &cobra.Command{ Use: "netbird", @@ -100,9 +101,16 @@ func init() { if runtime.GOOS == "windows" { defaultDaemonAddr = "tcp://127.0.0.1:41731" } + + defaultServiceName := "netbird" + if runtime.GOOS == "windows" { + defaultServiceName = "Netbird" + } + rootCmd.PersistentFlags().StringVar(&daemonAddr, "daemon-addr", defaultDaemonAddr, "Daemon service address to serve CLI requests [unix|tcp]://[path|host:port]") rootCmd.PersistentFlags().StringVarP(&managementURL, "management-url", "m", "", fmt.Sprintf("Management Service URL [http|https]://[host]:[port] (default \"%s\")", internal.DefaultManagementURL)) rootCmd.PersistentFlags().StringVar(&adminURL, "admin-url", "", fmt.Sprintf("Admin Panel URL [http|https]://[host]:[port] (default \"%s\")", internal.DefaultAdminURL)) + rootCmd.PersistentFlags().StringVarP(&serviceName, "service", "s", defaultServiceName, "Netbird system service name") rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", defaultConfigPath, "Netbird config file location") rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "info", "sets Netbird log level") rootCmd.PersistentFlags().StringVar(&logFile, "log-file", defaultLogFile, "sets Netbird log path. If console is specified the log will be output to stdout") diff --git a/client/cmd/service.go b/client/cmd/service.go index 18fe5d621..5c60744f9 100644 --- a/client/cmd/service.go +++ b/client/cmd/service.go @@ -2,8 +2,6 @@ package cmd import ( "context" - "runtime" - "github.com/kardianos/service" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -24,12 +22,8 @@ func newProgram(ctx context.Context, cancel context.CancelFunc) *program { } func newSVCConfig() *service.Config { - name := "netbird" - if runtime.GOOS == "windows" { - name = "Netbird" - } return &service.Config{ - Name: name, + Name: serviceName, DisplayName: "Netbird", Description: "A WireGuard-based mesh network that connects your devices into a single private network.", Option: make(service.KeyValue),