Skip to content

Commit

Permalink
Add config for dynamic params
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed May 21, 2015
1 parent 77d1228 commit 4b91fd4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion dcron/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@ package dcron

import (
"fmt"
"os"

"github.com/spf13/viper"
)

var config *viper.Viper

func init() {
hostname, err := os.Hostname()
if err != nil {
panic(err)
}
config = viper.New()

config.SetDefault("rpc_addr", "127.0.0.1:7373")
config.SetDefault("discover", "dcron")
config.SetDefault("node_name", hostname)
config.SetDefault("node", config.GetString("node_name"))
config.SetDefault("bind", "0.0.0.0:7946")
config.SetDefault("http_addr", ":8080")

config.SetConfigName("dcron") // name of config file (without extension)
config.AddConfigPath("./config") // call multiple times to add many search paths
err := config.ReadInConfig() // Find and read the config file
err = config.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
Expand Down
6 changes: 5 additions & 1 deletion dcron/serf.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func (sm *serfManager) Start() {
if config.GetString("discover") != "" {
discover = " -discover=" + config.GetString("discover")
}
serfArgs := []string{discover, "-rpc-addr=" + config.GetString("rpc_addr"), "-config-file=config/dcron.json"}
bind := "-bind= " + config.GetString("bind")
rpc_addr := "-rpc-addr=" + config.GetString("rpc_addr")
node := "-node=" + config.GetString("node")

serfArgs := []string{discover, node, rpc_addr, bind, "-config-file=config/dcron.json"}
agent, err := spawnProc("./bin/serf agent" + strings.Join(serfArgs, " "))
if err != nil {
log.Error(err)
Expand Down

0 comments on commit 4b91fd4

Please sign in to comment.