Skip to content

Commit 61bca8a

Browse files
committed
subservers+terminal: integrate status server
Pass the status manager to the sub-server manager so that the sub-server manager can inform the status manager of any sub-servers that have started or failed to start.
1 parent 380d5b8 commit 61bca8a

File tree

3 files changed

+39
-31
lines changed

3 files changed

+39
-31
lines changed

subservers/manager.go

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
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,15 +33,19 @@ var (
3233

3334
// Manager manages a set of subServer objects.
3435
type 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

@@ -55,12 +60,13 @@ func (s *Manager) AddServer(ss SubServer) {
5560
})
5661

5762
s.permsMgr.RegisterSubServer(ss.Name(), ss.Permissions())
63+
s.statusServer.RegisterSubServer(ss.Name())
5864
}
5965

6066
// StartIntegratedServers starts all the manager's sub-servers that should be
6167
// started in integrated mode.
6268
func (s *Manager) StartIntegratedServers(lndClient lnrpc.LightningClient,
63-
lndGrpc *lndclient.GrpcLndServices, withMacaroonService bool) error {
69+
lndGrpc *lndclient.GrpcLndServices, withMacaroonService bool) {
6470

6571
s.mu.Lock()
6672
defer s.mu.Unlock()
@@ -72,19 +78,24 @@ func (s *Manager) StartIntegratedServers(lndClient lnrpc.LightningClient,
7278

7379
err := ss.startIntegrated(
7480
lndClient, lndGrpc, withMacaroonService,
81+
func(err error) {
82+
s.statusServer.SetErrored(
83+
ss.Name(), err.Error(),
84+
)
85+
},
7586
)
7687
if err != nil {
77-
return fmt.Errorf("unable to start %v in integrated "+
78-
"mode: %v", ss.Name(), err)
88+
s.statusServer.SetErrored(ss.Name(), err.Error())
89+
continue
7990
}
80-
}
8191

82-
return nil
92+
s.statusServer.SetRunning(ss.Name())
93+
}
8394
}
8495

8596
// ConnectRemoteSubServers creates connections to all the manager's sub-servers
8697
// that are running remotely.
87-
func (s *Manager) ConnectRemoteSubServers() error {
98+
func (s *Manager) ConnectRemoteSubServers() {
8899
s.mu.Lock()
89100
defer s.mu.Unlock()
90101

@@ -95,12 +106,12 @@ func (s *Manager) ConnectRemoteSubServers() error {
95106

96107
err := ss.connectRemote()
97108
if err != nil {
98-
return fmt.Errorf("failed to connect to remote %s: %v",
99-
ss.Name(), err)
109+
s.statusServer.SetErrored(ss.Name(), err.Error())
110+
continue
100111
}
101-
}
102112

103-
return nil
113+
s.statusServer.SetRunning(ss.Name())
114+
}
104115
}
105116

106117
// RegisterRPCServices registers all the manager's sub-servers with the given
@@ -291,6 +302,8 @@ func (s *Manager) Stop() error {
291302
log.Errorf("Error stopping %s: %v", ss.Name(), err)
292303
returnErr = err
293304
}
305+
306+
s.statusServer.SetStopped(ss.Name())
294307
}
295308

296309
return returnErr

subservers/subserver.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ func (s *subServerWrapper) stop() error {
9999

100100
// startIntegrated starts the subServer in integrated mode.
101101
func (s *subServerWrapper) startIntegrated(lndClient lnrpc.LightningClient,
102-
lndGrpc *lndclient.GrpcLndServices, withMacaroonService bool) error {
102+
lndGrpc *lndclient.GrpcLndServices, withMacaroonService bool,
103+
onError func(error)) error {
103104

104105
err := s.Start(lndClient, lndGrpc, withMacaroonService)
105106
if err != nil {
@@ -121,11 +122,11 @@ func (s *subServerWrapper) startIntegrated(lndClient lnrpc.LightningClient,
121122
// happens. We don't need to try to stop it again.
122123
s.setStarted(false)
123124

124-
err = fmt.Errorf("received critical error from "+
125-
"sub-server (%s), shutting down: %v",
126-
s.Name(), err)
127-
128-
log.Error(err)
125+
onError(
126+
fmt.Errorf("received critical error from "+
127+
"sub-server (%s), shutting down: %v",
128+
s.Name(), err),
129+
)
129130

130131
case <-s.quit:
131132
}

terminal.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (g *LightningTerminal) Run() error {
231231

232232
// Create the instances of our subservers now so we can hook them up to
233233
// lnd once it's fully started.
234-
g.subServerMgr = subservers.NewManager(g.permsMgr)
234+
g.subServerMgr = subservers.NewManager(g.permsMgr, g.statusMgr)
235235

236236
// Register our sub-servers. This must be done before the REST proxy is
237237
// set up so that the correct REST handlers are registered.
@@ -498,10 +498,7 @@ func (g *LightningTerminal) start() error {
498498

499499
// Initialise any connections to sub-servers that we are running in
500500
// remote mode.
501-
if err := g.subServerMgr.ConnectRemoteSubServers(); err != nil {
502-
return fmt.Errorf("error connecting to remote sub-servers: %v",
503-
err)
504-
}
501+
g.subServerMgr.ConnectRemoteSubServers()
505502

506503
// Now start the RPC proxy that will handle all incoming gRPC, grpc-web
507504
// and REST requests.
@@ -561,12 +558,9 @@ func (g *LightningTerminal) start() error {
561558

562559
// Both connection types are ready now, let's start our sub-servers if
563560
// they should be started locally as an integrated service.
564-
err = g.subServerMgr.StartIntegratedServers(
561+
g.subServerMgr.StartIntegratedServers(
565562
g.basicClient, g.lndClient, createDefaultMacaroons,
566563
)
567-
if err != nil {
568-
return fmt.Errorf("could not start subservers: %v", err)
569-
}
570564

571565
err = g.startInternalSubServers(createDefaultMacaroons)
572566
if err != nil {

0 commit comments

Comments
 (0)