Commit 1b52bb36 authored by ale's avatar ale

Disable HTTP server for readonly instances

parent 36012c94
Pipeline #4273 passed with stages
in 1 minute and 44 seconds
......@@ -4,6 +4,9 @@ import (
"context"
"flag"
"log"
"os"
"os/signal"
"syscall"
"git.autistici.org/ai3/go-common/serverutil"
"github.com/google/subcommands"
......@@ -56,12 +59,20 @@ func (c *serverCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}
}
defer srv.Close()
httpSrv := replds.NewHTTPServer(srv)
// If this is a readonly server, just wait for a termination
// signal, otherwise start the HTTP server for our API.
if config.Server.Readonly {
sigCh := make(chan os.Signal)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
<-sigCh
} else {
httpSrv := replds.NewHTTPServer(srv)
log.Printf("starting replds on %s", config.Server.Addr)
if err := serverutil.Serve(httpSrv.Handler(), config.HTTPServer, config.Server.Addr); err != nil {
log.Printf("error: %v", err)
return subcommands.ExitFailure
log.Printf("starting replds on %s", config.Server.Addr)
if err := serverutil.Serve(httpSrv.Handler(), config.HTTPServer, config.Server.Addr); err != nil {
log.Printf("error: %v", err)
return subcommands.ExitFailure
}
}
return subcommands.ExitSuccess
......
......@@ -214,7 +214,9 @@ func (s *Server) doSetNodes(ctx context.Context, nodes []*Node, updatePeers bool
var res SetNodesResponse
if updatePeers {
// Ping remote nodes with updated state.
// Ping remote nodes with the updated state. This
// reduces the latency of update propagation (we don't
// have to wait until the peers poll us).
res.HostsOk = 1
for _, peer := range s.peers {
err := s.network.Client(peer).internalUpdateNodes(ctx, &internalUpdateNodesRequest{
......@@ -419,6 +421,9 @@ func (s *Server) pollPeerRequest(peer string) (bool, error) {
peerName := stripHTTP(peer)
peerRequests.With(prometheus.Labels{"peer": peerName}).Inc()
// Create a shallow copy of the list of the Nodes we know
// about, containing just path/timestamp, to send to the peer
// in our GetNodes request.
s.mx.Lock()
var req internalGetNodesRequest
for _, node := range s.nodes {
......@@ -443,6 +448,7 @@ func (s *Server) pollPeerRequest(peer string) (bool, error) {
return false, nil
}
// Update the internal state with the new data.
return resp.Partial, s.internalUpdateNodes(ctx, &internalUpdateNodesRequest{Nodes: resp.Nodes})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment