Skip to content

Commit d5c0144

Browse files
committed
agent: handle more properties + tidy
1 parent daedd92 commit d5c0144

4 files changed

Lines changed: 28 additions & 20 deletions

File tree

agent/agent.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ package agent
22

33
import (
44
"fmt"
5-
"github.com/garyburd/redigo/redis"
65
"os"
76
"os/exec"
87
"strings"
8+
9+
"github.com/garyburd/redigo/redis"
910
)
1011

1112
type TwemproxyConfig struct {
12-
Listen string `yaml:"listen,omitempty"`
13-
Hash string `yaml:"hash,omitempty"`
14-
Distribution string `yaml:"distribution,omitempty"`
15-
Redis bool `yaml:"redis,omitempty"`
16-
RetryTimeout int `yaml:"server_retry_timeout,omitempty"`
17-
FailureLimit int `yaml:"server_failure_limit,omitempty"`
18-
Servers []string `yaml:"servers,omitempty"`
13+
Listen string `yaml:"listen,omitempty"`
14+
Hash string `yaml:"hash,omitempty"`
15+
Distribution string `yaml:"distribution,omitempty"`
16+
AutoEjectHosts bool `yaml:"auto_eject_hosts,omitempty"`
17+
Redis bool `yaml:"redis,omitempty"`
18+
ServerConnections int `yaml:"server_connections,omitempty"`
19+
Timeout int `yaml:"timeout,omitempty"`
20+
RetryTimeout int `yaml:"server_retry_timeout,omitempty"`
21+
FailureLimit int `yaml:"server_failure_limit,omitempty"`
22+
Servers []string `yaml:"servers,omitempty"`
1923
}
2024

2125
var twemproxyConfig map[string]TwemproxyConfig
@@ -60,7 +64,7 @@ func RestartTwemproxy() error {
6064
Debug("Restarting Twemproxy.")
6165
args := strings.Split(Settings.RestartArgs, string(' '))
6266
cmd := exec.Command(Settings.RestartCommand, args...)
63-
cmd.Env = append (os.Environ(), Settings.RestartEnv)
67+
cmd.Env = append(os.Environ(), Settings.RestartEnv)
6468
out, err := cmd.Output()
6569

6670
if err != nil {
@@ -77,7 +81,7 @@ func GetSentinel() (redis.Conn, error) {
7781
c, err = redis.Dial("tcp", Settings.Sentinels[i])
7882
if err == nil {
7983
Debug(fmt.Sprintf("Connected to sentinel %s", Settings.Sentinels[i]))
80-
break;
84+
break
8185
}
8286
Debug(fmt.Sprintf("Sentinel %s is not reachable", Settings.Sentinels[i]))
8387
}

agent/settings.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
type AgentSettings struct {
99
AgentConfigFile string
1010
Verbose bool
11-
TwemproxyPoolName string `yaml:"twemproxy_pool_name"`
12-
TwemproxyConfigFile string `yaml:"twemproxy_config_file"`
11+
TwemproxyPoolName string `yaml:"twemproxy_pool_name"`
12+
TwemproxyConfigFile string `yaml:"twemproxy_config_file"`
1313
Sentinels []string `yaml:"sentinels"`
14-
RestartCommand string `yaml:"restart_command"`
15-
RestartArgs string `yaml:"restart_args"`
16-
RestartEnv string `yaml:"restart_env"`
17-
LogFile string `yaml:"log_file"`
14+
RestartCommand string `yaml:"restart_command"`
15+
RestartArgs string `yaml:"restart_args"`
16+
RestartEnv string `yaml:"restart_env"`
17+
LogFile string `yaml:"log_file"`
1818
}
1919

2020
var Settings AgentSettings = AgentSettings{}

agent/util.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package agent
22

33
import (
4-
"log"
54
"fmt"
6-
"os"
75
"io/ioutil"
6+
"log"
7+
"os"
8+
89
"launchpad.net/goyaml"
910
)
1011

@@ -38,13 +39,13 @@ func WriteYaml(path string, obj interface{}) error {
3839
if err != nil {
3940
return err
4041
}
41-
tmp := path + ".tmp"
42+
tmp := path + ".tmp"
4243
f, err := os.OpenFile(tmp, os.O_WRONLY|os.O_CREATE|os.O_SYNC, 0644)
4344
if err != nil {
4445
return err
4546
}
4647
defer f.Close()
47-
48+
4849
_, err = f.Write(data)
4950

5051
if err != nil {

conf/nutcracker.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ root:
22
listen: 172.19.111.15:22121
33
hash: fnv1a_64
44
distribution: ketama
5+
auto_eject_hosts: false
56
redis: true
7+
server_connections: 2
8+
timeout: 500
69
server_retry_timeout: 100
710
server_failure_limit: 500
811
servers:

0 commit comments

Comments
 (0)