9
9
10
10
restProxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
11
11
"github.com/lightninglabs/lightning-terminal/perms"
12
+ "github.com/lightninglabs/lightning-terminal/status"
12
13
"github.com/lightninglabs/lndclient"
13
14
"github.com/lightningnetwork/lnd/lncfg"
14
15
"github.com/lightningnetwork/lnd/lnrpc"
@@ -32,20 +33,27 @@ var (
32
33
33
34
// Manager manages a set of subServer objects.
34
35
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
38
40
}
39
41
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
+
42
46
return & Manager {
43
- permsMgr : permsMgr ,
47
+ permsMgr : permsMgr ,
48
+ statusServer : statusServer ,
44
49
}
45
50
}
46
51
47
52
// AddServer adds a new subServer to the manager's set.
48
53
func (s * Manager ) AddServer (ss SubServer , enable bool ) {
54
+ // Register all sub-servers with the status server.
55
+ s .statusServer .RegisterSubServer (ss .Name ())
56
+
49
57
// If the sub-server has explicitly been disabled, then we don't add it
50
58
// to the set of servers tracked by the Manager.
51
59
if ! enable {
@@ -65,12 +73,15 @@ func (s *Manager) AddServer(ss SubServer, enable bool) {
65
73
s .permsMgr .RegisterSubServer (
66
74
ss .Name (), ss .Permissions (), ss .WhiteListedURLs (),
67
75
)
76
+
77
+ // Mark the sub-server as enabled with the status manager.
78
+ s .statusServer .SetEnabled (ss .Name ())
68
79
}
69
80
70
81
// StartIntegratedServers starts all the manager's sub-servers that should be
71
82
// started in integrated mode.
72
83
func (s * Manager ) StartIntegratedServers (lndClient lnrpc.LightningClient ,
73
- lndGrpc * lndclient.GrpcLndServices , withMacaroonService bool ) error {
84
+ lndGrpc * lndclient.GrpcLndServices , withMacaroonService bool ) {
74
85
75
86
s .mu .Lock ()
76
87
defer s .mu .Unlock ()
@@ -82,19 +93,24 @@ func (s *Manager) StartIntegratedServers(lndClient lnrpc.LightningClient,
82
93
83
94
err := ss .startIntegrated (
84
95
lndClient , lndGrpc , withMacaroonService ,
96
+ func (err error ) {
97
+ s .statusServer .SetErrored (
98
+ ss .Name (), err .Error (),
99
+ )
100
+ },
85
101
)
86
102
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
89
105
}
90
- }
91
106
92
- return nil
107
+ s .statusServer .SetRunning (ss .Name ())
108
+ }
93
109
}
94
110
95
111
// ConnectRemoteSubServers creates connections to all the manager's sub-servers
96
112
// that are running remotely.
97
- func (s * Manager ) ConnectRemoteSubServers () error {
113
+ func (s * Manager ) ConnectRemoteSubServers () {
98
114
s .mu .Lock ()
99
115
defer s .mu .Unlock ()
100
116
@@ -105,12 +121,12 @@ func (s *Manager) ConnectRemoteSubServers() error {
105
121
106
122
err := ss .connectRemote ()
107
123
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
110
126
}
111
- }
112
127
113
- return nil
128
+ s .statusServer .SetRunning (ss .Name ())
129
+ }
114
130
}
115
131
116
132
// RegisterRPCServices registers all the manager's sub-servers with the given
@@ -301,6 +317,8 @@ func (s *Manager) Stop() error {
301
317
log .Errorf ("Error stopping %s: %v" , ss .Name (), err )
302
318
returnErr = err
303
319
}
320
+
321
+ s .statusServer .SetStopped (ss .Name ())
304
322
}
305
323
306
324
return returnErr
0 commit comments