mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-19 00:36:38 +00:00
cleanup
This commit is contained in:
@@ -28,7 +28,6 @@ var (
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "path to JSON configuration file (optional, can use env vars instead)")
|
||||
|
||||
// Set version information
|
||||
rootCmd.Version = version.Short()
|
||||
rootCmd.SetVersionTemplate("{{.Version}}\n")
|
||||
}
|
||||
@@ -39,14 +38,12 @@ func Execute() error {
|
||||
}
|
||||
|
||||
func run(cmd *cobra.Command, args []string) error {
|
||||
// Load configuration from file or environment variables
|
||||
config, err := proxy.LoadFromFileOrEnv(configFile)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load configuration: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Set log level
|
||||
setupLogging(config.LogLevel)
|
||||
|
||||
log.Infof("Starting Netbird Proxy - %s", version.Short())
|
||||
@@ -55,14 +52,12 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
log.Infof("Listen Address: %s", config.ReverseProxy.ListenAddress)
|
||||
log.Infof("Log Level: %s", config.LogLevel)
|
||||
|
||||
// Create server instance
|
||||
server, err := proxy.NewServer(config)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create server: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Start server in a goroutine
|
||||
serverErrors := make(chan error, 1)
|
||||
go func() {
|
||||
if err := server.Start(); err != nil {
|
||||
@@ -70,11 +65,9 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}()
|
||||
|
||||
// Set up signal handler for graceful shutdown
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
// Wait for either an error or shutdown signal
|
||||
select {
|
||||
case err := <-serverErrors:
|
||||
log.Fatalf("Server error: %v", err)
|
||||
@@ -83,11 +76,9 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
log.Infof("Received signal: %v", sig)
|
||||
}
|
||||
|
||||
// Create shutdown context with timeout
|
||||
ctx, cancel := context.WithTimeout(context.Background(), config.ShutdownTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Gracefully stop the server
|
||||
if err := server.Stop(ctx); err != nil {
|
||||
log.Fatalf("Failed to stop server gracefully: %v", err)
|
||||
return err
|
||||
@@ -98,13 +89,11 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func setupLogging(level string) {
|
||||
// Set log format
|
||||
log.SetFormatter(&log.TextFormatter{
|
||||
FullTimestamp: true,
|
||||
TimestampFormat: "2006-01-02 15:04:05",
|
||||
})
|
||||
|
||||
// Set log level
|
||||
switch level {
|
||||
case "debug":
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
Reference in New Issue
Block a user