Skip to content

Commit

Permalink
Merge pull request elastic#1212 from colinsurprenant/agent_stall
Browse files Browse the repository at this point in the history
fix agent stall when also using web argument
  • Loading branch information
jordansissel committed Apr 2, 2014
2 parents 816d966 + 74d2fe2 commit 357b561
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/logstash/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def wait
class LogStash::Runner
include LogStash::Program

def initialize
@runners = []
end

def main(args)
require "logstash/util"
require "stud/trap"
Expand All @@ -108,7 +112,6 @@ def main(args)

args = [nil] if args.empty?

@runners = []
while args != nil && !args.empty?
args = run(args)
end
Expand Down Expand Up @@ -182,15 +185,16 @@ def run(args)
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
Expand Down Expand Up @@ -224,8 +228,17 @@ def run(args)
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 changes: 42 additions & 0 deletions spec/runner_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 357b561

Please sign in to comment.