Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sunspot_solr/lib/sunspot/solr/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@ def run
def stop
if File.exist?(pid_path)
pid = IO.read(pid_path).to_i
pgpid = Process.getpgid(pid) # process group id for started process
# required to kill child processes
begin
Process.kill('TERM', pid)
Process.kill('TERM', -pgpid) # negative argument means that
# process group is killed
rescue Errno::ESRCH
raise NotRunningError, "Process with PID #{pid} is no longer running"
ensure
Expand Down
30 changes: 26 additions & 4 deletions sunspot_solr/spec/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
end

it 'runs Solr with specified data dir' do
@server.solr_data_dir = '/var/solr/data'
@server.should_receive(:exec).with(%r(-Dsolr\.data\.dir=/var/solr/data))
@server.solr_data_dir = '/tmp/solr/data'
@server.should_receive(:exec).with(%r(-Dsolr\.data\.dir=/tmp/solr/data))
@server.run
end

it 'runs Solr with specified Solr home' do
@server.solr_home = '/var/solr'
@server.should_receive(:exec).with(%r(-Dsolr\.solr\.home=/var/solr))
@server.solr_home = '/tmp/solr'
@server.should_receive(:exec).with(%r(-Dsolr\.solr\.home=/tmp/solr))
@server.run
end

Expand All @@ -59,6 +59,28 @@
}.to raise_error(Sunspot::Solr::Server::JavaMissing)
end

context 'when solr process already exists' do
let(:pid_path) { @server.pid_path }

before do
File.stub(:exist?)
.with(pid_path)
.and_return(true)
IO.stub(:read)
.with(pid_path)
.and_return(8000)
end
it 'kills solr process and child processes on stop' do
FileUtils.should_receive(:rm).with(pid_path)
Process.should_receive(:getpgid)
.with(8000)
.and_return(8001)
Process.should_receive(:kill).with("TERM", -8001)

@server.stop
end
end

describe 'with logging' do
before :each do
@server.log_level = 'info'
Expand Down