lnd.xprv/cmd/lnd/main.go
Hampus Sjöberg ada1bc701c signal: handle shutdown properly
This addresses issues related to the mobile lnd builds, where
calling `stopDaemon` and subsequently calling LndMobile's `Start`
results in crash.
2021-03-18 12:54:25 +01:00

43 lines
1013 B
Go

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