jettywrapper 1.4.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ file = File.expand_path("../../Gemfile", __FILE__)
4
+
5
+ if File.exists?(file)
6
+ puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
7
+ instance_eval File.read(file)
8
+ end
9
+
10
+ gem 'activesupport', '~> 4.1.1'
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ file = File.expand_path("../../Gemfile", __FILE__)
4
+
5
+ if File.exists?(file)
6
+ puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
7
+ instance_eval File.read(file)
8
+ end
9
+
10
+ gem 'activesupport', '~> 4.2.0.beta2'
data/jettywrapper.gemspec CHANGED
@@ -14,26 +14,22 @@ Gem::Specification.new do |s|
14
14
  s.description = %q{Spin up a jetty instance (e.g., the one at https://github.com/projecthydra/hydra-jetty) and wrap test in it. This lets us run tests against a real copy of solr and fedora.}
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- {spec}/*`.split("\n")
17
- # s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
17
  s.require_paths = ["lib"]
18
+ s.license = 'APACHE2'
19
19
 
20
20
  s.required_rubygems_version = ">= 1.3.6"
21
21
 
22
22
  s.add_dependency "logger"
23
- s.add_dependency "mediashelf-loggable"
24
23
  s.add_dependency "childprocess"
25
24
  s.add_dependency "i18n"
26
25
  s.add_dependency "activesupport", ">=3.0.0"
27
26
 
28
- s.add_development_dependency "rspec"
27
+ s.add_development_dependency "rspec", '~> 2.99'
28
+ s.add_development_dependency "rspec-its"
29
29
  s.add_development_dependency 'rake'
30
-
31
30
 
32
31
  s.add_development_dependency 'yard'#, '0.6.5' # Yard > 0.6.5 won't generate docs.
33
32
  # I don't know why & don't have time to
34
33
  # debug it right now
35
-
36
- s.add_development_dependency 'RedCloth'
37
-
38
34
  end
39
35
 
@@ -1,3 +1,3 @@
1
1
  class Jettywrapper
2
- VERSION = "1.4.2"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/jettywrapper.rb CHANGED
@@ -1,26 +1,24 @@
1
- require 'loggable'
2
1
  require 'singleton'
3
2
  require 'fileutils'
4
3
  require 'shellwords'
5
4
  require 'socket'
6
5
  require 'timeout'
7
6
  require 'childprocess'
7
+ require 'active_support/benchmarkable'
8
8
  require 'active_support/core_ext/hash'
9
9
  require 'erb'
10
10
  require 'yaml'
11
+ require 'logger'
11
12
 
12
13
  Dir[File.expand_path(File.join(File.dirname(__FILE__),"tasks/*.rake"))].each { |ext| load ext } if defined?(Rake)
13
14
 
14
-
15
15
  # Jettywrapper is a Singleton class, so you can only create one jetty instance at a time.
16
16
  class Jettywrapper
17
-
17
+
18
18
  include Singleton
19
- include Loggable
20
19
  include ActiveSupport::Benchmarkable
21
-
22
-
23
- attr_accessor :jetty_home # Jetty's home directory
20
+
21
+ attr_accessor :jetty_home # Jetty's home directory
24
22
  attr_accessor :port # Jetty's port. Default is 8888. Note that attribute is named port, but params passed in expect :jetty_port
25
23
  attr_accessor :startup_wait # How many seconds to wait for jetty to spin up. Default is 5.
26
24
  attr_accessor :quiet # true (default) to reduce Jetty's output
@@ -28,53 +26,51 @@ class Jettywrapper
28
26
  attr_accessor :base_path # The root of the application. Used for determining where log files and PID files should go.
29
27
  attr_accessor :java_opts # Options to pass to java (ex. ["-Xmx512mb", "-Xms128mb"])
30
28
  attr_accessor :jetty_opts # Options to pass to jetty (ex. ["etc/my_jetty.xml", "etc/other.xml"] as in http://wiki.eclipse.org/Jetty/Reference/jetty.xml_usage
31
-
29
+
32
30
  # configure the singleton with some defaults
33
31
  def initialize(params = {})
34
32
  self.base_path = self.class.app_root
35
33
  end
36
34
 
37
-
38
- # Methods inside of the class << self block can be called directly on Jettywrapper, as class methods.
35
+ # Methods inside of the class << self block can be called directly on Jettywrapper, as class methods.
39
36
  # Methods outside the class << self block must be called on Jettywrapper.instance, as instance methods.
40
37
  class << self
41
38
 
42
- def url=(url)
43
- @url = url
39
+ attr_writer :hydra_jetty_version, :url, :tmp_dir, :jetty_dir, :env
40
+
41
+ def hydra_jetty_version
42
+ @hydra_jetty_version ||= 'v8.1.1'
44
43
  end
45
44
 
46
45
  def url
47
- @url ||= defined?(ZIP_URL) ? ZIP_URL : 'https://github.com/projecthydra/hydra-jetty/archive/v5.2.0.zip'
46
+ @url ||= defined?(ZIP_URL) ? ZIP_URL : "https://github.com/projecthydra/hydra-jetty/archive/#{hydra_jetty_version}.zip"
48
47
  @url
49
48
  end
50
49
 
51
- def tmp_dir=(dir)
52
- @tmp_dir = dir
53
- end
54
-
55
50
  def tmp_dir
56
51
  @tmp_dir ||= 'tmp'
57
52
  end
58
53
 
59
54
  def zip_file
60
- File.join tmp_dir, url.split('/').last
55
+ ENV['JETTY_ZIP'] || File.join(tmp_dir, url.split('/').last)
61
56
  end
62
57
 
63
58
  def jetty_dir
64
- 'jetty'
59
+ @jetty_dir ||= 'jetty'
65
60
  end
66
61
 
67
62
  def download(url = nil)
63
+ return if File.exists? zip_file
68
64
  self.url = url if url
69
65
  logger.info "Downloading jetty at #{self.url} ..."
70
66
  FileUtils.mkdir tmp_dir unless File.exists? tmp_dir
71
67
  system "curl -L #{self.url} -o #{zip_file}"
72
68
  abort "Unable to download jetty from #{self.url}" unless $?.success?
73
69
  end
74
-
70
+
75
71
  def unzip
76
72
  download unless File.exists? zip_file
77
- logger.info "Unpacking jetty..."
73
+ logger.info "Unpacking #{zip_file}..."
78
74
  tmp_save_dir = File.join tmp_dir, 'jetty_generator'
79
75
  system "unzip -d #{tmp_save_dir} -qo #{zip_file}"
80
76
  abort "Unable to unzip #{zip_file} into tmp_save_dir/" unless $?.success?
@@ -90,8 +86,8 @@ class Jettywrapper
90
86
 
91
87
  def expanded_zip_dir(tmp_save_dir)
92
88
  # This old way is more specific, but won't work for blacklight-jetty
93
- #expanded_dir = Dir[File.join(tmp_save_dir, "hydra-jetty-*")].first
94
- Dir[File.join(tmp_save_dir, "*")].first
89
+ #expanded_dir = Dir[File.join(tmp_save_dir, "hydra-jetty-*")].first
90
+ Dir[File.join(tmp_save_dir, "*")].first
95
91
  end
96
92
 
97
93
  def clean
@@ -101,22 +97,41 @@ class Jettywrapper
101
97
 
102
98
  def reset_config
103
99
  @app_root = nil
100
+ @env = nil
101
+ @url = nil
102
+ @hydra_jetty_version = nil
104
103
  end
105
104
 
106
105
  def app_root
107
106
  return @app_root if @app_root
108
- @app_root = Rails.root if defined?(Rails.root)
107
+ @app_root = Rails.root if defined?(Rails) and defined?(Rails.root)
109
108
  @app_root ||= APP_ROOT if defined?(APP_ROOT)
110
109
  @app_root ||= '.'
111
110
  end
112
-
113
- def load_config
114
- if defined? Rails
115
- config_name = Rails.env
116
- else
117
- config_name = ENV['environment']
111
+
112
+ def env
113
+ @env ||= begin
114
+ case
115
+ when ENV['JETTYWRAPPER_ENV']
116
+ ENV['JETTYWRAPPER_ENV']
117
+ when defined?(Rails) && Rails.respond_to?(:env)
118
+ Rails.env
119
+ when ENV['RAILS_ENV']
120
+ ENV['RAILS_ENV']
121
+ when ENV['environment']
122
+ ENV['environment']
123
+ else
124
+ default_environment
125
+ end
118
126
  end
127
+ end
128
+
129
+ def default_environment
130
+ 'development'
131
+ end
119
132
 
133
+ def load_config(config_name = env)
134
+ @env = config_name
120
135
  jetty_file = "#{app_root}/config/jetty.yml"
121
136
 
122
137
  unless File.exists?(jetty_file)
@@ -125,33 +140,32 @@ class Jettywrapper
125
140
  end
126
141
 
127
142
  begin
128
- @jetty_erb = ERB.new(IO.read(jetty_file)).result(binding)
129
- rescue Exception => e
143
+ jetty_erb = ERB.new(IO.read(jetty_file)).result(binding)
144
+ rescue
130
145
  raise("jetty.yml was found, but could not be parsed with ERB. \n#{$!.inspect}")
131
146
  end
132
147
 
133
148
  begin
134
- @jetty_yml = YAML::load(@jetty_erb)
135
- rescue StandardError => e
149
+ jetty_yml = YAML::load(jetty_erb)
150
+ rescue
136
151
  raise("jetty.yml was found, but could not be parsed.\n")
137
152
  end
138
153
 
139
- if @jetty_yml.nil? || !@jetty_yml.is_a?(Hash)
154
+ if jetty_yml.nil? || !jetty_yml.is_a?(Hash)
140
155
  raise("jetty.yml was found, but was blank or malformed.\n")
141
156
  end
142
157
 
143
- config = @jetty_yml.with_indifferent_access
144
- config[config_name] || config[:default]
158
+ config = jetty_yml.with_indifferent_access
159
+ config[config_name] || config['default'.freeze]
145
160
  end
146
-
147
161
 
148
- # Set the jetty parameters. It accepts a Hash of symbols.
162
+ # Set the jetty parameters. It accepts a Hash of symbols.
149
163
  # @param [Hash<Symbol>] params
150
164
  # :jetty_home Required. Jetty's home direcotry
151
165
  # :jetty_port Jetty's port. Default is 8888. Note that attribute is named port, but params passed in expect :jetty_port
152
166
  # :startup_wait How many seconds to wait for jetty to spin up. Default is 5. If jetty doesn't finish spinning up, tests can fail because they can't reach jetty.
153
167
  # :solr_home Solr's home directory. Default is jetty_home/solr
154
- # :quiet Keep True(default) to reduce jetty's output
168
+ # :quiet Keep True(default) to reduce jetty's output
155
169
  # :java_opts options to pass to the jvm (ex. ["-Xmx512mb", "-Xms128mb"])
156
170
  # :jetty_opts options to pass to jetty (ex. ["etc/my_jetty.xml", "etc/other.xml"] as in http://wiki.eclipse.org/Jetty/Reference/jetty.xml_usage
157
171
  def configure(params = {})
@@ -167,25 +181,24 @@ class Jettywrapper
167
181
  jetty_server.jetty_opts = params[:jetty_opts] || []
168
182
  return jetty_server
169
183
  end
170
-
171
-
184
+
172
185
  # Wrap the tests. Startup jetty, yield to the test task, capture any errors, shutdown
173
- # jetty, and return the error.
186
+ # jetty, and return the error.
174
187
  # @example Using this method in a rake task
175
188
  # require 'jettywrapper'
176
189
  # desc "Spin up jetty and run tests against it"
177
190
  # task :newtest do
178
- # jetty_params = {
179
- # :jetty_home => "/path/to/jetty",
180
- # :quiet => false,
181
- # :jetty_port => 8983,
191
+ # jetty_params = {
192
+ # :jetty_home => "/path/to/jetty",
193
+ # :quiet => false,
194
+ # :jetty_port => 8983,
182
195
  # :startup_wait => 30,
183
196
  # :jetty_opts => "/etc/jetty.xml"
184
197
  # }
185
- # error = Jettywrapper.wrap(jetty_params) do
186
- # Rake::Task["rake:spec"].invoke
187
- # Rake::Task["rake:cucumber"].invoke
188
- # end
198
+ # error = Jettywrapper.wrap(jetty_params) do
199
+ # Rake::Task["rake:spec"].invoke
200
+ # Rake::Task["rake:cucumber"].invoke
201
+ # end
189
202
  # raise "test failures: #{error}" if error
190
203
  # end
191
204
  def wrap(params)
@@ -207,42 +220,43 @@ class Jettywrapper
207
220
 
208
221
  return error
209
222
  end
210
-
223
+
211
224
  # Convenience method for configuring and starting jetty with one command
212
225
  # @param [Hash] params: The configuration to use for starting jetty
213
- # @example
226
+ # @example
214
227
  # Jettywrapper.start(:jetty_home => '/path/to/jetty', :jetty_port => '8983')
215
228
  def start(params)
216
- Jettywrapper.configure(params)
217
- Jettywrapper.instance.start
218
- return Jettywrapper.instance
229
+ unzip unless File.exists? jetty_dir
230
+ Jettywrapper.configure(params)
231
+ Jettywrapper.instance.start
232
+ return Jettywrapper.instance
219
233
  end
220
-
234
+
221
235
  # Convenience method for configuring and starting jetty with one command. Note
222
- # that for stopping, only the :jetty_home value is required (including other values won't
223
- # hurt anything, though).
236
+ # that for stopping, only the :jetty_home value is required (including other values won't
237
+ # hurt anything, though).
224
238
  # @param [Hash] params: The jetty_home to use for stopping jetty
225
239
  # @return [Jettywrapper.instance]
226
- # @example
240
+ # @example
227
241
  # Jettywrapper.stop_with_params(:jetty_home => '/path/to/jetty')
228
242
  def stop(params)
229
243
  Jettywrapper.configure(params)
230
244
  Jettywrapper.instance.stop
231
245
  return Jettywrapper.instance
232
246
  end
233
-
247
+
234
248
  # Determine whether the jetty at the given jetty_home is running
235
249
  # @param [Hash] params: :jetty_home is required. Which jetty do you want to check the status of?
236
250
  # @return [Boolean]
237
251
  # @example
238
252
  # Jettywrapper.is_jetty_running?(:jetty_home => '/path/to/jetty')
239
- def is_jetty_running?(params)
253
+ def is_jetty_running?(params)
240
254
  Jettywrapper.configure(params)
241
255
  pid = Jettywrapper.instance.pid
242
256
  return false unless pid
243
257
  true
244
258
  end
245
-
259
+
246
260
  # Return the pid of the specified jetty, or return nil if it isn't running
247
261
  # @param [Hash] params: :jetty_home is required.
248
262
  # @return [Fixnum] or [nil]
@@ -254,7 +268,7 @@ class Jettywrapper
254
268
  return nil unless pid
255
269
  pid
256
270
  end
257
-
271
+
258
272
  # Check to see if the port is open so we can raise an error if we have a conflict
259
273
  # @param [Fixnum] port the port to check
260
274
  # @return [Boolean]
@@ -278,8 +292,8 @@ class Jettywrapper
278
292
 
279
293
  return false
280
294
  end
281
-
282
- # Check to see if the pid is actually running. This only works on unix.
295
+
296
+ # Check to see if the pid is actually running. This only works on unix.
283
297
  def is_pid_running?(pid)
284
298
  begin
285
299
  return Process.getpgid(pid) != -1
@@ -287,156 +301,166 @@ class Jettywrapper
287
301
  return false
288
302
  end
289
303
  end
290
-
291
- end #end of class << self
292
-
293
-
294
- # What command is being run to invoke jetty?
295
- def jetty_command
296
- ["java", java_variables, java_opts, "-jar", "start.jar", jetty_opts].flatten
297
- end
298
-
299
- def java_variables
300
- ["-Djetty.port=#{@port}",
301
- "-Dsolr.solr.home=#{Shellwords.escape(@solr_home)}"]
302
- end
303
-
304
- # Start the jetty server. Check the pid file to see if it is running already,
305
- # and stop it if so. After you start jetty, write the PID to a file.
306
- # This is the instance start method. It must be called on Jettywrapper.instance
307
- # You're probably better off using Jettywrapper.start(:jetty_home => "/path/to/jetty")
308
- # @example
309
- # Jettywrapper.configure(params)
310
- # Jettywrapper.instance.start
311
- # return Jettywrapper.instance
312
- def start
313
- logger.debug "Starting jetty with these values: "
314
- logger.debug "jetty_home: #{@jetty_home}"
315
- logger.debug "jetty_command: #{jetty_command.join(' ')}"
316
-
317
- # Check to see if we can start.
318
- # 1. If there is a pid, check to see if it is really running
319
- # 2. Check to see if anything is blocking the port we want to use
320
- if pid
321
- if Jettywrapper.is_pid_running?(pid)
322
- raise("Server is already running with PID #{pid}")
323
- else
324
- logger.warn "Removing stale PID file at #{pid_path}"
325
- File.delete(pid_path)
326
- end
327
- end
328
- if Jettywrapper.is_port_in_use?(self.port)
329
- raise("Port #{self.port} is already in use.")
330
- end
331
- benchmark "Started jetty" do
332
- Dir.chdir(@jetty_home) do
333
- process.start
334
- end
335
- FileUtils.makedirs(pid_dir) unless File.directory?(pid_dir)
336
- begin
337
- f = File.new(pid_path, "w")
338
- rescue Errno::ENOENT, Errno::EACCES
339
- f = File.new(File.join(base_path,'tmp',pid_file),"w")
340
- end
341
- f.puts "#{process.pid}"
342
- f.close
343
- logger.debug "Wrote pid file to #{pid_path} with value #{process.pid}"
344
- startup_wait!
345
- end
346
- end
347
-
348
- # Wait for the jetty server to start and begin listening for requests
349
- def startup_wait!
350
- begin
351
- Timeout::timeout(startup_wait) do
352
- sleep 1 until (Jettywrapper.is_port_in_use? self.port)
353
- end
354
- rescue Timeout::Error
355
- logger.warn "Waited #{startup_wait} seconds for jetty to start, but it is not yet listening on port #{self.port}. Continuing anyway."
356
- end
357
- end
358
-
359
- def process
360
- @process ||= begin
361
- process = ChildProcess.build(*jetty_command)
362
- if self.quiet
363
- process.io.stderr = File.open(File.expand_path("jettywrapper.log"), "w+")
364
- process.io.stdout = process.io.stderr
365
- logger.warn "Logging jettywrapper stdout to #{File.expand_path(process.io.stderr.path)}"
366
- else
367
- process.io.inherit!
368
- end
369
- process.detach = true
370
304
 
371
- process
305
+ def logger=(logger)
306
+ @@logger = logger
307
+ end
308
+
309
+ # If ::Rails.logger is defined and is not nil, it will be returned.
310
+ # If no logger has been defined, a new STDOUT Logger will be created.
311
+ def logger
312
+ @@logger ||= defined?(::Rails) && Rails.logger ? ::Rails.logger : ::Logger.new(STDOUT)
313
+ end
314
+
315
+ end #end of class << self
316
+
317
+ def logger
318
+ self.class.logger
319
+ end
320
+
321
+ # What command is being run to invoke jetty?
322
+ def jetty_command
323
+ ["java", java_variables, java_opts, "-jar", "start.jar", jetty_opts].flatten
324
+ end
325
+
326
+ def java_variables
327
+ ["-Djetty.port=#{@port}",
328
+ "-Dsolr.solr.home=#{Shellwords.escape(@solr_home)}"]
329
+ end
330
+
331
+ # Start the jetty server. Check the pid file to see if it is running already,
332
+ # and stop it if so. After you start jetty, write the PID to a file.
333
+ # This is the instance start method. It must be called on Jettywrapper.instance
334
+ # You're probably better off using Jettywrapper.start(:jetty_home => "/path/to/jetty")
335
+ # @example
336
+ # Jettywrapper.configure(params)
337
+ # Jettywrapper.instance.start
338
+ # return Jettywrapper.instance
339
+ def start
340
+ logger.debug "Starting jetty with these values: "
341
+ logger.debug "jetty_home: #{@jetty_home}"
342
+ logger.debug "jetty_command: #{jetty_command.join(' ')}"
343
+
344
+ # Check to see if we can start.
345
+ # 1. If there is a pid, check to see if it is really running
346
+ # 2. Check to see if anything is blocking the port we want to use
347
+ if pid
348
+ if Jettywrapper.is_pid_running?(pid)
349
+ raise("Server is already running with PID #{pid}")
350
+ else
351
+ logger.warn "Removing stale PID file at #{pid_path}"
352
+ File.delete(pid_path)
353
+ end
354
+ end
355
+ if Jettywrapper.is_port_in_use?(self.port)
356
+ raise("Port #{self.port} is already in use.")
357
+ end
358
+ benchmark "Started jetty" do
359
+ Dir.chdir(@jetty_home) do
360
+ process.start
372
361
  end
373
- end
374
-
375
- def reset_process!
376
- @process = nil
377
- end
378
- # Instance stop method. Must be called on Jettywrapper.instance
379
- # You're probably better off using Jettywrapper.stop(:jetty_home => "/path/to/jetty")
380
- # @example
381
- # Jettywrapper.configure(params)
382
- # Jettywrapper.instance.stop
383
- # return Jettywrapper.instance
384
- def stop
385
- logger.debug "Instance stop method called for pid '#{pid}'"
386
- if pid
387
- if @process
388
- @process.stop
362
+ FileUtils.makedirs(pid_dir) unless File.directory?(pid_dir)
363
+ begin
364
+ f = File.new(pid_path, "w")
365
+ rescue Errno::ENOENT, Errno::EACCES
366
+ f = File.new(File.join(base_path,'tmp',pid_file),"w")
367
+ end
368
+ f.puts "#{process.pid}"
369
+ f.close
370
+ logger.debug "Wrote pid file to #{pid_path} with value #{process.pid}"
371
+ startup_wait!
372
+ end
373
+ end
374
+
375
+ # Wait for the jetty server to start and begin listening for requests
376
+ def startup_wait!
377
+ begin
378
+ Timeout::timeout(startup_wait) do
379
+ sleep 1 until (Jettywrapper.is_port_in_use? self.port)
380
+ end
381
+ rescue Timeout::Error
382
+ logger.warn "Waited #{startup_wait} seconds for jetty to start, but it is not yet listening on port #{self.port}. Continuing anyway."
383
+ end
384
+ end
385
+
386
+ def process
387
+ @process ||= begin
388
+ process = ChildProcess.build(*jetty_command)
389
+ if self.quiet
390
+ process.io.stderr = File.open(File.expand_path("jettywrapper.log"), "w+")
391
+ process.io.stdout = process.io.stderr
392
+ logger.warn "Logging jettywrapper stdout to #{File.expand_path(process.io.stderr.path)}"
389
393
  else
390
- Process.kill("KILL", pid) rescue nil
394
+ process.io.inherit!
391
395
  end
396
+ process.detach = true
392
397
 
393
- begin
394
- File.delete(pid_path)
395
- rescue
396
- end
398
+ process
397
399
  end
398
- end
399
-
400
-
401
- # The fully qualified path to the pid_file
402
- def pid_path
403
- #need to memoize this, becasuse the base path could be relative and the cwd can change in the yield block of wrap
404
- @path ||= File.join(pid_dir, pid_file)
405
- end
406
-
407
- # The file where the process ID will be written
408
- def pid_file
409
- jetty_home_to_pid_file(@jetty_home)
410
- end
411
-
412
- # Take the @jetty_home value and transform it into a legal filename
413
- # @return [String] the name of the pid_file
414
- # @example
415
- # /usr/local/jetty1 => _usr_local_jetty1.pid
416
- def jetty_home_to_pid_file(jetty_home)
400
+ end
401
+
402
+ def reset_process!
403
+ @process = nil
404
+ end
405
+
406
+ # Instance stop method. Must be called on Jettywrapper.instance
407
+ # You're probably better off using Jettywrapper.stop(:jetty_home => "/path/to/jetty")
408
+ # @example
409
+ # Jettywrapper.configure(params)
410
+ # Jettywrapper.instance.stop
411
+ # return Jettywrapper.instance
412
+ def stop
413
+ logger.debug "Instance stop method called for pid '#{pid}'"
414
+ if pid
415
+ if @process
416
+ @process.stop
417
+ else
418
+ Process.kill("KILL", pid) rescue nil
419
+ end
420
+
417
421
  begin
418
- jetty_home.gsub(/\//,'_') << ".pid"
422
+ File.delete(pid_path)
419
423
  rescue
420
- raise "Couldn't make a pid file for jetty_home value #{jetty_home}"
421
- raise $!
422
424
  end
423
425
  end
426
+ end
427
+
428
+ # The fully qualified path to the pid_file
429
+ def pid_path
430
+ #need to memoize this, becasuse the base path could be relative and the cwd can change in the yield block of wrap
431
+ @path ||= File.join(pid_dir, pid_file)
432
+ end
433
+
434
+ # The file where the process ID will be written
435
+ def pid_file
436
+ jetty_home_to_pid_file(@jetty_home)
437
+ end
438
+
439
+ # Take the @jetty_home value and transform it into a legal filename
440
+ # @return [String] the name of the pid_file
441
+ # @example
442
+ # /usr/local/jetty1 => _usr_local_jetty1.pid
443
+ def jetty_home_to_pid_file(jetty_home)
444
+ begin
445
+ jetty_home.gsub(/\//,'_') << "_#{self.class.env}" << ".pid"
446
+ rescue Exception => e
447
+ raise "Couldn't make a pid file for jetty_home value #{jetty_home}\n Caused by: #{e}"
448
+ end
449
+ end
424
450
 
425
- # The directory where the pid_file will be written
426
- def pid_dir
427
- File.expand_path(File.join(base_path,'tmp','pids'))
428
- end
429
-
430
- # Check to see if there is a pid file already
431
- # @return true if the file exists, otherwise false
432
- def pid_file?
433
- return true if File.exist?(pid_path)
434
- false
435
- end
436
-
437
- # the process id of the currently running jetty instance
438
- def pid
439
- File.open( pid_path ) { |f| return f.gets.to_i } if File.exist?(pid_path)
440
- end
441
-
451
+ # The directory where the pid_file will be written
452
+ def pid_dir
453
+ File.expand_path(File.join(base_path,'tmp','pids'))
454
+ end
455
+
456
+ # Check to see if there is a pid file already
457
+ # @return true if the file exists, otherwise false
458
+ def pid_file?
459
+ File.exist?(pid_path)
460
+ end
461
+
462
+ # the process id of the currently running jetty instance
463
+ def pid
464
+ File.open( pid_path ) { |f| return f.gets.to_i } if File.exist?(pid_path)
465
+ end
442
466
  end