mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-15 03:11:02 +01:00
Print out errors on exit from cmd
This commit is contained in:
parent
c057fbd4f4
commit
86f1724efa
@ -60,10 +60,12 @@ var (
|
|||||||
cobraConfig *Config
|
cobraConfig *Config
|
||||||
cfgFile string
|
cfgFile string
|
||||||
rootCmd = &cobra.Command{
|
rootCmd = &cobra.Command{
|
||||||
Use: "relay",
|
Use: "relay",
|
||||||
Short: "Relay service",
|
Short: "Relay service",
|
||||||
Long: "Relay service for Netbird agents",
|
Long: "Relay service for Netbird agents",
|
||||||
RunE: execute,
|
RunE: execute,
|
||||||
|
SilenceUsage: true,
|
||||||
|
SilenceErrors: true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -128,7 +130,7 @@ func execute(cmd *cobra.Command, args []string) error {
|
|||||||
err = cfg.Validate()
|
err = cfg.Validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("invalid config: %s", err)
|
log.Errorf("invalid config: %s", err)
|
||||||
os.Exit(1)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
metricsServer, err := metrics.NewServer(metricsPort, "")
|
metricsServer, err := metrics.NewServer(metricsPort, "")
|
||||||
@ -170,7 +172,7 @@ func execute(cmd *cobra.Command, args []string) error {
|
|||||||
log.Infof("server will be available on: %s", srv.InstanceURL())
|
log.Infof("server will be available on: %s", srv.InstanceURL())
|
||||||
go func() {
|
go func() {
|
||||||
if err := srv.Listen(srvListenerCfg); err != nil {
|
if err := srv.Listen(srvListenerCfg); err != nil {
|
||||||
log.Errorf("failed to bind server: %s", err)
|
log.Fatalf("failed to bind server: %s", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -185,6 +187,7 @@ func execute(cmd *cobra.Command, args []string) error {
|
|||||||
shutDownErrors = multierror.Append(shutDownErrors, fmt.Errorf("failed to close server: %s", err))
|
shutDownErrors = multierror.Append(shutDownErrors, fmt.Errorf("failed to close server: %s", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Infof("shutting down metrics server")
|
||||||
if err := metricsServer.Close(); err != nil {
|
if err := metricsServer.Close(); err != nil {
|
||||||
shutDownErrors = multierror.Append(shutDownErrors, fmt.Errorf("failed to close metrics server: %v", err))
|
shutDownErrors = multierror.Append(shutDownErrors, fmt.Errorf("failed to close metrics server: %v", err))
|
||||||
}
|
}
|
||||||
@ -200,8 +203,7 @@ func setupTLSCertManager(letsencryptDataDir string, letsencryptDomains ...string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := rootCmd.Execute()
|
if err := rootCmd.Execute(); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("%v", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user