jettywrapper 0.0.7 → 0.0.8
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.
- data/.gitmodules +3 -0
- data/Rakefile +1 -1
- data/TODO.txt +3 -0
- data/lib/jettywrapper.rb +162 -29
- data/lib/jettywrapper/version.rb +1 -1
- data/spec/lib/jettywrapper_integration_spec.run_by_hand +137 -0
- data/spec/lib/jettywrapper_spec.rb +65 -19
- data/tasks/jettywrapper.rake +136 -0
- metadata +7 -5
- data/spec/lib/jettywrapper_integration_spec.rb +0 -59
data/.gitmodules
CHANGED
data/Rakefile
CHANGED
data/TODO.txt
ADDED
data/lib/jettywrapper.rb
CHANGED
@@ -4,6 +4,9 @@ require 'logger'
|
|
4
4
|
require 'loggable'
|
5
5
|
require 'singleton'
|
6
6
|
require 'ftools'
|
7
|
+
require 'socket'
|
8
|
+
require 'timeout'
|
9
|
+
require 'ruby-debug'
|
7
10
|
|
8
11
|
class Jettywrapper
|
9
12
|
|
@@ -32,6 +35,8 @@ class Jettywrapper
|
|
32
35
|
@logger.debug 'Initializing jettywrapper'
|
33
36
|
end
|
34
37
|
|
38
|
+
# Methods inside of the class << self block can be called directly on Jettywrapper, as class methods.
|
39
|
+
# Methods outside the class << self block must be called on Jettywrapper.instance, as instance methods.
|
35
40
|
class << self
|
36
41
|
|
37
42
|
# Set the jetty parameters. It accepts a Hash of symbols.
|
@@ -76,7 +81,7 @@ class Jettywrapper
|
|
76
81
|
# end
|
77
82
|
# raise "test failures: #{error}" if error
|
78
83
|
# end
|
79
|
-
def wrap(params
|
84
|
+
def wrap(params)
|
80
85
|
error = false
|
81
86
|
jetty_server = self.instance
|
82
87
|
jetty_server.quiet = params[:quiet] || true
|
@@ -102,6 +107,86 @@ class Jettywrapper
|
|
102
107
|
return error
|
103
108
|
end
|
104
109
|
|
110
|
+
# Convenience method for configuring and starting jetty with one command
|
111
|
+
# @param [Hash] params: The configuration to use for starting jetty
|
112
|
+
# @example
|
113
|
+
# Jettywrapper.start_with_params(:jetty_home => '/path/to/jetty', :jetty_port => '8983')
|
114
|
+
def start(params)
|
115
|
+
Jettywrapper.configure(params)
|
116
|
+
Jettywrapper.instance.start
|
117
|
+
return Jettywrapper.instance
|
118
|
+
end
|
119
|
+
|
120
|
+
# Convenience method for configuring and starting jetty with one command. Note
|
121
|
+
# that for stopping, only the :jetty_home value is required (including other values won't
|
122
|
+
# hurt anything, though).
|
123
|
+
# @param [Hash] params: The jetty_home to use for stopping jetty
|
124
|
+
# @return [Jettywrapper.instance]
|
125
|
+
# @example
|
126
|
+
# Jettywrapper.stop_with_params(:jetty_home => '/path/to/jetty')
|
127
|
+
def stop(params)
|
128
|
+
Jettywrapper.configure(params)
|
129
|
+
Jettywrapper.instance.stop
|
130
|
+
return Jettywrapper.instance
|
131
|
+
end
|
132
|
+
|
133
|
+
# Determine whether the jetty at the given jetty_home is running
|
134
|
+
# @param [Hash] params: :jetty_home is required. Which jetty do you want to check the status of?
|
135
|
+
# @return [Boolean]
|
136
|
+
# @example
|
137
|
+
# Jettywrapper.is_running?(:jetty_home => '/path/to/jetty')
|
138
|
+
def is_jetty_running?(params)
|
139
|
+
Jettywrapper.configure(params)
|
140
|
+
pid = Jettywrapper.instance.pid
|
141
|
+
return false unless pid
|
142
|
+
true
|
143
|
+
end
|
144
|
+
|
145
|
+
# Return the pid of the specified jetty, or return nil if it isn't running
|
146
|
+
# @param [Hash] params: :jetty_home is required.
|
147
|
+
# @return [Fixnum] or [nil]
|
148
|
+
# @example
|
149
|
+
# Jettywrapper.pid(:jetty_home => '/path/to/jetty')
|
150
|
+
def pid(params)
|
151
|
+
Jettywrapper.configure(params)
|
152
|
+
pid = Jettywrapper.instance.pid
|
153
|
+
return nil unless pid
|
154
|
+
pid
|
155
|
+
end
|
156
|
+
|
157
|
+
# Check to see if the port is open so we can raise an error if we have a conflict
|
158
|
+
# @param [Fixnum] port the port to check
|
159
|
+
# @return [Boolean]
|
160
|
+
# @example
|
161
|
+
# Jettywrapper.is_port_open?(8983)
|
162
|
+
def is_port_in_use?(port)
|
163
|
+
begin
|
164
|
+
Timeout::timeout(1) do
|
165
|
+
begin
|
166
|
+
s = TCPSocket.new('127.0.0.1', port)
|
167
|
+
s.close
|
168
|
+
return true
|
169
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
170
|
+
return false
|
171
|
+
rescue
|
172
|
+
return false
|
173
|
+
end
|
174
|
+
end
|
175
|
+
rescue Timeout::Error
|
176
|
+
end
|
177
|
+
|
178
|
+
return false
|
179
|
+
end
|
180
|
+
|
181
|
+
# Check to see if the pid is actually running. This only works on unix.
|
182
|
+
def is_running?(pid)
|
183
|
+
begin
|
184
|
+
return Process.getpgid(pid) != -1
|
185
|
+
rescue Errno::ESRCH
|
186
|
+
return false
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
105
190
|
end #end of class << self
|
106
191
|
|
107
192
|
|
@@ -112,21 +197,32 @@ class Jettywrapper
|
|
112
197
|
|
113
198
|
# Start the jetty server. Check the pid file to see if it is running already,
|
114
199
|
# and stop it if so. After you start jetty, write the PID to a file.
|
200
|
+
# This is the instance start method. It must be called on Jettywrapper.instance
|
201
|
+
# You're probably better off using Jettywrapper.start(:jetty_home => "/path/to/jetty")
|
202
|
+
# @example
|
203
|
+
# Jettywrapper.configure(params)
|
204
|
+
# Jettywrapper.instance.start
|
205
|
+
# return Jettywrapper.instance
|
115
206
|
def start
|
116
207
|
@logger.debug "Starting jetty with these values: "
|
117
208
|
@logger.debug "jetty_home: #{@jetty_home}"
|
118
209
|
@logger.debug "solr_home: #{@solr_home}"
|
119
210
|
@logger.debug "fedora_home: #{@fedora_home}"
|
120
211
|
@logger.debug "jetty_command: #{jetty_command}"
|
121
|
-
|
212
|
+
|
213
|
+
# Check to see if we can start.
|
214
|
+
# 1. If there is a pid, check to see if it is really running
|
215
|
+
# 2. Check to see if anything is blocking the port we want to use
|
122
216
|
if pid
|
123
|
-
|
124
|
-
Process.kill(0,pid)
|
217
|
+
if Jettywrapper.is_running?(pid)
|
125
218
|
raise("Server is already running with PID #{pid}")
|
126
|
-
|
219
|
+
else
|
127
220
|
@logger.warn "Removing stale PID file at #{pid_path}"
|
128
221
|
File.delete(pid_path)
|
129
222
|
end
|
223
|
+
if Jettywrapper.is_port_in_use?(@jetty_port)
|
224
|
+
raise("Port #{self.jetty_port} is already in use.")
|
225
|
+
end
|
130
226
|
end
|
131
227
|
Dir.chdir(@jetty_home) do
|
132
228
|
self.send "#{platform}_process".to_sym
|
@@ -142,36 +238,47 @@ class Jettywrapper
|
|
142
238
|
@logger.debug "Wrote pid file to #{pid_path} with value #{@pid}"
|
143
239
|
end
|
144
240
|
|
145
|
-
|
146
|
-
|
241
|
+
# Instance stop method. Must be called on Jettywrapper.instance
|
242
|
+
# You're probably better off using Jettywrapper.stop(:jetty_home => "/path/to/jetty")
|
243
|
+
# @example
|
244
|
+
# Jettywrapper.configure(params)
|
245
|
+
# Jettywrapper.instance.stop
|
246
|
+
# return Jettywrapper.instance
|
247
|
+
def stop
|
147
248
|
if pid
|
148
249
|
begin
|
149
250
|
self.send "#{platform}_stop".to_sym
|
150
251
|
rescue Errno::ESRCH
|
151
|
-
@logger.
|
252
|
+
@logger.error "I tried to kill the process #{pid} but it seems it wasn't running."
|
253
|
+
end
|
254
|
+
begin
|
255
|
+
File.delete(pid_path)
|
256
|
+
rescue
|
152
257
|
end
|
153
|
-
FileUtils.rm(pid_path)
|
154
258
|
end
|
155
259
|
end
|
156
260
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
261
|
+
# Spawn a process on windows
|
262
|
+
def win_process
|
263
|
+
@pid = Process.create(
|
264
|
+
:app_name => jetty_command,
|
265
|
+
:creation_flags => Process::DETACHED_PROCESS,
|
266
|
+
:process_inherit => false,
|
267
|
+
:thread_inherit => true,
|
268
|
+
:cwd => "#{@jetty_home}"
|
269
|
+
).process_id
|
270
|
+
end
|
166
271
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
272
|
+
# Determine whether we're running on windows or unix. We need to know this so
|
273
|
+
# we know how to start and stop processes.
|
274
|
+
def platform
|
275
|
+
case RUBY_PLATFORM
|
276
|
+
when /mswin32/
|
277
|
+
return 'win'
|
278
|
+
else
|
279
|
+
return 'nix'
|
280
|
+
end
|
281
|
+
end
|
175
282
|
|
176
283
|
def nix_process
|
177
284
|
@pid = fork do
|
@@ -187,18 +294,43 @@ class Jettywrapper
|
|
187
294
|
|
188
295
|
# stop jetty the *nix way
|
189
296
|
def nix_stop
|
190
|
-
|
191
|
-
|
297
|
+
return nil if pid == nil
|
298
|
+
begin
|
299
|
+
pid_keeper = pid
|
300
|
+
@logger.debug "Killing process #{pid}"
|
301
|
+
Process.kill('TERM',pid)
|
302
|
+
sleep 2
|
303
|
+
FileUtils.rm(pid_path)
|
304
|
+
if Jettywrapper.is_running?(pid_keeper)
|
305
|
+
raise "Couldn't kill process #{pid_keeper}"
|
306
|
+
end
|
307
|
+
rescue Errno::ESRCH
|
308
|
+
@logger.debug "I tried to kill #{pid_keeper} but it appears it wasn't running."
|
309
|
+
end
|
192
310
|
end
|
193
311
|
|
312
|
+
# The fully qualified path to the pid_file
|
194
313
|
def pid_path
|
195
314
|
File.join(pid_dir, pid_file)
|
196
315
|
end
|
197
316
|
|
198
317
|
# The file where the process ID will be written
|
199
318
|
def pid_file
|
200
|
-
@pid_file ||
|
319
|
+
@pid_file || jetty_home_to_pid_file(@jetty_home)
|
201
320
|
end
|
321
|
+
|
322
|
+
# Take the @jetty_home value and transform it into a legal filename
|
323
|
+
# @return [String] the name of the pid_file
|
324
|
+
# @example
|
325
|
+
# /usr/local/jetty1 => _usr_local_jetty1.pid
|
326
|
+
def jetty_home_to_pid_file(jetty_home)
|
327
|
+
begin
|
328
|
+
jetty_home.gsub(/\//,'_') << ".pid"
|
329
|
+
rescue
|
330
|
+
raise "Couldn't make a pid file for jetty_home value #{jetty_home}"
|
331
|
+
raise $!
|
332
|
+
end
|
333
|
+
end
|
202
334
|
|
203
335
|
# The directory where the pid_file will be written
|
204
336
|
def pid_dir
|
@@ -212,6 +344,7 @@ class Jettywrapper
|
|
212
344
|
false
|
213
345
|
end
|
214
346
|
|
347
|
+
# the process id of the currently running jetty instance
|
215
348
|
def pid
|
216
349
|
@pid || File.open( pid_path ) { |f| return f.gets.to_i } if File.exist?(pid_path)
|
217
350
|
end
|
data/lib/jettywrapper/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
GEMVERSION = "0.0.
|
1
|
+
GEMVERSION = "0.0.8"
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
require File.join(File.dirname(__FILE__), "/../../lib/jettywrapper")
|
3
|
+
require 'rubygems'
|
4
|
+
require 'ruby-debug'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
module Hydra
|
8
|
+
describe Jettywrapper do
|
9
|
+
context "integration" do
|
10
|
+
before(:all) do
|
11
|
+
$stderr.reopen("/dev/null", "w")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "starts" do
|
15
|
+
jetty_params = {
|
16
|
+
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1")
|
17
|
+
}
|
18
|
+
Jettywrapper.configure(jetty_params)
|
19
|
+
ts = Jettywrapper.instance
|
20
|
+
ts.logger.debug "Stopping jetty from rspec."
|
21
|
+
ts.stop
|
22
|
+
ts.start
|
23
|
+
ts.logger.debug "Jetty started from rspec at #{ts.pid}"
|
24
|
+
pid_from_file = File.open( ts.pid_path ) { |f| f.gets.to_i }
|
25
|
+
ts.pid.should eql(pid_from_file)
|
26
|
+
sleep 30 # give jetty time to start
|
27
|
+
|
28
|
+
# Can we connect to solr?
|
29
|
+
require 'net/http'
|
30
|
+
response = Net::HTTP.get_response(URI.parse("http://localhost:8888/solr/admin/"))
|
31
|
+
response.code.should eql("200")
|
32
|
+
ts.stop
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
it "won't start if it's already running" do
|
37
|
+
jetty_params = {
|
38
|
+
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1")
|
39
|
+
}
|
40
|
+
Jettywrapper.configure(jetty_params)
|
41
|
+
ts = Jettywrapper.instance
|
42
|
+
ts.logger.debug "Stopping jetty from rspec."
|
43
|
+
ts.stop
|
44
|
+
ts.start
|
45
|
+
sleep 30
|
46
|
+
ts.logger.debug "Jetty started from rspec at #{ts.pid}"
|
47
|
+
response = Net::HTTP.get_response(URI.parse("http://localhost:8888/solr/admin/"))
|
48
|
+
response.code.should eql("200")
|
49
|
+
lambda { ts.start }.should raise_exception(/Server is already running/)
|
50
|
+
ts.stop
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can start multiple copies of jetty, as long as they have different jetty_homes" do
|
54
|
+
jetty1_params = {
|
55
|
+
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1"),
|
56
|
+
:jetty_port => '8983'
|
57
|
+
}
|
58
|
+
jetty2_params = {
|
59
|
+
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty2"),
|
60
|
+
:jetty_port => '8984'
|
61
|
+
}
|
62
|
+
|
63
|
+
# Ensure nothing is running when we start
|
64
|
+
Jettywrapper.stop(jetty1_params)
|
65
|
+
Jettywrapper.stop(jetty2_params)
|
66
|
+
|
67
|
+
# Spin up two copies of jetty, with different jetty home values and on different ports
|
68
|
+
Jettywrapper.start(jetty1_params)
|
69
|
+
Jettywrapper.start(jetty2_params)
|
70
|
+
|
71
|
+
# Ensure both are viable
|
72
|
+
sleep 30
|
73
|
+
response1 = Net::HTTP.get_response(URI.parse("http://localhost:8983/solr/admin/"))
|
74
|
+
response1.code.should eql("200")
|
75
|
+
response2 = Net::HTTP.get_response(URI.parse("http://localhost:8984/solr/admin/"))
|
76
|
+
response2.code.should eql("200")
|
77
|
+
|
78
|
+
# Shut them both down
|
79
|
+
Jettywrapper.stop(jetty1_params)
|
80
|
+
Jettywrapper.stop(jetty2_params)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "raises an error if you try to start a jetty that is already running" do
|
84
|
+
jetty_params = {
|
85
|
+
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1"),
|
86
|
+
:jetty_port => '8983'
|
87
|
+
}
|
88
|
+
ts = Jettywrapper.configure(jetty_params)
|
89
|
+
ts.stop
|
90
|
+
ts.pid_file?.should eql(false)
|
91
|
+
ts.start
|
92
|
+
sleep 30
|
93
|
+
lambda{ ts.start }.should raise_exception
|
94
|
+
ts.stop
|
95
|
+
end
|
96
|
+
|
97
|
+
it "can check to see whether a port is already in use" do
|
98
|
+
params = {
|
99
|
+
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1"),
|
100
|
+
:jetty_port => '9999'
|
101
|
+
}
|
102
|
+
Jettywrapper.stop(params)
|
103
|
+
sleep 10
|
104
|
+
Jettywrapper.is_port_in_use?(params[:jetty_port]).should eql(false)
|
105
|
+
Jettywrapper.start(params)
|
106
|
+
sleep 30
|
107
|
+
Jettywrapper.is_port_in_use?(params[:jetty_port]).should eql(true)
|
108
|
+
Jettywrapper.stop(params)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Not ready for this yet
|
112
|
+
# it "won't start if there is a port conflict" do
|
113
|
+
# jetty1_params = {
|
114
|
+
# :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1"),
|
115
|
+
# :jetty_port => '8983'
|
116
|
+
# }
|
117
|
+
# jetty2_params = {
|
118
|
+
# :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty2"),
|
119
|
+
# :jetty_port => '8983'
|
120
|
+
# }
|
121
|
+
# # Ensure nothing is running when we start
|
122
|
+
# Jettywrapper.stop(jetty1_params)
|
123
|
+
# Jettywrapper.stop(jetty2_params)
|
124
|
+
#
|
125
|
+
# # Spin up two copies of jetty, with different jetty home values but the same port
|
126
|
+
# Jettywrapper.start(jetty1_params)
|
127
|
+
# lambda{ Jettywrapper.start(jetty2_params) }.should raise_exception
|
128
|
+
#
|
129
|
+
# # Shut them both down
|
130
|
+
# Jettywrapper.stop(jetty1_params)
|
131
|
+
# Jettywrapper.stop(jetty2_params)
|
132
|
+
# end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
@@ -6,6 +6,8 @@ require 'ruby-debug'
|
|
6
6
|
module Hydra
|
7
7
|
describe Jettywrapper do
|
8
8
|
|
9
|
+
# JETTY1 =
|
10
|
+
|
9
11
|
before(:all) do
|
10
12
|
@jetty_params = {
|
11
13
|
:quiet => false,
|
@@ -72,13 +74,72 @@ module Hydra
|
|
72
74
|
}
|
73
75
|
ts = Jettywrapper.configure(jetty_params)
|
74
76
|
Jettywrapper.any_instance.stubs(:fork).returns(5454)
|
77
|
+
ts.stop
|
75
78
|
ts.start
|
76
79
|
ts.pid.should eql(5454)
|
80
|
+
ts.stop
|
81
|
+
end
|
82
|
+
|
83
|
+
it "can pass params to a start method" do
|
84
|
+
jetty_params = {
|
85
|
+
:jetty_home => '/tmp', :jetty_port => 8777
|
86
|
+
}
|
87
|
+
ts = Jettywrapper.configure(jetty_params)
|
88
|
+
ts.stop
|
89
|
+
Jettywrapper.any_instance.stubs(:fork).returns(2323)
|
90
|
+
swp = Jettywrapper.start(jetty_params)
|
91
|
+
swp.pid.should eql(2323)
|
92
|
+
swp.pid_file.should eql("_tmp.pid")
|
93
|
+
swp.stop
|
94
|
+
end
|
95
|
+
|
96
|
+
it "checks to see if its pid files are stale" do
|
97
|
+
@pending
|
98
|
+
end
|
99
|
+
|
100
|
+
# return true if it's running, otherwise return false
|
101
|
+
it "can get the status for a given jetty instance" do
|
102
|
+
# Don't actually start jetty, just fake it
|
103
|
+
Jettywrapper.any_instance.stubs(:fork).returns(12345)
|
104
|
+
|
105
|
+
jetty_params = {
|
106
|
+
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1")
|
107
|
+
}
|
108
|
+
Jettywrapper.stop(jetty_params)
|
109
|
+
Jettywrapper.is_jetty_running?(jetty_params).should eql(false)
|
110
|
+
Jettywrapper.start(jetty_params)
|
111
|
+
Jettywrapper.is_jetty_running?(jetty_params).should eql(true)
|
112
|
+
Jettywrapper.stop(jetty_params)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "can get the pid for a given jetty instance" do
|
116
|
+
# Don't actually start jetty, just fake it
|
117
|
+
Jettywrapper.any_instance.stubs(:fork).returns(54321)
|
118
|
+
jetty_params = {
|
119
|
+
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1")
|
120
|
+
}
|
121
|
+
Jettywrapper.stop(jetty_params)
|
122
|
+
Jettywrapper.pid(jetty_params).should eql(nil)
|
123
|
+
Jettywrapper.start(jetty_params)
|
124
|
+
Jettywrapper.pid(jetty_params).should eql(54321)
|
125
|
+
Jettywrapper.stop(jetty_params)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "can pass params to a stop method" do
|
129
|
+
jetty_params = {
|
130
|
+
:jetty_home => '/tmp', :jetty_port => 8777
|
131
|
+
}
|
132
|
+
Jettywrapper.any_instance.stubs(:fork).returns(2323)
|
133
|
+
swp = Jettywrapper.start(jetty_params)
|
134
|
+
(File.file? swp.pid_path).should eql(true)
|
135
|
+
|
136
|
+
swp = Jettywrapper.stop(jetty_params)
|
137
|
+
(File.file? swp.pid_path).should eql(false)
|
77
138
|
end
|
78
139
|
|
79
140
|
it "knows what its pid file should be called" do
|
80
141
|
ts = Jettywrapper.configure(@jetty_params)
|
81
|
-
ts.pid_file.should eql("
|
142
|
+
ts.pid_file.should eql("_path_to_jetty.pid")
|
82
143
|
end
|
83
144
|
|
84
145
|
it "knows where its pid file should be written" do
|
@@ -92,7 +153,7 @@ module Hydra
|
|
92
153
|
}
|
93
154
|
ts = Jettywrapper.configure(jetty_params)
|
94
155
|
Jettywrapper.any_instance.stubs(:fork).returns(2222)
|
95
|
-
|
156
|
+
ts.stop
|
96
157
|
ts.pid_file?.should eql(false)
|
97
158
|
ts.start
|
98
159
|
ts.pid.should eql(2222)
|
@@ -101,21 +162,6 @@ module Hydra
|
|
101
162
|
pid_from_file.should eql(2222)
|
102
163
|
end
|
103
164
|
|
104
|
-
it "checks to see if jetty is running already before it starts" do
|
105
|
-
jetty_params = {
|
106
|
-
:jetty_home => '/tmp'
|
107
|
-
}
|
108
|
-
ts = Jettywrapper.configure(jetty_params)
|
109
|
-
Jettywrapper.any_instance.stubs(:fork).returns(3333)
|
110
|
-
FileUtils.rm(ts.pid_path)
|
111
|
-
ts.pid_file?.should eql(false)
|
112
|
-
ts.start
|
113
|
-
ts.pid.should eql(3333)
|
114
|
-
Jettywrapper.any_instance.stubs(:fork).returns(4444)
|
115
|
-
ts.start
|
116
|
-
ts.pid.should eql(4444)
|
117
|
-
end
|
118
|
-
|
119
165
|
end # end of instantiation context
|
120
166
|
|
121
167
|
context "logging" do
|
@@ -154,10 +200,10 @@ module Hydra
|
|
154
200
|
Jettywrapper.any_instance.stubs(:start).returns(true)
|
155
201
|
Jettywrapper.any_instance.stubs(:stop).returns(true)
|
156
202
|
error = Jettywrapper.wrap(@jetty_params) do
|
157
|
-
raise "
|
203
|
+
raise "this is an expected error message"
|
158
204
|
end
|
159
205
|
error.class.should eql(RuntimeError)
|
160
|
-
error.message.should eql("
|
206
|
+
error.message.should eql("this is an expected error message")
|
161
207
|
end
|
162
208
|
|
163
209
|
end # end of wrapping context
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# Note: These rake tasks are here mainly as examples to follow. You're going to want
|
2
|
+
# to write your own rake tasks that use the locations of your jetty instances.
|
3
|
+
|
4
|
+
require 'jettywrapper'
|
5
|
+
|
6
|
+
namespace :jettywrapper do
|
7
|
+
|
8
|
+
jetty1 = {
|
9
|
+
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../jetty1"),
|
10
|
+
:jetty_port => "8983"
|
11
|
+
}
|
12
|
+
|
13
|
+
jetty2 = {
|
14
|
+
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../jetty2"),
|
15
|
+
:jetty_port => "8984"
|
16
|
+
}
|
17
|
+
|
18
|
+
namespace :status do
|
19
|
+
|
20
|
+
desc "Return the status of jetty1"
|
21
|
+
task :jetty1 do
|
22
|
+
status = Jettywrapper.is_running?(jetty1) ? "Running: #{Jettywrapper.pid(jetty1)}" : "Not running"
|
23
|
+
puts status
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Return the status of jetty2"
|
27
|
+
task :jetty2 do
|
28
|
+
status = Jettywrapper.is_running?(jetty2) ? "Running: #{Jettywrapper.pid(jetty2)}" : "Not running"
|
29
|
+
puts status
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
namespace :start do
|
35
|
+
|
36
|
+
desc "Start jetty1"
|
37
|
+
task :jetty1 do
|
38
|
+
Jettywrapper.start(jetty1)
|
39
|
+
puts "jetty1 started at PID #{Jettywrapper.pid(jetty1)}"
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "Start jetty2"
|
43
|
+
task :jetty2 do
|
44
|
+
Jettywrapper.start(jetty2)
|
45
|
+
puts "jetty2 started at PID #{Jettywrapper.pid(jetty2)}"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
namespace :stop do
|
51
|
+
|
52
|
+
desc "stop jetty1"
|
53
|
+
task :jetty1 do
|
54
|
+
Jettywrapper.stop(jetty1)
|
55
|
+
puts "jetty1 stopped"
|
56
|
+
end
|
57
|
+
|
58
|
+
desc "stop jetty2"
|
59
|
+
task :jetty2 do
|
60
|
+
Jettywrapper.stop(jetty2)
|
61
|
+
puts "jetty1 stopped"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
namespace :restart do
|
67
|
+
|
68
|
+
desc "Restarts jetty1"
|
69
|
+
task :jetty1 do
|
70
|
+
Jettywrapper.stop(jetty1)
|
71
|
+
Jettywrapper.start(jetty1)
|
72
|
+
end
|
73
|
+
|
74
|
+
desc "Restarts jetty2"
|
75
|
+
task :jetty2 do
|
76
|
+
Jettywrapper.stop(jetty2)
|
77
|
+
Jettywrapper.start(jetty2)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
desc "Init Hydra configuration"
|
83
|
+
task :init => [:environment] do
|
84
|
+
if !ENV["environment"].nil?
|
85
|
+
RAILS_ENV = ENV["environment"]
|
86
|
+
end
|
87
|
+
|
88
|
+
JETTY_HOME_TEST = File.expand_path(File.dirname(__FILE__) + '/../../jetty-test')
|
89
|
+
JETTY_HOME_DEV = File.expand_path(File.dirname(__FILE__) + '/../../jetty-dev')
|
90
|
+
|
91
|
+
JETTY_PARAMS_TEST = {
|
92
|
+
:quiet => ENV['HYDRA_CONSOLE'] ? false : true,
|
93
|
+
:jetty_home => JETTY_HOME_TEST,
|
94
|
+
:jetty_port => 8983,
|
95
|
+
:solr_home => File.expand_path(JETTY_HOME_TEST + '/solr'),
|
96
|
+
:fedora_home => File.expand_path(JETTY_HOME_TEST + '/fedora/default')
|
97
|
+
}
|
98
|
+
|
99
|
+
JETTY_PARAMS_DEV = {
|
100
|
+
:quiet => ENV['HYDRA_CONSOLE'] ? false : true,
|
101
|
+
:jetty_home => JETTY_HOME_DEV,
|
102
|
+
:jetty_port => 8984,
|
103
|
+
:solr_home => File.expand_path(JETTY_HOME_DEV + '/solr'),
|
104
|
+
:fedora_home => File.expand_path(JETTY_HOME_DEV + '/fedora/default')
|
105
|
+
}
|
106
|
+
|
107
|
+
# If Fedora Repository connection is not already initialized, initialize it using ActiveFedora defaults
|
108
|
+
ActiveFedora.init unless Thread.current[:repo]
|
109
|
+
end
|
110
|
+
|
111
|
+
desc "Copies the default SOLR config for the bundled jetty"
|
112
|
+
task :config_solr => [:init] do
|
113
|
+
FileList['solr/conf/*'].each do |f|
|
114
|
+
cp("#{f}", JETTY_PARAMS_TEST[:solr_home] + '/conf/', :verbose => true)
|
115
|
+
cp("#{f}", JETTY_PARAMS_DEV[:solr_home] + '/conf/', :verbose => true)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
desc "Copies a custom fedora config for the bundled jetty"
|
120
|
+
task :config_fedora => [:init] do
|
121
|
+
fcfg = 'fedora/conf/fedora.fcfg'
|
122
|
+
if File.exists?(fcfg)
|
123
|
+
puts "copying over fedora.fcfg"
|
124
|
+
cp("#{fcfg}", JETTY_PARAMS_TEST[:fedora_home] + '/server/config/', :verbose => true)
|
125
|
+
cp("#{fcfg}", JETTY_PARAMS_DEV[:fedora_home] + '/server/config/', :verbose => true)
|
126
|
+
else
|
127
|
+
puts "#{fcfg} file not found -- skipping fedora config"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
desc "Copies the default Solr & Fedora configs into the bundled jetty"
|
132
|
+
task :config do
|
133
|
+
Rake::Task["hydra:jetty:config_fedora"].invoke
|
134
|
+
Rake::Task["hydra:jetty:config_solr"].invoke
|
135
|
+
end
|
136
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jettywrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bess Sadler
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
18
|
+
date: 2011-06-24 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -223,12 +223,14 @@ files:
|
|
223
223
|
- Gemfile
|
224
224
|
- README.textile
|
225
225
|
- Rakefile
|
226
|
+
- TODO.txt
|
226
227
|
- jettywrapper.gemspec
|
227
228
|
- lib/jettywrapper.rb
|
228
229
|
- lib/jettywrapper/version.rb
|
229
|
-
- spec/lib/jettywrapper_integration_spec.
|
230
|
+
- spec/lib/jettywrapper_integration_spec.run_by_hand
|
230
231
|
- spec/lib/jettywrapper_spec.rb
|
231
232
|
- spec/spec_helper.rb
|
233
|
+
- tasks/jettywrapper.rake
|
232
234
|
has_rdoc: true
|
233
235
|
homepage: https://github.com/projecthydra/jettywrapper
|
234
236
|
licenses: []
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
-
require File.join(File.dirname(__FILE__), "/../../lib/jettywrapper")
|
3
|
-
require 'rubygems'
|
4
|
-
require 'ruby-debug'
|
5
|
-
require 'uri'
|
6
|
-
|
7
|
-
module Hydra
|
8
|
-
describe Jettywrapper do
|
9
|
-
context "integration" do
|
10
|
-
before(:all) do
|
11
|
-
$stderr.reopen("/dev/null", "w")
|
12
|
-
end
|
13
|
-
|
14
|
-
it "starts" do
|
15
|
-
|
16
|
-
jetty_params = {
|
17
|
-
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1")
|
18
|
-
|
19
|
-
}
|
20
|
-
Jettywrapper.configure(jetty_params)
|
21
|
-
ts = Jettywrapper.instance
|
22
|
-
ts.logger.debug "Stopping jetty from rspec."
|
23
|
-
ts.stop
|
24
|
-
ts.start
|
25
|
-
ts.logger.debug "Jetty started from rspec at #{ts.pid}"
|
26
|
-
pid_from_file = File.open( ts.pid_path ) { |f| f.gets.to_i }
|
27
|
-
ts.pid.should eql(pid_from_file)
|
28
|
-
sleep 15 # give jetty time to start
|
29
|
-
|
30
|
-
# Can we connect to solr?
|
31
|
-
require 'net/http'
|
32
|
-
response = Net::HTTP.get_response(URI.parse("http://localhost:8888/solr/admin/"))
|
33
|
-
response.code.should eql("200")
|
34
|
-
ts.stop
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
it "won't start if it's already running" do
|
39
|
-
jetty_params = {
|
40
|
-
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1")
|
41
|
-
|
42
|
-
}
|
43
|
-
Jettywrapper.configure(jetty_params)
|
44
|
-
ts = Jettywrapper.instance
|
45
|
-
ts.logger.debug "Stopping jetty from rspec."
|
46
|
-
ts.stop
|
47
|
-
ts.start
|
48
|
-
sleep 15
|
49
|
-
ts.logger.debug "Jetty started from rspec at #{ts.pid}"
|
50
|
-
response = Net::HTTP.get_response(URI.parse("http://localhost:8888/solr/admin/"))
|
51
|
-
response.code.should eql("200")
|
52
|
-
lambda { ts.start }.should raise_exception(/Server is already running/)
|
53
|
-
ts.stop
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|