lnd: switch to lnd signal package
This commit is contained in:
parent
aaf0c228d5
commit
95440bc723
37
lnd.go
37
lnd.go
|
@ -35,7 +35,6 @@ import (
|
||||||
|
|
||||||
proxy "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
proxy "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||||
flags "github.com/jessevdk/go-flags"
|
flags "github.com/jessevdk/go-flags"
|
||||||
"github.com/lightningnetwork/lnd/autopilot"
|
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/lncfg"
|
"github.com/lightningnetwork/lnd/lncfg"
|
||||||
|
@ -44,6 +43,7 @@ import (
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/macaroons"
|
"github.com/lightningnetwork/lnd/macaroons"
|
||||||
|
"github.com/lightningnetwork/lnd/signal"
|
||||||
"github.com/lightningnetwork/lnd/walletunlocker"
|
"github.com/lightningnetwork/lnd/walletunlocker"
|
||||||
"github.com/roasbeef/btcd/btcec"
|
"github.com/roasbeef/btcd/btcec"
|
||||||
"github.com/roasbeef/btcd/wire"
|
"github.com/roasbeef/btcd/wire"
|
||||||
|
@ -62,7 +62,6 @@ var (
|
||||||
Commit string
|
Commit string
|
||||||
|
|
||||||
cfg *config
|
cfg *config
|
||||||
shutdownChannel = make(chan struct{})
|
|
||||||
registeredChains = newChainRegistry()
|
registeredChains = newChainRegistry()
|
||||||
|
|
||||||
macaroonDatabaseDir string
|
macaroonDatabaseDir string
|
||||||
|
@ -94,6 +93,8 @@ var (
|
||||||
// defers created in the top-level scope of a main method aren't executed if
|
// defers created in the top-level scope of a main method aren't executed if
|
||||||
// os.Exit() is called.
|
// os.Exit() is called.
|
||||||
func lndMain() error {
|
func lndMain() error {
|
||||||
|
defer ltndLog.Info("Shutdown complete")
|
||||||
|
|
||||||
// Load the configuration, and parse any command line options. This
|
// Load the configuration, and parse any command line options. This
|
||||||
// function will also set up logging properly.
|
// function will also set up logging properly.
|
||||||
loadedConfig, err := loadConfig()
|
loadedConfig, err := loadConfig()
|
||||||
|
@ -500,6 +501,7 @@ func lndMain() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
server.fundingMgr = fundingMgr
|
server.fundingMgr = fundingMgr
|
||||||
|
defer fundingMgr.Stop()
|
||||||
|
|
||||||
// Check macaroon authentication if macaroons aren't disabled.
|
// Check macaroon authentication if macaroons aren't disabled.
|
||||||
if macaroonService != nil {
|
if macaroonService != nil {
|
||||||
|
@ -517,6 +519,7 @@ func lndMain() error {
|
||||||
if err := rpcServer.Start(); err != nil {
|
if err := rpcServer.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer rpcServer.Stop()
|
||||||
|
|
||||||
grpcServer := grpc.NewServer(serverOpts...)
|
grpcServer := grpc.NewServer(serverOpts...)
|
||||||
lnrpc.RegisterLightningServer(grpcServer, rpcServer)
|
lnrpc.RegisterLightningServer(grpcServer, rpcServer)
|
||||||
|
@ -574,18 +577,9 @@ func lndMain() error {
|
||||||
ltndLog.Infof("Waiting for chain backend to finish sync, "+
|
ltndLog.Infof("Waiting for chain backend to finish sync, "+
|
||||||
"start_height=%v", bestHeight)
|
"start_height=%v", bestHeight)
|
||||||
|
|
||||||
// We'll add an interrupt handler in order to process shutdown
|
|
||||||
// requests while the chain backend syncs.
|
|
||||||
addInterruptHandler(func() {
|
|
||||||
rpcServer.Stop()
|
|
||||||
fundingMgr.Stop()
|
|
||||||
})
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
if !signal.Alive() {
|
||||||
case <-shutdownChannel:
|
|
||||||
return nil
|
return nil
|
||||||
default:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
synced, _, err := activeChainControl.wallet.IsSynced()
|
synced, _, err := activeChainControl.wallet.IsSynced()
|
||||||
|
@ -615,10 +609,10 @@ func lndMain() error {
|
||||||
srvrLog.Errorf("unable to start server: %v\n", err)
|
srvrLog.Errorf("unable to start server: %v\n", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer server.Stop()
|
||||||
|
|
||||||
// Now that the server has started, if the autopilot mode is currently
|
// Now that the server has started, if the autopilot mode is currently
|
||||||
// active, then we'll initialize a fresh instance of it and start it.
|
// active, then we'll initialize a fresh instance of it and start it.
|
||||||
var pilot *autopilot.Agent
|
|
||||||
if cfg.Autopilot.Active {
|
if cfg.Autopilot.Active {
|
||||||
pilot, err := initAutoPilot(server, cfg.Autopilot)
|
pilot, err := initAutoPilot(server, cfg.Autopilot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -631,21 +625,12 @@ func lndMain() error {
|
||||||
err)
|
err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer pilot.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
addInterruptHandler(func() {
|
|
||||||
rpcServer.Stop()
|
|
||||||
fundingMgr.Stop()
|
|
||||||
if pilot != nil {
|
|
||||||
pilot.Stop()
|
|
||||||
}
|
|
||||||
server.Stop()
|
|
||||||
})
|
|
||||||
|
|
||||||
// Wait for shutdown signal from either a graceful server stop or from
|
// Wait for shutdown signal from either a graceful server stop or from
|
||||||
// the interrupt handler.
|
// the interrupt handler.
|
||||||
<-shutdownChannel
|
<-signal.ShutdownChannel()
|
||||||
ltndLog.Info("Shutdown complete")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1036,7 +1021,7 @@ func waitForWalletPassword(grpcEndpoints, restEndpoints []net.Addr,
|
||||||
// Don't leave the file open in case the new wallet
|
// Don't leave the file open in case the new wallet
|
||||||
// could not be created for whatever reason.
|
// could not be created for whatever reason.
|
||||||
if err := loader.UnloadWallet(); err != nil {
|
if err := loader.UnloadWallet(); err != nil {
|
||||||
ltndLog.Errorf("Could not unload new " +
|
ltndLog.Errorf("Could not unload new "+
|
||||||
"wallet: %v", err)
|
"wallet: %v", err)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1061,7 +1046,7 @@ func waitForWalletPassword(grpcEndpoints, restEndpoints []net.Addr,
|
||||||
}
|
}
|
||||||
return walletInitParams, nil
|
return walletInitParams, nil
|
||||||
|
|
||||||
case <-shutdownChannel:
|
case <-signal.ShutdownChannel():
|
||||||
return nil, fmt.Errorf("shutting down")
|
return nil, fmt.Errorf("shutting down")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user