jettywrapper 0.0.5 → 0.0.6
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/lib/jettywrapper.rb +89 -49
- data/lib/jettywrapper/version.rb +1 -1
- metadata +3 -3
data/lib/jettywrapper.rb
CHANGED
@@ -4,6 +4,7 @@ class Jettywrapper
|
|
4
4
|
|
5
5
|
require 'singleton'
|
6
6
|
include Singleton
|
7
|
+
require 'ftools'
|
7
8
|
|
8
9
|
attr_accessor :pid # If Jettywrapper is running, what pid is it running as?
|
9
10
|
attr_accessor :port # What port should jetty start on? Default is 8888
|
@@ -14,9 +15,14 @@ class Jettywrapper
|
|
14
15
|
attr_accessor :fedora_home # Where is fedora located? Default is jetty_home/fedora
|
15
16
|
|
16
17
|
# configure the singleton with some defaults
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def initialize(params = {})
|
19
|
+
@pid = nil
|
20
|
+
if defined?(Rails.root)
|
21
|
+
@base_path = Rails.root
|
22
|
+
else
|
23
|
+
@base_path = "."
|
24
|
+
end
|
25
|
+
end
|
20
26
|
|
21
27
|
class << self
|
22
28
|
|
@@ -95,63 +101,97 @@ class Jettywrapper
|
|
95
101
|
"java -Djetty.port=#{@port} -Dsolr.solr.home=#{@solr_home} -Dfedora.home=#{@fedora_home} -jar start.jar"
|
96
102
|
end
|
97
103
|
|
104
|
+
# Start the jetty server. Check the pid file to see if it is running already,
|
105
|
+
# and stop it if so. After you start jetty, write the PID to a file.
|
106
|
+
|
98
107
|
def start
|
99
108
|
puts "jetty_home: #{@jetty_home}"
|
100
109
|
puts "solr_home: #{@solr_home}"
|
101
110
|
puts "fedora_home: #{@fedora_home}"
|
102
111
|
puts "jetty_command: #{jetty_command}"
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
if RUBY_PLATFORM =~ /mswin32/
|
111
|
-
require 'win32/process'
|
112
|
-
|
113
|
-
# start jetty for windows
|
114
|
-
def platform_specific_start
|
115
|
-
puts "Starting Jetty on windows"
|
116
|
-
Dir.chdir(@jetty_home) do
|
117
|
-
@pid = Process.create(
|
118
|
-
:app_name => jetty_command,
|
119
|
-
:creation_flags => Process::DETACHED_PROCESS,
|
120
|
-
:process_inherit => false,
|
121
|
-
:thread_inherit => true,
|
122
|
-
:cwd => "#{@jetty_home}"
|
123
|
-
).process_id
|
112
|
+
if pid
|
113
|
+
begin
|
114
|
+
Process.kill(0,pid)
|
115
|
+
raise("Server is already running with PID #{pid}")
|
116
|
+
rescue Errno::ESRCH
|
117
|
+
STDERR.puts("Removing stale PID file at #{pid_path}")
|
118
|
+
File.delete(pid_path)
|
124
119
|
end
|
125
120
|
end
|
126
|
-
|
127
|
-
|
128
|
-
def platform_specific_stop
|
129
|
-
Process.kill(1, @pid)
|
130
|
-
Process.wait
|
121
|
+
Dir.chdir(@jetty_home) do
|
122
|
+
self.send "#{platform}_process".to_sym
|
131
123
|
end
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
124
|
+
File.makedirs(pid_dir) unless File.directory?(pid_dir)
|
125
|
+
begin
|
126
|
+
f = File.new(pid_path, "w")
|
127
|
+
rescue Errno::ENOENT, Errno::EACCES
|
128
|
+
f = File.new(File.join(@base_path,'tmp',pid_file),"w")
|
136
129
|
end
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
130
|
+
f.puts "#{@pid}"
|
131
|
+
f.close
|
132
|
+
end
|
133
|
+
|
134
|
+
def stop
|
135
|
+
puts "stopping"
|
136
|
+
if pid
|
137
|
+
begin
|
138
|
+
self.send "#{platform}_stop".to_sym
|
139
|
+
rescue Errno::ESRCH
|
140
|
+
STDERR.puts("Removing stale PID file at #{pid_path}")
|
146
141
|
end
|
142
|
+
FileUtils.rm(pid_path)
|
147
143
|
end
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
144
|
+
end
|
145
|
+
|
146
|
+
def win_process
|
147
|
+
@pid = Process.create(
|
148
|
+
:app_name => jetty_command,
|
149
|
+
:creation_flags => Process::DETACHED_PROCESS,
|
150
|
+
:process_inherit => false,
|
151
|
+
:thread_inherit => true,
|
152
|
+
:cwd => "#{@jetty_home}"
|
153
|
+
).process_id
|
154
|
+
end
|
155
|
+
|
156
|
+
def platform
|
157
|
+
case RUBY_PLATFORM
|
158
|
+
when /mswin32/
|
159
|
+
return 'win'
|
160
|
+
else
|
161
|
+
return 'nix'
|
154
162
|
end
|
155
|
-
|
163
|
+
end
|
164
|
+
|
165
|
+
def nix_process
|
166
|
+
@pid = fork do
|
167
|
+
STDERR.close if @quiet
|
168
|
+
exec jetty_command
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# stop a running solr server
|
173
|
+
def win_stop
|
174
|
+
Process.kill(1, @pid)
|
175
|
+
end
|
176
|
+
|
177
|
+
def nix_stop
|
178
|
+
Process.kill('TERM',pid)
|
179
|
+
end
|
180
|
+
|
181
|
+
def pid_path
|
182
|
+
File.join(pid_dir, pid_file)
|
183
|
+
end
|
184
|
+
|
185
|
+
def pid_file
|
186
|
+
@pid_file || 'hydra-jetty.pid'
|
187
|
+
end
|
188
|
+
|
189
|
+
def pid_dir
|
190
|
+
File.expand_path(@pid_dir || File.join(@base_path,'tmp','pids'))
|
191
|
+
end
|
192
|
+
|
193
|
+
def pid
|
194
|
+
@pid || File.open( pid_path ) { |f| return f.gets.to_i } if File.exist?(pid_path)
|
195
|
+
end
|
156
196
|
|
157
197
|
end
|
data/lib/jettywrapper/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
GEMVERSION = "0.0.
|
1
|
+
GEMVERSION = "0.0.6"
|
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: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bess Sadler
|