mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-25 17:43:38 +01:00
9e8725618e
- dupword checks for duplicate words in the source code - durationcheck checks for two durations multiplied together - forbidigo forbids identifiers - mirror reports wrong mirror patterns of bytes/strings usage - misspell finds commonly misspelled English words in comments - predeclared finds code that shadows one of Go's predeclared identifiers - thelper detects Go test helpers without t.Helper() call and checks the consistency of test helpers
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
"runtime"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/netbirdio/netbird/version"
|
|
)
|
|
|
|
const (
|
|
// ExitSetupFailed defines exit code
|
|
ExitSetupFailed = 1
|
|
)
|
|
|
|
var (
|
|
logLevel string
|
|
defaultLogFile string
|
|
logFile string
|
|
|
|
rootCmd = &cobra.Command{
|
|
Use: "netbird-signal",
|
|
Short: "",
|
|
Long: "",
|
|
Version: version.NetbirdVersion(),
|
|
}
|
|
|
|
// Execution control channel for stopCh signal
|
|
stopCh chan int
|
|
)
|
|
|
|
// Execute executes the root command.
|
|
func Execute() error {
|
|
return rootCmd.Execute()
|
|
}
|
|
|
|
func init() {
|
|
stopCh = make(chan int)
|
|
defaultLogFile = "/var/log/netbird/signal.log"
|
|
defaultSignalSSLDir = "/var/lib/netbird/"
|
|
|
|
if runtime.GOOS == "windows" {
|
|
defaultLogFile = os.Getenv("PROGRAMDATA") + "\\Netbird\\" + "signal.log"
|
|
}
|
|
|
|
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "")
|
|
rootCmd.PersistentFlags().StringVar(&logFile, "log-file", defaultLogFile, "sets Netbird log path. If console is specified the log will be output to stdout")
|
|
rootCmd.AddCommand(runCmd)
|
|
}
|
|
|
|
// SetupCloseHandler handles SIGTERM signal and exits with success
|
|
func SetupCloseHandler() {
|
|
c := make(chan os.Signal, 1)
|
|
signal.Notify(c, os.Interrupt)
|
|
go func() {
|
|
for range c {
|
|
fmt.Println("\r- Ctrl+C pressed in Terminal")
|
|
stopCh <- 0
|
|
}
|
|
}()
|
|
}
|