mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-29 11:33:48 +01:00
13b4be31df
* feature: add logging to a file * refactor: move InitLog to util lib * docs: update signal and management docs * chore: update docker compose * set --log-file to console * chore: comment out log volume in docker compose Co-authored-by: mlsmaycon <mlsmaycon@gmail.com>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/spf13/cobra"
|
|
"os"
|
|
"os/signal"
|
|
"runtime"
|
|
)
|
|
|
|
const (
|
|
// ExitSetupFailed defines exit code
|
|
ExitSetupFailed = 1
|
|
)
|
|
|
|
var (
|
|
configPath string
|
|
defaultConfigPath string
|
|
logLevel string
|
|
defaultLogFile string
|
|
logFile string
|
|
|
|
rootCmd = &cobra.Command{
|
|
Use: "wiretrustee-mgmt",
|
|
Short: "",
|
|
Long: "",
|
|
}
|
|
|
|
// 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)
|
|
|
|
defaultConfigPath = "/etc/wiretrustee/management.json"
|
|
defaultLogFile = "/var/log/wiretrustee/management.log"
|
|
if runtime.GOOS == "windows" {
|
|
defaultConfigPath = os.Getenv("PROGRAMDATA") + "\\Wiretrustee\\" + "management.json"
|
|
defaultLogFile = os.Getenv("PROGRAMDATA") + "\\Wiretrustee\\" + "management.log"
|
|
}
|
|
rootCmd.PersistentFlags().StringVar(&configPath, "config", defaultConfigPath, "Wiretrustee config file location to write new config to")
|
|
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "")
|
|
rootCmd.PersistentFlags().StringVar(&logFile, "log-file", defaultLogFile, "sets Wiretrustee log path. If console is specified the the log will be output to stdout")
|
|
rootCmd.AddCommand(mgmtCmd)
|
|
}
|
|
|
|
// 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
|
|
}
|
|
}()
|
|
}
|