mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
Merge pull request #1212 from colinsurprenant/agent_stall
fix agent stall when also using web argument
This commit is contained in:
commit
357b561acc
2 changed files with 61 additions and 6 deletions
|
@ -90,6 +90,10 @@ end
|
|||
class LogStash::Runner
|
||||
include LogStash::Program
|
||||
|
||||
def initialize
|
||||
@runners = []
|
||||
end
|
||||
|
||||
def main(args)
|
||||
require "logstash/util"
|
||||
require "stud/trap"
|
||||
|
@ -108,7 +112,6 @@ class LogStash::Runner
|
|||
|
||||
args = [nil] if args.empty?
|
||||
|
||||
@runners = []
|
||||
while args != nil && !args.empty?
|
||||
args = run(args)
|
||||
end
|
||||
|
@ -182,15 +185,16 @@ class LogStash::Runner
|
|||
agent = LogStash::Agent.new($0)
|
||||
begin
|
||||
agent.parse(args)
|
||||
@runners << Stud::Task.new { agent.execute }
|
||||
rescue Clamp::HelpWanted => e
|
||||
puts e.command.help
|
||||
show_help(e.command)
|
||||
return []
|
||||
rescue Clamp::UsageError => e
|
||||
# If 'too many arguments' then give the arguments to
|
||||
# the next command. Otherwise it's a real error.
|
||||
raise if e.message != "too many arguments"
|
||||
remaining = agent.remaining_arguments
|
||||
end
|
||||
@runners << Stud::Task.new { agent.execute }
|
||||
|
||||
return remaining
|
||||
end
|
||||
|
@ -224,8 +228,17 @@ class LogStash::Runner
|
|||
return args
|
||||
end # def run
|
||||
|
||||
# @return true if this file is the main file being run and not via rspec
|
||||
def self.autorun?
|
||||
# caller is the current execution stack
|
||||
$0 == __FILE__ && caller.none?{|entry| entry =~ /rspec/}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def show_help(command)
|
||||
puts command.help
|
||||
end
|
||||
end # class LogStash::Runner
|
||||
|
||||
if $0 == __FILE__
|
||||
LogStash::Runner.new.main(ARGV)
|
||||
end
|
||||
LogStash::Runner.new.main(ARGV) if LogStash::Runner.autorun?
|
||||
|
|
42
spec/runner_spec.rb
Normal file
42
spec/runner_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require "logstash/runner"
|
||||
require "logstash/agent"
|
||||
require "logstash/kibana"
|
||||
require "stud/task"
|
||||
|
||||
class NullRunner
|
||||
def run(args); end
|
||||
end
|
||||
|
||||
describe LogStash::Runner do
|
||||
|
||||
context "argument parsing" do
|
||||
it "should run agent" do
|
||||
expect(Stud::Task).to receive(:new).once.and_return(nil)
|
||||
args = ["agent", "-e", ""]
|
||||
expect(subject.run(args)).to eq(nil)
|
||||
end
|
||||
|
||||
it "should run agent help" do
|
||||
expect(subject).to receive(:show_help).once.and_return(nil)
|
||||
args = ["agent", "-h"]
|
||||
expect(subject.run(args)).to eq([])
|
||||
end
|
||||
|
||||
it "should run agent help and not run following commands" do
|
||||
expect(subject).to receive(:show_help).once.and_return(nil)
|
||||
args = ["agent", "-h", "web"]
|
||||
expect(subject.run(args)).to eq([])
|
||||
end
|
||||
|
||||
it "should run agent and web" do
|
||||
expect(Stud::Task).to receive(:new).once
|
||||
args = ["agent", "-e", "", "web"]
|
||||
args = subject.run(args)
|
||||
expect(args).to eq(["web"])
|
||||
|
||||
expect(LogStash::Kibana::Runner).to receive(:new).once.and_return(NullRunner.new)
|
||||
args = subject.run(args)
|
||||
expect(args).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue