diff --git a/lnd.go b/lnd.go index 5d5606d8..38ad62a4 100644 --- a/lnd.go +++ b/lnd.go @@ -19,6 +19,7 @@ import ( flags "github.com/btcsuite/go-flags" proxy "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/lightningnetwork/lnd/autopilot" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnwallet" @@ -286,11 +287,33 @@ func lndMain() error { return err } + // 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. + var pilot *autopilot.Agent + if cfg.Autopilot.Active { + pilot, err := initAutoPilot(server, cfg.Autopilot) + if err != nil { + ltndLog.Errorf("unable to create autopilot agent: %v", + err) + return err + } + if err := pilot.Start(); err != nil { + ltndLog.Errorf("unable to start autopilot agent: %v", + err) + return err + } + } + addInterruptHandler(func() { ltndLog.Infof("Gracefully shutting down the server...") rpcServer.Stop() fundingMgr.Stop() server.Stop() + + if pilot != nil { + pilot.Stop() + } + server.WaitForShutdown() })