diff --git a/sunspot_solr/lib/sunspot/solr/server.rb b/sunspot_solr/lib/sunspot/solr/server.rb index 14d394558..fd0e42452 100644 --- a/sunspot_solr/lib/sunspot/solr/server.rb +++ b/sunspot_solr/lib/sunspot/solr/server.rb @@ -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 diff --git a/sunspot_solr/spec/server_spec.rb b/sunspot_solr/spec/server_spec.rb index 1c0056860..2622e1af1 100644 --- a/sunspot_solr/spec/server_spec.rb +++ b/sunspot_solr/spec/server_spec.rb @@ -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 @@ -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'