redis-mmm 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/redis_mmm +27 -4
  2. metadata +3 -3
data/bin/redis_mmm CHANGED
@@ -73,11 +73,12 @@ class RedisMMM < Thor
73
73
  end
74
74
 
75
75
  def add_ip(ip, interface)
76
- ssh("/sbin/ip addr add #{ip} dev #{interface}")
76
+ $log.debug ssh("ip addr show #{interface} | grep #{ip} || sudo ip addr add #{ip} dev #{interface}")
77
+
77
78
  end
78
79
 
79
80
  def remove_ip(ip, interface)
80
- ssh("/sbin/ip addr del #{ip} dev #{interface}")
81
+ $log.debug ssh("ip addr show #{interface} | grep #{ip} && sudo ip addr del #{ip} dev #{interface}")
81
82
  end
82
83
 
83
84
  def slaveof(host)
@@ -103,9 +104,9 @@ class RedisMMM < Thor
103
104
  end
104
105
 
105
106
  def ssh(command)
106
- cmd = "/usr/bin/ssh -p #{ssh_port} #{ssh_user}@#{address} -c \"sudo #{command}\""
107
+ cmd = "/usr/bin/ssh -p #{ssh_port} #{ssh_user}@#{address} \"#{command}\""
107
108
  $log.debug "Executing #{cmd}"
108
- # `#{cmd}`
109
+ `#{cmd}`
109
110
  end
110
111
 
111
112
  end
@@ -114,6 +115,9 @@ class RedisMMM < Thor
114
115
 
115
116
  desc "mon", "Start the monitor"
116
117
  method_option :config, :default => "/etc/redis-mmm.conf", :required => true, :aliases => "-c"
118
+ method_option :log, :type => :string
119
+ method_option :verbose, :type =>:boolean, :aliases => "-v"
120
+ method_option :pid, :type => :string
117
121
  def mon
118
122
  init_state
119
123
 
@@ -127,6 +131,7 @@ class RedisMMM < Thor
127
131
 
128
132
  desc "info [HOST]", "Get info about the host"
129
133
  method_option :config, :default => "/etc/redis-mmm.conf", :required => true, :aliases => "-c"
134
+ method_option :verbose, :type =>:boolean, :aliases => "-v"
130
135
  def info(name)
131
136
  host = self.host(name)
132
137
  info = host.state
@@ -145,6 +150,7 @@ class RedisMMM < Thor
145
150
 
146
151
  desc "status", "Show the current cluster status"
147
152
  method_option :config, :default => "/etc/redis-mmm.conf", :required => true, :aliases => "-c"
153
+ method_option :verbose, :type =>:boolean, :aliases => "-v"
148
154
  def status
149
155
  puts "Configured hosts"
150
156
  hosts.each do |host|
@@ -154,6 +160,7 @@ class RedisMMM < Thor
154
160
 
155
161
  desc "set_master [HOST]", "Changes the master"
156
162
  method_option :config, :default => "/etc/redis-mmm.conf", :required => true, :aliases => "-c"
163
+ method_option :verbose, :type =>:boolean, :aliases => "-v"
157
164
  def set_master(host)
158
165
  init_state
159
166
  change_master_to(host)
@@ -162,6 +169,22 @@ class RedisMMM < Thor
162
169
  protected
163
170
 
164
171
  def init_state
172
+ if log = (options.log || config.params['log'])
173
+ $log = Logger.new(log)
174
+ end
175
+
176
+ $log.level = options.verbose || config.params['verbose'] ? Logger::DEBUG : Logger::INFO
177
+
178
+ if pidfile = (options.pid || config.params['pid'])
179
+ File.open(pidfile, "w") do |f|
180
+ f.write(Process.pid.to_s)
181
+ end
182
+
183
+ at_exit do
184
+ FileUtils.rm_f(pidfile)
185
+ end
186
+ end
187
+
165
188
  @current_master = find_current_master
166
189
  $log.info "current master is #{@current_master}"
167
190
  end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Siebert
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-16 00:00:00 +01:00
18
+ date: 2011-11-17 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency