lnd.xprv/cmd/lnd/main.go
carla daae8a9944
multi: wrap logger to request shutdown from signal on critical error
This commit adds a shutdown logger which will send a request for
shutdown on critical errors. It uses the signal package to request safe
shutdown of the daemon. Since we init our logs in config validation,
we add a started channel to the signal package to prevent the case where
we have a critical log after the ShutdownLogger has started but before
the daemon has started listening for intercepts. In this case, we just
ignore the shutdown request.
2020-08-24 08:54:34 +02:00

40 lines
887 B
Go

package main
import (
"fmt"
"os"
"github.com/jessevdk/go-flags"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/signal"
)
func main() {
// Load the configuration, and parse any command line options. This
// function will also set up logging properly.
loadedConfig, err := lnd.LoadConfig()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
// Hook interceptor for os signals.
if err := signal.Intercept(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
// Call the "real" main in a nested manner so the defers will properly
// be executed in the case of a graceful shutdown.
err = lnd.Main(
loadedConfig, lnd.ListenerCfg{}, signal.ShutdownChannel(),
)
if err != nil {
if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp {
} else {
_, _ = fmt.Fprintln(os.Stderr, err)
}
os.Exit(1)
}
}