99
1010 restProxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
1111 "github.com/lightninglabs/lightning-terminal/perms"
12+ "github.com/lightninglabs/lightning-terminal/status"
1213 "github.com/lightninglabs/lndclient"
1314 "github.com/lightningnetwork/lnd/lncfg"
1415 "github.com/lightningnetwork/lnd/lnrpc"
@@ -32,20 +33,27 @@ var (
3233
3334// Manager manages a set of subServer objects.
3435type Manager struct {
35- servers []* subServerWrapper
36- permsMgr * perms.Manager
37- mu sync.RWMutex
36+ servers []* subServerWrapper
37+ permsMgr * perms.Manager
38+ statusServer * status.Manager
39+ mu sync.RWMutex
3840}
3941
40- // NewManager constructs a new subServerMgr.
41- func NewManager (permsMgr * perms.Manager ) * Manager {
42+ // NewManager constructs a new Manager.
43+ func NewManager (permsMgr * perms.Manager ,
44+ statusServer * status.Manager ) * Manager {
45+
4246 return & Manager {
43- permsMgr : permsMgr ,
47+ permsMgr : permsMgr ,
48+ statusServer : statusServer ,
4449 }
4550}
4651
4752// AddServer adds a new subServer to the manager's set.
4853func (s * Manager ) AddServer (ss SubServer , enable bool ) {
54+ // Register all sub-servers with the status server.
55+ s .statusServer .RegisterSubServer (ss .Name ())
56+
4957 // If the sub-server has explicitly been disabled, then we don't add it
5058 // to the set of servers tracked by the Manager.
5159 if ! enable {
@@ -65,12 +73,15 @@ func (s *Manager) AddServer(ss SubServer, enable bool) {
6573 s .permsMgr .RegisterSubServer (
6674 ss .Name (), ss .Permissions (), ss .WhiteListedURLs (),
6775 )
76+
77+ // Mark the sub-server as enabled with the status manager.
78+ s .statusServer .SetEnabled (ss .Name ())
6879}
6980
7081// StartIntegratedServers starts all the manager's sub-servers that should be
7182// started in integrated mode.
7283func (s * Manager ) StartIntegratedServers (lndClient lnrpc.LightningClient ,
73- lndGrpc * lndclient.GrpcLndServices , withMacaroonService bool ) error {
84+ lndGrpc * lndclient.GrpcLndServices , withMacaroonService bool ) {
7485
7586 s .mu .Lock ()
7687 defer s .mu .Unlock ()
@@ -82,19 +93,24 @@ func (s *Manager) StartIntegratedServers(lndClient lnrpc.LightningClient,
8293
8394 err := ss .startIntegrated (
8495 lndClient , lndGrpc , withMacaroonService ,
96+ func (err error ) {
97+ s .statusServer .SetErrored (
98+ ss .Name (), err .Error (),
99+ )
100+ },
85101 )
86102 if err != nil {
87- return fmt . Errorf ( "unable to start %v in integrated " +
88- "mode: %v" , ss . Name (), err )
103+ s . statusServer . SetErrored ( ss . Name (), err . Error ())
104+ continue
89105 }
90- }
91106
92- return nil
107+ s .statusServer .SetRunning (ss .Name ())
108+ }
93109}
94110
95111// ConnectRemoteSubServers creates connections to all the manager's sub-servers
96112// that are running remotely.
97- func (s * Manager ) ConnectRemoteSubServers () error {
113+ func (s * Manager ) ConnectRemoteSubServers () {
98114 s .mu .Lock ()
99115 defer s .mu .Unlock ()
100116
@@ -105,12 +121,12 @@ func (s *Manager) ConnectRemoteSubServers() error {
105121
106122 err := ss .connectRemote ()
107123 if err != nil {
108- return fmt . Errorf ( "failed to connect to remote %s: %v" ,
109- ss . Name (), err )
124+ s . statusServer . SetErrored ( ss . Name (), err . Error ())
125+ continue
110126 }
111- }
112127
113- return nil
128+ s .statusServer .SetRunning (ss .Name ())
129+ }
114130}
115131
116132// RegisterRPCServices registers all the manager's sub-servers with the given
@@ -301,6 +317,8 @@ func (s *Manager) Stop() error {
301317 log .Errorf ("Error stopping %s: %v" , ss .Name (), err )
302318 returnErr = err
303319 }
320+
321+ s .statusServer .SetStopped (ss .Name ())
304322 }
305323
306324 return returnErr
0 commit comments