cli: reload RPC-server TLS config on SIGHUP

This commit is contained in:
Anna Shaleva 2021-04-30 15:53:27 +03:00
parent 5924123927
commit a04e46f719

View file

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
"syscall"
"github.com/nspcc-dev/neo-go/cli/options" "github.com/nspcc-dev/neo-go/cli/options"
"github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/config"
@ -325,6 +326,9 @@ func startServer(ctx *cli.Context) error {
go serv.Start(errChan) go serv.Start(errChan)
rpcServer.Start(errChan) rpcServer.Start(errChan)
sighupCh := make(chan os.Signal, 1)
signal.Notify(sighupCh, syscall.SIGHUP)
fmt.Fprintln(ctx.App.Writer, logo()) fmt.Fprintln(ctx.App.Writer, logo())
fmt.Fprintln(ctx.App.Writer, serv.UserAgent) fmt.Fprintln(ctx.App.Writer, serv.UserAgent)
fmt.Fprintln(ctx.App.Writer) fmt.Fprintln(ctx.App.Writer)
@ -336,8 +340,20 @@ Main:
case err := <-errChan: case err := <-errChan:
shutdownErr = fmt.Errorf("server error: %w", err) shutdownErr = fmt.Errorf("server error: %w", err)
cancel() cancel()
case sig := <-sighupCh:
switch sig {
case syscall.SIGHUP:
log.Info("SIGHUP received, restarting rpc-server")
serverErr := rpcServer.Shutdown()
if serverErr != nil {
errChan <- fmt.Errorf("error while restarting rpc-server: %w", serverErr)
break
}
rpcServer = server.New(chain, cfg.ApplicationConfiguration.RPC, serv, serv.GetOracle(), log)
rpcServer.Start(errChan)
}
case <-grace.Done(): case <-grace.Done():
signal.Stop(sighupCh)
serv.Shutdown() serv.Shutdown()
if serverErr := rpcServer.Shutdown(); serverErr != nil { if serverErr := rpcServer.Shutdown(); serverErr != nil {
shutdownErr = fmt.Errorf("error on shutdown: %w", serverErr) shutdownErr = fmt.Errorf("error on shutdown: %w", serverErr)