Skip to content

Commit

Permalink
dump config on SIGUSR1
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Jul 3, 2023
1 parent 740d58c commit d893e24
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/revad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func handleSignalFlag() {
signal = syscall.SIGQUIT
case "stop":
signal = syscall.SIGTERM
case "dump":
signal = syscall.SIGUSR1
default:
fmt.Fprintf(os.Stderr, "unknown signal %q\n", *signalFlag)
os.Exit(1)
Expand Down
1 change: 1 addition & 0 deletions cmd/revad/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Shared struct {
// Core holds the core configuration.
type Core struct {
MaxCPUs string `key:"max_cpus" mapstructure:"max_cpus"`
ConfigDumpFile string `key:"config_dump_file" mapstructure:"config_dump_file" default:"/tmp/reva-dump.toml"`
TracingEnabled bool `key:"tracing_enabled" mapstructure:"tracing_enabled" default:"true"`
TracingEndpoint string `key:"tracing_endpoint" mapstructure:"tracing_endpoint" default:"localhost:6831"`
TracingCollector string `key:"tracing_collector" mapstructure:"tracing_collector"`
Expand Down
42 changes: 40 additions & 2 deletions cmd/revad/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ package runtime
import (
"fmt"
"net"
"os"
"os/signal"
"runtime"
"strconv"
"strings"
"syscall"

"github.com/BurntSushi/toml"
"github.com/pkg/errors"

"github.com/cs3org/reva/cmd/revad/pkg/config"
Expand Down Expand Up @@ -115,15 +119,49 @@ func New(config *config.Config, opt ...Option) (*Reva, error) {
return nil, err
}

return &Reva{
r := &Reva{
config: config,
servers: servers,
serverless: serverless,
watcher: watcher,
lns: listeners,
pidfile: opts.PidFile,
log: log,
}, nil
}
r.initConfigDumper()
return r, nil
}

func (r *Reva) initConfigDumper() {
// dump the config when the process receives a SIGUSR1 signal
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGUSR1)

go func() {
<-sigs
r.dumpConfig()
}()
}

func (r *Reva) dumpConfig() {
cfg := r.config.Dump()
// TODO: merge this config with the one received from
// the running services
out := r.config.Core.ConfigDumpFile
f, err := os.OpenFile(out, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
if err != nil {
r.log.Error().Err(err).Msgf("error opening file %s for dumping the config", out)
return
}
defer f.Close()

enc := toml.NewEncoder(f)
enc.Indent = ""
if err := enc.Encode(cfg); err != nil {
r.log.Error().Err(err).Msg("error encoding config")
return
}
r.log.Debug().Msgf("config dumped successfully in %s", out)
}

func servicesAddresses(cfg *config.Config) map[string]grace.Addressable {
Expand Down

0 comments on commit d893e24

Please sign in to comment.