diff --git a/cmd/app/grpc.go b/cmd/app/grpc.go index caa21252a..05dccbfb4 100644 --- a/cmd/app/grpc.go +++ b/cmd/app/grpc.go @@ -227,7 +227,7 @@ func (g *grpcServer) startTCPListener(wg *sync.WaitGroup) { defer g.tlsCertWatcher.Close() } if err := g.Server.Serve(lis); err != nil { - log.Logger.Errorf("error shutting down grpcServer: %w", err) + log.Logger.Fatalf("error shutting down grpcServer: %w", err) } <-idleConnsClosed wg.Done() @@ -240,12 +240,12 @@ func (g *grpcServer) startUnixListener() { if runtime.GOOS != "linux" { // As MacOS doesn't have abstract unix domain sockets the file // created by a previous run needs to be explicitly removed - if err := os.RemoveAll(LegacyUnixDomainSocket); err != nil { + if err := os.RemoveAll(g.grpcServerEndpoint); err != nil { log.Logger.Fatal(err) } } - unixAddr, err := net.ResolveUnixAddr("unix", LegacyUnixDomainSocket) + unixAddr, err := net.ResolveUnixAddr("unix", g.grpcServerEndpoint) if err != nil { log.Logger.Fatal(err) } @@ -265,7 +265,7 @@ func (g *grpcServer) ExposesGRPCTLS() bool { return viper.IsSet("grpc-tls-certificate") && viper.IsSet("grpc-tls-key") } -func createLegacyGRPCServer(cfg *config.FulcioConfig, v2Server gw.CAServer) (*grpcServer, error) { +func createLegacyGRPCServer(cfg *config.FulcioConfig, unixDomainSocket string, v2Server gw.CAServer) (*grpcServer, error) { logger, opts := log.SetupGRPCLogging() myServer := grpc.NewServer(grpc.UnaryInterceptor( @@ -283,7 +283,7 @@ func createLegacyGRPCServer(cfg *config.FulcioConfig, v2Server gw.CAServer) (*gr // Register your gRPC service implementations. gw_legacy.RegisterCAServer(myServer, legacyGRPCCAServer) - return &grpcServer{myServer, LegacyUnixDomainSocket, v2Server, nil}, nil + return &grpcServer{myServer, unixDomainSocket, v2Server, nil}, nil } func panicRecoveryHandler(ctx context.Context, p interface{}) error { diff --git a/cmd/app/http.go b/cmd/app/http.go index 59802e1ed..19a1564cc 100644 --- a/cmd/app/http.go +++ b/cmd/app/http.go @@ -127,7 +127,7 @@ func (h httpServer) startListener(wg *sync.WaitGroup) { wg.Add(1) go func() { if err := h.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { - log.Logger.Error(err) + log.Logger.Fatal(err) } <-idleConnsClosed wg.Done() diff --git a/cmd/app/http_test.go b/cmd/app/http_test.go index 1f6305139..debb70036 100644 --- a/cmd/app/http_test.go +++ b/cmd/app/http_test.go @@ -109,7 +109,7 @@ func setupHTTPServerWithGRPCTLS(t *testing.T) (httpServer, string) { if err != nil { t.Error(err) } - legacyGRPCServer, err := createLegacyGRPCServer(nil, grpcServer.caService) + legacyGRPCServer, err := createLegacyGRPCServer(nil, LegacyUnixDomainSocket, grpcServer.caService) if err != nil { t.Fatal(err) } diff --git a/cmd/app/serve.go b/cmd/app/serve.go index 956b10652..2196bfbc3 100644 --- a/cmd/app/serve.go +++ b/cmd/app/serve.go @@ -103,6 +103,7 @@ func newServeCmd() *cobra.Command { cmd.Flags().String("grpc-host", "0.0.0.0", "The host on which to serve requests for GRPC") cmd.Flags().String("grpc-port", "8081", "The port on which to serve requests for GRPC") cmd.Flags().String("metrics-port", "2112", "The port on which to serve prometheus metrics endpoint") + cmd.Flags().String("legacy-unix-domain-socket", LegacyUnixDomainSocket, "The Unix domain socket used for the legacy gRPC server") cmd.Flags().Duration("read-header-timeout", 10*time.Second, "The time allowed to read the headers of the requests in seconds") cmd.Flags().String("grpc-tls-certificate", "", "the certificate file to use for secure connections - only applies to grpc-port") cmd.Flags().String("grpc-tls-key", "", "the private key file to use for secure connections (without passphrase) - only applies to grpc-port") @@ -304,7 +305,7 @@ func runServeCmd(cmd *cobra.Command, args []string) { //nolint: revive grpcServer.setupPrometheus(reg) grpcServer.startTCPListener(&wg) - legacyGRPCServer, err := createLegacyGRPCServer(cfg, grpcServer.caService) + legacyGRPCServer, err := createLegacyGRPCServer(cfg, viper.GetString("legacy-unix-domain-socket"), grpcServer.caService) if err != nil { log.Logger.Fatal(err) } @@ -335,7 +336,7 @@ func runServeCmd(cmd *cobra.Command, args []string) { //nolint: revive log.Logger.Info("stopped prom server") }() if err := prom.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { - log.Logger.Error(err) + log.Logger.Fatal(err) } <-idleConnsClosed log.Logger.Info("prom server shutdown")