jettywrapper 0.0.6 → 0.0.7
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/.gitignore +1 -0
- data/.gitmodules +3 -0
- data/jettywrapper.gemspec +3 -0
- data/lib/jettywrapper.rb +41 -19
- data/lib/jettywrapper/version.rb +1 -1
- data/spec/lib/jettywrapper_integration_spec.rb +59 -0
- data/spec/lib/jettywrapper_spec.rb +51 -2
- metadata +54 -24
data/.gitignore
CHANGED
data/.gitmodules
ADDED
data/jettywrapper.gemspec
CHANGED
@@ -19,6 +19,9 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
s.required_rubygems_version = ">= 1.3.6"
|
21
21
|
|
22
|
+
s.add_dependency "logger"
|
23
|
+
s.add_dependency "loggable"
|
24
|
+
|
22
25
|
# Bundler will install these gems too if you've checked this out from source from git and run 'bundle install'
|
23
26
|
# It will not add these as dependencies if you require lyber-core for other projects
|
24
27
|
s.add_development_dependency "ruby-debug"
|
data/lib/jettywrapper.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# Jettywrapper is a Singleton class, so you can only create one jetty instance at a time.
|
2
|
+
require 'rubygems'
|
3
|
+
require 'logger'
|
4
|
+
require 'loggable'
|
5
|
+
require 'singleton'
|
6
|
+
require 'ftools'
|
2
7
|
|
3
8
|
class Jettywrapper
|
4
9
|
|
5
|
-
require 'singleton'
|
6
10
|
include Singleton
|
7
|
-
|
11
|
+
include Loggable
|
8
12
|
|
9
13
|
attr_accessor :pid # If Jettywrapper is running, what pid is it running as?
|
10
14
|
attr_accessor :port # What port should jetty start on? Default is 8888
|
@@ -13,15 +17,19 @@ class Jettywrapper
|
|
13
17
|
attr_accessor :quiet # Keep quiet about jetty output?
|
14
18
|
attr_accessor :solr_home # Where is solr located? Default is jetty_home/solr
|
15
19
|
attr_accessor :fedora_home # Where is fedora located? Default is jetty_home/fedora
|
20
|
+
attr_accessor :logger # Where should logs be written?
|
21
|
+
attr_accessor :base_path # The root of the application. Used for determining where log files and PID files should go.
|
16
22
|
|
17
23
|
# configure the singleton with some defaults
|
18
24
|
def initialize(params = {})
|
19
|
-
@pid = nil
|
25
|
+
# @pid = nil
|
20
26
|
if defined?(Rails.root)
|
21
27
|
@base_path = Rails.root
|
22
28
|
else
|
23
29
|
@base_path = "."
|
24
30
|
end
|
31
|
+
@logger = Logger.new("#{@base_path}/tmp/jettywrapper-debug.log")
|
32
|
+
@logger.debug 'Initializing jettywrapper'
|
25
33
|
end
|
26
34
|
|
27
35
|
class << self
|
@@ -93,9 +101,10 @@ class Jettywrapper
|
|
93
101
|
|
94
102
|
return error
|
95
103
|
end
|
96
|
-
|
97
|
-
|
98
|
-
|
104
|
+
|
105
|
+
end #end of class << self
|
106
|
+
|
107
|
+
|
99
108
|
# What command is being run to invoke jetty?
|
100
109
|
def jetty_command
|
101
110
|
"java -Djetty.port=#{@port} -Dsolr.solr.home=#{@solr_home} -Dfedora.home=#{@fedora_home} -jar start.jar"
|
@@ -103,18 +112,19 @@ class Jettywrapper
|
|
103
112
|
|
104
113
|
# Start the jetty server. Check the pid file to see if it is running already,
|
105
114
|
# and stop it if so. After you start jetty, write the PID to a file.
|
106
|
-
|
107
115
|
def start
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
116
|
+
@logger.debug "Starting jetty with these values: "
|
117
|
+
@logger.debug "jetty_home: #{@jetty_home}"
|
118
|
+
@logger.debug "solr_home: #{@solr_home}"
|
119
|
+
@logger.debug "fedora_home: #{@fedora_home}"
|
120
|
+
@logger.debug "jetty_command: #{jetty_command}"
|
121
|
+
|
112
122
|
if pid
|
113
123
|
begin
|
114
124
|
Process.kill(0,pid)
|
115
125
|
raise("Server is already running with PID #{pid}")
|
116
126
|
rescue Errno::ESRCH
|
117
|
-
|
127
|
+
@logger.warn "Removing stale PID file at #{pid_path}"
|
118
128
|
File.delete(pid_path)
|
119
129
|
end
|
120
130
|
end
|
@@ -129,15 +139,16 @@ class Jettywrapper
|
|
129
139
|
end
|
130
140
|
f.puts "#{@pid}"
|
131
141
|
f.close
|
142
|
+
@logger.debug "Wrote pid file to #{pid_path} with value #{@pid}"
|
132
143
|
end
|
133
144
|
|
134
145
|
def stop
|
135
|
-
|
146
|
+
@logger.warn "stopping jetty... "
|
136
147
|
if pid
|
137
148
|
begin
|
138
149
|
self.send "#{platform}_stop".to_sym
|
139
150
|
rescue Errno::ESRCH
|
140
|
-
|
151
|
+
@logger.warn "Removing stale PID file at #{pid_path}"
|
141
152
|
end
|
142
153
|
FileUtils.rm(pid_path)
|
143
154
|
end
|
@@ -164,17 +175,19 @@ class Jettywrapper
|
|
164
175
|
|
165
176
|
def nix_process
|
166
177
|
@pid = fork do
|
167
|
-
STDERR.close if @quiet
|
178
|
+
# STDERR.close if @quiet
|
168
179
|
exec jetty_command
|
169
180
|
end
|
170
181
|
end
|
171
182
|
|
172
|
-
# stop
|
183
|
+
# stop jetty the windows way
|
173
184
|
def win_stop
|
174
|
-
Process.kill(1,
|
185
|
+
Process.kill(1, pid)
|
175
186
|
end
|
176
187
|
|
188
|
+
# stop jetty the *nix way
|
177
189
|
def nix_stop
|
190
|
+
@logger.debug "Killing process #{pid}"
|
178
191
|
Process.kill('TERM',pid)
|
179
192
|
end
|
180
193
|
|
@@ -182,16 +195,25 @@ class Jettywrapper
|
|
182
195
|
File.join(pid_dir, pid_file)
|
183
196
|
end
|
184
197
|
|
198
|
+
# The file where the process ID will be written
|
185
199
|
def pid_file
|
186
200
|
@pid_file || 'hydra-jetty.pid'
|
187
201
|
end
|
188
202
|
|
203
|
+
# The directory where the pid_file will be written
|
189
204
|
def pid_dir
|
190
205
|
File.expand_path(@pid_dir || File.join(@base_path,'tmp','pids'))
|
191
206
|
end
|
207
|
+
|
208
|
+
# Check to see if there is a pid file already
|
209
|
+
# @return true if the file exists, otherwise false
|
210
|
+
def pid_file?
|
211
|
+
return true if File.exist?(pid_path)
|
212
|
+
false
|
213
|
+
end
|
192
214
|
|
193
215
|
def pid
|
194
|
-
|
216
|
+
@pid || File.open( pid_path ) { |f| return f.gets.to_i } if File.exist?(pid_path)
|
195
217
|
end
|
196
|
-
|
218
|
+
|
197
219
|
end
|
data/lib/jettywrapper/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
GEMVERSION = "0.0.
|
1
|
+
GEMVERSION = "0.0.7"
|
@@ -0,0 +1,59 @@
|
|
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
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
2
|
require File.join(File.dirname(__FILE__), "/../../lib/jettywrapper")
|
3
|
+
require 'rubygems'
|
4
|
+
require 'ruby-debug'
|
3
5
|
|
4
6
|
module Hydra
|
5
7
|
describe Jettywrapper do
|
@@ -74,8 +76,56 @@ module Hydra
|
|
74
76
|
ts.pid.should eql(5454)
|
75
77
|
end
|
76
78
|
|
79
|
+
it "knows what its pid file should be called" do
|
80
|
+
ts = Jettywrapper.configure(@jetty_params)
|
81
|
+
ts.pid_file.should eql("hydra-jetty.pid")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "knows where its pid file should be written" do
|
85
|
+
ts = Jettywrapper.configure(@jetty_params)
|
86
|
+
ts.pid_dir.should eql(File.expand_path("#{ts.base_path}/tmp/pids"))
|
87
|
+
end
|
88
|
+
|
89
|
+
it "writes a pid to a file when it is started" do
|
90
|
+
jetty_params = {
|
91
|
+
:jetty_home => '/tmp'
|
92
|
+
}
|
93
|
+
ts = Jettywrapper.configure(jetty_params)
|
94
|
+
Jettywrapper.any_instance.stubs(:fork).returns(2222)
|
95
|
+
FileUtils.rm(ts.pid_path)
|
96
|
+
ts.pid_file?.should eql(false)
|
97
|
+
ts.start
|
98
|
+
ts.pid.should eql(2222)
|
99
|
+
ts.pid_file?.should eql(true)
|
100
|
+
pid_from_file = File.open( ts.pid_path ) { |f| f.gets.to_i }
|
101
|
+
pid_from_file.should eql(2222)
|
102
|
+
end
|
103
|
+
|
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
|
+
|
77
119
|
end # end of instantiation context
|
78
120
|
|
121
|
+
context "logging" do
|
122
|
+
it "has a logger" do
|
123
|
+
ts = Jettywrapper.configure(@jetty_params)
|
124
|
+
ts.logger.should be_kind_of(Logger)
|
125
|
+
end
|
126
|
+
|
127
|
+
end # end of logging context
|
128
|
+
|
79
129
|
context "wrapping a task" do
|
80
130
|
it "wraps another method" do
|
81
131
|
Jettywrapper.any_instance.stubs(:start).returns(true)
|
@@ -110,7 +160,6 @@ module Hydra
|
|
110
160
|
error.message.should eql("foo")
|
111
161
|
end
|
112
162
|
|
113
|
-
end
|
114
|
-
|
163
|
+
end # end of wrapping context
|
115
164
|
end
|
116
165
|
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: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
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-22 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -29,8 +29,8 @@ dependencies:
|
|
29
29
|
- 0
|
30
30
|
version: "0"
|
31
31
|
requirement: *id001
|
32
|
-
type: :
|
33
|
-
name:
|
32
|
+
type: :runtime
|
33
|
+
name: logger
|
34
34
|
prerelease: false
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
@@ -43,11 +43,39 @@ dependencies:
|
|
43
43
|
- 0
|
44
44
|
version: "0"
|
45
45
|
requirement: *id002
|
46
|
+
type: :runtime
|
47
|
+
name: loggable
|
48
|
+
prerelease: false
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
requirement: *id003
|
60
|
+
type: :development
|
61
|
+
name: ruby-debug
|
62
|
+
prerelease: false
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
requirement: *id004
|
46
74
|
type: :development
|
47
75
|
name: ruby-debug-base
|
48
76
|
prerelease: false
|
49
77
|
- !ruby/object:Gem::Dependency
|
50
|
-
version_requirements: &
|
78
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
51
79
|
none: false
|
52
80
|
requirements:
|
53
81
|
- - <
|
@@ -57,12 +85,12 @@ dependencies:
|
|
57
85
|
- 2
|
58
86
|
- 0
|
59
87
|
version: "2.0"
|
60
|
-
requirement: *
|
88
|
+
requirement: *id005
|
61
89
|
type: :development
|
62
90
|
name: rspec
|
63
91
|
prerelease: false
|
64
92
|
- !ruby/object:Gem::Dependency
|
65
|
-
version_requirements: &
|
93
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
66
94
|
none: false
|
67
95
|
requirements:
|
68
96
|
- - <
|
@@ -73,12 +101,12 @@ dependencies:
|
|
73
101
|
- 0
|
74
102
|
- 0
|
75
103
|
version: 2.0.0
|
76
|
-
requirement: *
|
104
|
+
requirement: *id006
|
77
105
|
type: :development
|
78
106
|
name: rspec-rails
|
79
107
|
prerelease: false
|
80
108
|
- !ruby/object:Gem::Dependency
|
81
|
-
version_requirements: &
|
109
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
82
110
|
none: false
|
83
111
|
requirements:
|
84
112
|
- - ">="
|
@@ -87,12 +115,12 @@ dependencies:
|
|
87
115
|
segments:
|
88
116
|
- 0
|
89
117
|
version: "0"
|
90
|
-
requirement: *
|
118
|
+
requirement: *id007
|
91
119
|
type: :development
|
92
120
|
name: mocha
|
93
121
|
prerelease: false
|
94
122
|
- !ruby/object:Gem::Dependency
|
95
|
-
version_requirements: &
|
123
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
96
124
|
none: false
|
97
125
|
requirements:
|
98
126
|
- - ">="
|
@@ -103,12 +131,12 @@ dependencies:
|
|
103
131
|
- 8
|
104
132
|
- 5
|
105
133
|
version: 0.8.5
|
106
|
-
requirement: *
|
134
|
+
requirement: *id008
|
107
135
|
type: :development
|
108
136
|
name: cucumber
|
109
137
|
prerelease: false
|
110
138
|
- !ruby/object:Gem::Dependency
|
111
|
-
version_requirements: &
|
139
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
112
140
|
none: false
|
113
141
|
requirements:
|
114
142
|
- - ">="
|
@@ -117,12 +145,12 @@ dependencies:
|
|
117
145
|
segments:
|
118
146
|
- 0
|
119
147
|
version: "0"
|
120
|
-
requirement: *
|
148
|
+
requirement: *id009
|
121
149
|
type: :development
|
122
150
|
name: cucumber-rails
|
123
151
|
prerelease: false
|
124
152
|
- !ruby/object:Gem::Dependency
|
125
|
-
version_requirements: &
|
153
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
126
154
|
none: false
|
127
155
|
requirements:
|
128
156
|
- - ">="
|
@@ -131,12 +159,12 @@ dependencies:
|
|
131
159
|
segments:
|
132
160
|
- 0
|
133
161
|
version: "0"
|
134
|
-
requirement: *
|
162
|
+
requirement: *id010
|
135
163
|
type: :development
|
136
164
|
name: gherkin
|
137
165
|
prerelease: false
|
138
166
|
- !ruby/object:Gem::Dependency
|
139
|
-
version_requirements: &
|
167
|
+
version_requirements: &id011 !ruby/object:Gem::Requirement
|
140
168
|
none: false
|
141
169
|
requirements:
|
142
170
|
- - ">="
|
@@ -145,12 +173,12 @@ dependencies:
|
|
145
173
|
segments:
|
146
174
|
- 0
|
147
175
|
version: "0"
|
148
|
-
requirement: *
|
176
|
+
requirement: *id011
|
149
177
|
type: :development
|
150
178
|
name: rcov
|
151
179
|
prerelease: false
|
152
180
|
- !ruby/object:Gem::Dependency
|
153
|
-
version_requirements: &
|
181
|
+
version_requirements: &id012 !ruby/object:Gem::Requirement
|
154
182
|
none: false
|
155
183
|
requirements:
|
156
184
|
- - "="
|
@@ -161,12 +189,12 @@ dependencies:
|
|
161
189
|
- 6
|
162
190
|
- 5
|
163
191
|
version: 0.6.5
|
164
|
-
requirement: *
|
192
|
+
requirement: *id012
|
165
193
|
type: :development
|
166
194
|
name: yard
|
167
195
|
prerelease: false
|
168
196
|
- !ruby/object:Gem::Dependency
|
169
|
-
version_requirements: &
|
197
|
+
version_requirements: &id013 !ruby/object:Gem::Requirement
|
170
198
|
none: false
|
171
199
|
requirements:
|
172
200
|
- - ">="
|
@@ -175,7 +203,7 @@ dependencies:
|
|
175
203
|
segments:
|
176
204
|
- 0
|
177
205
|
version: "0"
|
178
|
-
requirement: *
|
206
|
+
requirement: *id013
|
179
207
|
type: :development
|
180
208
|
name: RedCloth
|
181
209
|
prerelease: false
|
@@ -190,6 +218,7 @@ extra_rdoc_files: []
|
|
190
218
|
|
191
219
|
files:
|
192
220
|
- .gitignore
|
221
|
+
- .gitmodules
|
193
222
|
- .rvmrc
|
194
223
|
- Gemfile
|
195
224
|
- README.textile
|
@@ -197,6 +226,7 @@ files:
|
|
197
226
|
- jettywrapper.gemspec
|
198
227
|
- lib/jettywrapper.rb
|
199
228
|
- lib/jettywrapper/version.rb
|
229
|
+
- spec/lib/jettywrapper_integration_spec.rb
|
200
230
|
- spec/lib/jettywrapper_spec.rb
|
201
231
|
- spec/spec_helper.rb
|
202
232
|
has_rdoc: true
|