diff --git a/cmd/samproxy/main.go b/cmd/samproxy/main.go index 371d59e3e8..11221c9409 100644 --- a/cmd/samproxy/main.go +++ b/cmd/samproxy/main.go @@ -32,6 +32,7 @@ var version string type Options struct { ConfiFile string `short:"c" long:"config" description:"Path to config file" default:"/etc/samproxy/samproxy.toml"` + PeerType string `short:"p" long:"peer_type" description:"Peer type - should be redis or file" default:"file"` Version bool `short:"v" long:"version" description:"Print version number and exit"` } @@ -54,8 +55,17 @@ func main() { os.Exit(0) } - c := &config.FileConfig{Path: opts.ConfiFile} - err := c.Start() + var c config.Config + var err error + // either the flag or the env var will kick us in to redis mode + if opts.PeerType == "redis" || os.Getenv(config.RedisHostEnvVarName) != "" { + c = &config.RedisPeerFileConfig{} + c.(*config.RedisPeerFileConfig).Path = opts.ConfiFile + err = c.(*config.RedisPeerFileConfig).Start() + } else { + c = &config.FileConfig{Path: opts.ConfiFile} + err = c.(*config.FileConfig).Start() + } if err != nil { fmt.Printf("unable to load config: %+v\n", err) os.Exit(1) diff --git a/config/redis.go b/config/redis.go index 02b7278b44..0cab411b68 100644 --- a/config/redis.go +++ b/config/redis.go @@ -167,22 +167,15 @@ func (rc *RedisPeerFileConfig) watchPeers() { sort.Strings(oldPeerList) tk := time.NewTicker(refreshCacheInterval) - defer func() { - fmt.Printf("leaving watchPeers\n") - }() - for range tk.C { - fmt.Printf("watchPeers: starting tick\n") currentPeers, err := rc.peerStore.GetMembers(context.TODO()) if err != nil { - fmt.Printf("watchPeers: got error %+v|n", err) // TODO maybe do something better here? continue } sort.Strings(currentPeers) if !equal(oldPeerList, currentPeers) { // update peer list and trigger callbacks saying the peer list has changed - fmt.Printf("peer list has changed; new peer list +%v\n", currentPeers) rc.peerLock.Lock() rc.peers = currentPeers oldPeerList = currentPeers