Skip to content

Commit

Permalink
Merge pull request #3176 from rhafer/nats-loop
Browse files Browse the repository at this point in the history
nats: Wait for sigint/sigterm instead of spinning in a tight loop
  • Loading branch information
David Christofas authored Feb 15, 2022
2 parents c1a994b + 015d371 commit 22385ba
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions nats/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package command

import (
"fmt"
"os"
"os/signal"
"syscall"

"github.com/cs3org/reva/pkg/events/server"
"github.com/owncloud/ocis/nats/pkg/config"
Expand All @@ -25,13 +28,23 @@ func Server(cfg *config.Config) *cli.Command {
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
err := server.RunNatsServer(server.Host(cfg.Nats.Host), server.Port(cfg.Nats.Port), server.StanOpts(func(o *stanServer.Options) {
o.CustomLogger = &logWrapper{logger}
}))
if err != nil {
return err
}
for {
select {
case <-ch:
// TODO: Should we shut down the NatsServer in a proper way here?
// That would require a reference to the StanServer instance for being able to call
// StanServer.Shutdown() github.com/cs3org/reva/pkg/events/server doesn't provide that
// currently
return nil
}
}
},
}
Expand Down

0 comments on commit 22385ba

Please sign in to comment.