mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-18 22:34:22 +01:00
handle clean shutdown
This commit is contained in:
@@ -66,6 +66,10 @@ func (c *ClnPlugin) Start() {
|
||||
c.setupLogging()
|
||||
go c.listenRequests()
|
||||
<-c.done
|
||||
s := c.server
|
||||
if s != nil {
|
||||
<-s.completed
|
||||
}
|
||||
}
|
||||
|
||||
// Stops the cln plugin. Drops any remaining work immediately.
|
||||
|
||||
@@ -2,11 +2,20 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/breez/lspd/cln_plugin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
plugin := cln_plugin.NewClnPlugin(os.Stdin, os.Stdout)
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-c
|
||||
// Stop everything gracefully on stop signal
|
||||
plugin.Stop()
|
||||
}()
|
||||
plugin.Start()
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ type server struct {
|
||||
newSubscriber chan struct{}
|
||||
started chan struct{}
|
||||
done chan struct{}
|
||||
completed chan struct{}
|
||||
startError chan error
|
||||
sendQueue chan *htlcAcceptedMsg
|
||||
recvQueue chan *htlcResultMsg
|
||||
@@ -76,6 +77,7 @@ func (s *server) Start() error {
|
||||
}
|
||||
|
||||
s.done = make(chan struct{})
|
||||
s.completed = make(chan struct{})
|
||||
s.newSubscriber = make(chan struct{})
|
||||
s.grpcServer = grpc.NewServer(
|
||||
grpc.KeepaliveParams(keepalive.ServerParameters{
|
||||
@@ -93,7 +95,9 @@ func (s *server) Start() error {
|
||||
go s.listenHtlcRequests()
|
||||
go s.listenHtlcResponses()
|
||||
close(s.started)
|
||||
return s.grpcServer.Serve(lis)
|
||||
err = s.grpcServer.Serve(lis)
|
||||
close(s.completed)
|
||||
return err
|
||||
}
|
||||
|
||||
// Waits until the server has started, or errored during startup.
|
||||
@@ -119,6 +123,7 @@ func (s *server) Stop() {
|
||||
s.grpcServer = nil
|
||||
|
||||
close(s.done)
|
||||
<-s.completed
|
||||
log.Printf("Server stopped.")
|
||||
}
|
||||
|
||||
|
||||
2
go.mod
2
go.mod
@@ -4,7 +4,7 @@ go 1.19
|
||||
|
||||
require (
|
||||
github.com/aws/aws-sdk-go v1.30.20
|
||||
github.com/breez/lntest v0.0.17
|
||||
github.com/breez/lntest v0.0.18
|
||||
github.com/btcsuite/btcd v0.23.3
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.2.1
|
||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/breez/lntest"
|
||||
lspd "github.com/breez/lspd/rpc"
|
||||
@@ -109,6 +110,7 @@ func (c *ClnLspNode) Start() {
|
||||
})
|
||||
|
||||
cmd := exec.CommandContext(c.harness.Ctx, c.lspBase.scriptFilePath)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
logFile, err := os.Create(c.logFilePath)
|
||||
if err != nil {
|
||||
lntest.PerformCleanup(cleanups)
|
||||
@@ -136,7 +138,7 @@ func (c *ClnLspNode) Start() {
|
||||
return nil
|
||||
}
|
||||
|
||||
proc.Kill()
|
||||
syscall.Kill(-proc.Pid, syscall.SIGINT)
|
||||
|
||||
log.Printf("About to wait for lspd to exit")
|
||||
status, err := proc.Wait()
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/breez/lntest"
|
||||
lspd "github.com/breez/lspd/rpc"
|
||||
@@ -132,6 +133,7 @@ func (c *LndLspNode) Start() {
|
||||
}
|
||||
|
||||
cmd := exec.CommandContext(c.harness.Ctx, c.lspBase.scriptFilePath)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
logFile, err := os.Create(c.logFilePath)
|
||||
if err != nil {
|
||||
lntest.PerformCleanup(cleanups)
|
||||
@@ -159,7 +161,7 @@ func (c *LndLspNode) Start() {
|
||||
return nil
|
||||
}
|
||||
|
||||
proc.Kill()
|
||||
syscall.Kill(-proc.Pid, syscall.SIGINT)
|
||||
|
||||
log.Printf("About to wait for lspd to exit")
|
||||
status, err := proc.Wait()
|
||||
|
||||
Reference in New Issue
Block a user