lnd+cmd: move interrupt into cmd

If the main package is used as a library, we don't want it to
register interrupt signals itself. Rather we want to pass in the
shutdown channel manually. We do this in the cmd now.
This commit is contained in:
Oliver Gugger
2020-04-30 09:42:28 +02:00
parent 7158103d4d
commit 620eaa3199
2 changed files with 15 additions and 10 deletions

View File

@@ -4,8 +4,9 @@ import (
"fmt"
"os"
flags "github.com/jessevdk/go-flags"
"github.com/jessevdk/go-flags"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/signal"
)
func main() {
@@ -17,9 +18,15 @@ func main() {
os.Exit(1)
}
// Hook interceptor for os signals.
signal.Intercept()
// 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{}); err != nil {
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)