desi 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  Desi
2
2
  ====
3
3
  [![Build Status](https://secure.travis-ci.org/AF83/desi.png)](http://travis-ci.org/AF83/desi)
4
+ [![Gem Version](https://badge.fury.io/rb/desi.png)](http://badge.fury.io/rb/desi)
4
5
 
5
6
  Desi (Developper ElasticSearch Installer) is very simple tool to quickly set up
6
7
  an [Elastic Search](http://www.elasticsearch.org/) local install for
@@ -24,6 +25,7 @@ It can be used both as a command-line tool and as a library.
24
25
  $ desi restart # (Re)start cluster (even if active)
25
26
  $ desi stop # Stop cluster
26
27
  $ desi status [--host HOST] # Show running cluster info
28
+ $ desi tail # Show tail output from Elastic Search's log file
27
29
 
28
30
  $ desi indices "^foo" # List all indices whose name match /^foo/
29
31
  $ desi indices "^foo" --delete # Delete all matching indices
@@ -77,8 +79,13 @@ will be spun up by (`desi start`)
77
79
  * Elastic Search 0.19.9 started
78
80
  $ desi status
79
81
  OK. Elastic Search cluster 'elasticsearch' (v0.19.9) is running on 1 node(s) with status yellow
80
- ```
81
82
 
83
+ # Start Elastic Search in the foreground
84
+ $ desi start -f # or --foreground
85
+ ES will be launched in the foreground
86
+ ^C # Manual stop with Control-C
87
+ Elastic Search interrupted!
88
+ ```
82
89
 
83
90
  * library
84
91
 
@@ -92,6 +92,10 @@ module Desi
92
92
  @workdir.join('elasticsearch.pid')
93
93
  end
94
94
 
95
+ def logfile
96
+ current_dir.join('logs', 'elasticsearch.log')
97
+ end
98
+
95
99
  def launcher
96
100
  current_dir.join('bin', 'elasticsearch')
97
101
  end
@@ -25,8 +25,16 @@ module Desi
25
25
  def initialize(opts = {})
26
26
  @host = opts.fetch(:host, 'http://127.0.0.1:9200')
27
27
  @verbose = opts[:verbose]
28
+ @foreground = opts[:foreground]
28
29
  @local_install = LocalInstall.new
29
30
  @client = opts.fetch(:http_client_factory, Desi::HttpClient).new(@host)
31
+
32
+ @tail_after_start = opts[:tail]
33
+
34
+ if @tail_after_start && @foreground
35
+ $stderr.puts "Cannot tail logs when starting ES in foreground mode"
36
+ exit 1
37
+ end
30
38
  end
31
39
 
32
40
  # Start the cluster
@@ -136,6 +144,14 @@ module Desi
136
144
  end
137
145
  end
138
146
 
147
+ def show_tail(options = {})
148
+ puts "Will tail ES logs…" if @verbose
149
+ executable = "tail"
150
+ lines = Integer(options.fetch(:lines, 10))
151
+
152
+ system "#{executable} -n #{lines} -f #{logfile}"
153
+ end
154
+
139
155
  protected
140
156
 
141
157
  # Return cluster health data straight from the cluster
@@ -151,6 +167,10 @@ module Desi
151
167
 
152
168
  private
153
169
 
170
+ def logfile
171
+ @local_install.logfile
172
+ end
173
+
154
174
  def wait_until_cluster_becomes_ready(max_wait = 10, step = 0.5)
155
175
  wait_for(max_wait, step) { cluster_ready? }
156
176
  end
@@ -160,8 +180,9 @@ module Desi
160
180
  end
161
181
 
162
182
  def start_cluster
163
- line = Cocaine::CommandLine.new(@local_install.launcher.to_s, "-p :pidfile")
164
- line.run(pidfile: pidfile.to_s)
183
+ catch_manual_interruption!
184
+ perform_start
185
+ show_tail if tail_after_start?
165
186
 
166
187
  unless wait_until_cluster_becomes_ready
167
188
  raise "Cluster still not ready after #{max_wait} seconds!"
@@ -206,6 +227,37 @@ module Desi
206
227
  delay < max_wait
207
228
  end
208
229
 
230
+ def perform_start
231
+ puts "ES will be launched in the foreground" if foreground?
232
+
233
+ Cocaine::CommandLine.new(@local_install.launcher.to_s, *start_command_options).
234
+ run(pidfile: pidfile.to_s)
235
+ end
236
+
237
+ def start_command_options
238
+ ['-p :pidfile', @foreground ? '-f' : nil].compact.join(' ')
239
+ end
240
+
241
+ def foreground?
242
+ !!@foreground
243
+ end
244
+
245
+ def tail_after_start?
246
+ @tail_after_start
247
+ end
248
+
249
+ def catch_manual_interruption!
250
+ if foreground?
251
+ old_handler = trap(:INT) do
252
+ $stderr.puts "Elastic Search interrupted!"
253
+ if old_handler.respond_to?(:call)
254
+ old_handler.call
255
+ else
256
+ exit 1
257
+ end
258
+ end
259
+ end
260
+ end
209
261
 
210
262
  end
211
263
  end
data/lib/desi/runner.rb CHANGED
@@ -10,10 +10,16 @@ module Desi
10
10
  option :quiet, type: :boolean, desc: "Do not output anything", default: !STDOUT.tty?
11
11
  end
12
12
 
13
+ def self.start_options
14
+ option :foreground, type: :boolean, desc: "Run ES in the foreground", default: false
15
+ option :tail, type: :boolean, desc: "Run tail after (re)starting", default: false
16
+ end
17
+
13
18
  desc "List locally installed Elastic Search releases"
14
19
  verbosity_option
15
20
  def list(options = {})
16
- puts "Local ES installs in #{Desi.configuration.directory} (current one is tagged with '*'):" unless quiet?(options)
21
+ set_verbosity!(options)
22
+ puts "Local ES installs in #{Desi.configuration.directory} (current one is tagged with '*'):" if options[:verbose]
17
23
  Desi::LocalInstall.new.releases.sort.reverse.each do |v|
18
24
  puts v
19
25
  end
@@ -23,57 +29,65 @@ module Desi
23
29
  verbosity_option
24
30
  option :limit, type: :numeric, desc: "Number of releases to show (0 for all)", default: 5
25
31
  def releases(options = {})
32
+ set_verbosity!(options)
26
33
  limit = options[:limit]
27
34
  releases = Desi::Upstream.new.releases.each_with_index.
28
35
  take_while {|rel, i| i < limit || limit == 0 }.map(&:first)
29
36
 
30
- if quiet?(options)
31
- releases
32
- else
37
+ if options[:verbose]
33
38
  puts "Here are #{limit == 0 ? 'all the' : "the #{limit} latest"} releases"
34
39
  releases.each {|rel| puts " - #{rel.name}" }
40
+ else
41
+ releases
35
42
  end
36
43
  end
37
44
 
38
45
  desc "Install ES (to latest stable version by default)"
39
46
  verbosity_option
40
47
  def install(version_or_full_name = nil, options = {})
48
+ set_verbosity!(options)
41
49
  release = if version_or_full_name
42
50
  Desi::Upstream.new.find_release(version_or_full_name)
43
51
  else
44
- puts " * No release specified, will fetch latest." unless quiet?(options)
52
+ puts " * No release specified, will fetch latest." if options[:verbose]
45
53
  Desi::Upstream.new.latest_release
46
54
  end
47
55
 
48
- puts " * fetching release #{release}" unless quiet?(options)
49
- package = Desi::Downloader.new(verbose: !quiet?(options)).download!(release)
56
+ puts " * fetching release #{release}" if options[:verbose]
57
+ package = Desi::Downloader.new(options).download!(release)
50
58
 
51
- puts " * #{release} installed" if Desi::Installer.new(package).install! && !quiet?(options)
59
+ puts " * #{release} installed" if Desi::Installer.new(package).install! && options[:verbose]
52
60
  end
53
61
 
54
62
  desc "Start Elastic Search (do nothing if already active)"
55
63
  verbosity_option
64
+ start_options
56
65
  def start(options = {})
57
- Desi::ProcessManager.new(verbose: !quiet?(options)).start
66
+ set_verbosity!(options)
67
+ Desi::ProcessManager.new(options).start
58
68
  end
59
69
 
60
70
  desc "Start or restart Elastic Search (restart if already active)"
61
71
  verbosity_option
72
+ start_options
62
73
  def restart(options = {})
63
- Desi::ProcessManager.new(verbose: !quiet?(options)).restart
74
+ set_verbosity!(options)
75
+ Desi::ProcessManager.new(options).restart
64
76
  end
65
77
 
66
78
  desc "Stop Elastic Search"
67
79
  verbosity_option
68
80
  def stop(options = {})
69
- Desi::ProcessManager.new(verbose: !quiet?(options)).stop
81
+ set_verbosity!(options)
82
+ Desi::ProcessManager.new(options).stop
70
83
  end
71
84
 
72
85
  desc "Show current status"
73
86
  verbosity_option
74
87
  option "--host", type: :string, desc: "Elastic Search cluster URL", default: '127.0.0.1:9200'
75
88
  def status(options = {})
76
- Desi::ProcessManager.new(verbose: !quiet?(options), host: options[:host]).status
89
+ set_verbosity!(options)
90
+ Desi::ProcessManager.new(options).status
77
91
  end
78
92
 
79
93
  desc "List indices"
@@ -82,7 +96,8 @@ module Desi
82
96
  option "--delete", type: :boolean, desc: "Delete the specified indices (You've been warned!)", default: false
83
97
  option "--empty", type: :boolean, desc: "Delete all documents from the specified indices", default: false
84
98
  def indices(pattern = nil, options = {})
85
- index_manager = Desi::IndexManager.new(verbose: !quiet?(options), host: options[:host])
99
+ set_verbosity!(options)
100
+ index_manager = Desi::IndexManager.new(options)
86
101
 
87
102
  if options[:delete]
88
103
  index_manager.delete!(pattern)
@@ -93,19 +108,15 @@ module Desi
93
108
  end
94
109
  end
95
110
 
96
- # desc "Upgrade to latest ElasticSearch version"
97
- # def upgrade
98
- # end
99
-
100
- # desc "Switch currently active ES version to VERSION"
101
- # option :version, type: :string
102
- # def switch
103
- # end
111
+ desc "Show tail output from Elastic Search's log file"
112
+ def tail
113
+ Desi::ProcessManager.new.show_tail
114
+ end
104
115
 
105
116
  private
106
117
 
107
- def quiet?(opts = {})
108
- opts[:quiet] || !opts[:verbose]
118
+ def set_verbosity!(opts)
119
+ opts[:verbose] ||= opts.delete(:quiet)
109
120
  end
110
121
 
111
122
  end
data/lib/desi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Desi
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: desi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-20 00:00:00.000000000 Z
12
+ date: 2013-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: boson
@@ -206,12 +206,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
206
  - - ! '>='
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
+ segments:
210
+ - 0
211
+ hash: 2218572512027312974
209
212
  required_rubygems_version: !ruby/object:Gem::Requirement
210
213
  none: false
211
214
  requirements:
212
215
  - - ! '>='
213
216
  - !ruby/object:Gem::Version
214
217
  version: '0'
218
+ segments:
219
+ - 0
220
+ hash: 2218572512027312974
215
221
  requirements: []
216
222
  rubyforge_project:
217
223
  rubygems_version: 1.8.23