multi: wrap logger to request shutdown from signal on critical error
This commit adds a shutdown logger which will send a request for shutdown on critical errors. It uses the signal package to request safe shutdown of the daemon. Since we init our logs in config validation, we add a started channel to the signal package to prevent the case where we have a critical log after the ShutdownLogger has started but before the daemon has started listening for intercepts. In this case, we just ignore the shutdown request.
This commit is contained in:
6 files changed
+98
-6
No files matched your search
@@ -414,7 +414,10 @@ func openChannelPsbt(ctx *cli.Context, client lnrpc.LightningClient,
|
||||
if err != nil {
|
||||
return fmt.Errorf("opening stream to server failed: %v", err)
|
||||
}
|
||||
signal.Intercept()
|
||||
|
||||
if err := signal.Intercept(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// We also need to spawn a goroutine that reads from the server. This
|
||||
// will copy the messages to the channel as long as they come in or add
|
||||
|
||||
+4
-1
@@ -19,7 +19,10 @@ func main() {
|
||||
}
|
||||
|
||||
// Hook interceptor for os signals.
|
||||
signal.Intercept()
|
||||
if err := signal.Intercept(); err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Call the "real" main in a nested manner so the defers will properly
|
||||
// be executed in the case of a graceful shutdown.
|
||||
|
||||
Reference in new issue
Block a user