@@ -235,7 +235,12 @@ func (g *LightningTerminal) Run() error {
235235 // Register LND, LiT and Accounts with the status manager.
236236 g .statusMgr .RegisterAndEnableSubServer (subservers .LND )
237237 g .statusMgr .RegisterAndEnableSubServer (subservers .LIT )
238- g .statusMgr .RegisterAndEnableSubServer (subservers .ACCOUNTS )
238+ g .statusMgr .RegisterSubServer (subservers .ACCOUNTS )
239+
240+ // Also enable the accounts subserver if it's not disabled.
241+ if ! g .cfg .Accounts .Disable {
242+ g .statusMgr .SetEnabled (subservers .ACCOUNTS )
243+ }
239244
240245 // Create the instances of our subservers now so we can hook them up to
241246 // lnd once it's fully started.
@@ -849,23 +854,41 @@ func (g *LightningTerminal) startInternalSubServers(
849854 return nil
850855 }
851856
857+ // Even if the accounts service fails on the Start function, or the
858+ // accounts service is disabled, we still want to call Stop function as
859+ // this closes the contexts and the db store which were opened with the
860+ // accounts.NewService function call in the LightningTerminal start
861+ // function above.
862+ closeAccountService := func () {
863+ if err := g .accountService .Stop (); err != nil {
864+ // We only log the error if we fail to stop the service,
865+ // as it's not critical that this succeeds in order to
866+ // keep litd running
867+ log .Errorf ("Error stopping account service: %v" , err )
868+ }
869+ }
870+
852871 log .Infof ("Starting LiT account service" )
853- err = g .accountService .Start (
854- g .lndClient .Client , g .lndClient .Router ,
855- g .lndClient .ChainParams ,
856- )
857- if err != nil {
858- log .Errorf ("error starting account service: %v, disabling " +
859- "account service" , err )
872+ if ! g .cfg .Accounts .Disable {
873+ err = g .accountService .Start (
874+ g .lndClient .Client , g .lndClient .Router ,
875+ g .lndClient .ChainParams ,
876+ )
877+ if err != nil {
878+ log .Errorf ("error starting account service: %v, " +
879+ "disabling account service" , err )
880+
881+ g .statusMgr .SetErrored (subservers .ACCOUNTS , err .Error ())
882+
883+ closeAccountService ()
884+ } else {
885+ g .statusMgr .SetRunning (subservers .ACCOUNTS )
860886
861- g .statusMgr .SetErrored (subservers .ACCOUNTS , err .Error ())
887+ g .accountServiceStarted = true
888+ }
862889 } else {
863- g . statusMgr . SetRunning ( subservers . ACCOUNTS )
890+ closeAccountService ( )
864891 }
865- // Even if we error on accountService.Start, we still want to mark the
866- // service as started so that we can properly shut it down in the
867- // shutdownSubServers call.
868- g .accountServiceStarted = true
869892
870893 requestLogger , err := firewall .NewRequestLogger (
871894 g .cfg .Firewall .RequestLogger , g .firewallDB ,
@@ -952,7 +975,12 @@ func (g *LightningTerminal) registerSubDaemonGrpcServers(server *grpc.Server,
952975 litrpc .RegisterStatusServer (server , g .statusMgr )
953976 } else {
954977 litrpc .RegisterSessionsServer (server , g .sessionRpcServer )
955- litrpc .RegisterAccountsServer (server , g .accountRpcServer )
978+
979+ if ! g .cfg .Accounts .Disable {
980+ litrpc .RegisterAccountsServer (
981+ server , g .accountRpcServer ,
982+ )
983+ }
956984 }
957985
958986 litrpc .RegisterFirewallServer (server , g .sessionRpcServer )
@@ -979,11 +1007,13 @@ func (g *LightningTerminal) RegisterRestSubserver(ctx context.Context,
9791007 return err
9801008 }
9811009
982- err = litrpc .RegisterAccountsHandlerFromEndpoint (
983- ctx , mux , endpoint , dialOpts ,
984- )
985- if err != nil {
986- return err
1010+ if ! g .cfg .Accounts .Disable {
1011+ err = litrpc .RegisterAccountsHandlerFromEndpoint (
1012+ ctx , mux , endpoint , dialOpts ,
1013+ )
1014+ if err != nil {
1015+ return err
1016+ }
9871017 }
9881018
9891019 err = litrpc .RegisterFirewallHandlerFromEndpoint (
0 commit comments