@@ -235,7 +235,12 @@ func (g *LightningTerminal) Run() error {
235
235
// Register LND, LiT and Accounts with the status manager.
236
236
g .statusMgr .RegisterAndEnableSubServer (subservers .LND )
237
237
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
+ }
239
244
240
245
// Create the instances of our subservers now so we can hook them up to
241
246
// lnd once it's fully started.
@@ -849,23 +854,41 @@ func (g *LightningTerminal) startInternalSubServers(
849
854
return nil
850
855
}
851
856
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
+
852
871
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 )
860
886
861
- g .statusMgr .SetErrored (subservers .ACCOUNTS , err .Error ())
887
+ g .accountServiceStarted = true
888
+ }
862
889
} else {
863
- g . statusMgr . SetRunning ( subservers . ACCOUNTS )
890
+ closeAccountService ( )
864
891
}
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
869
892
870
893
requestLogger , err := firewall .NewRequestLogger (
871
894
g .cfg .Firewall .RequestLogger , g .firewallDB ,
@@ -952,7 +975,12 @@ func (g *LightningTerminal) registerSubDaemonGrpcServers(server *grpc.Server,
952
975
litrpc .RegisterStatusServer (server , g .statusMgr )
953
976
} else {
954
977
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
+ }
956
984
}
957
985
958
986
litrpc .RegisterFirewallServer (server , g .sessionRpcServer )
@@ -979,11 +1007,13 @@ func (g *LightningTerminal) RegisterRestSubserver(ctx context.Context,
979
1007
return err
980
1008
}
981
1009
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
+ }
987
1017
}
988
1018
989
1019
err = litrpc .RegisterFirewallHandlerFromEndpoint (
0 commit comments