Skip to content

Commit

Permalink
Merge pull request #84 from driskell/features/stdin_command_line
Browse files Browse the repository at this point in the history
Add -stdin command line argument and stdin configuration section, and re...
  • Loading branch information
driskell committed Jan 17, 2015
2 parents 5d7b210 + 6b8f1ad commit 44c6cfa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
42 changes: 19 additions & 23 deletions spec/courier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
"ssl ca": "#{@ssl_cert.path}",
"servers": [ "localhost:#{server_port}" ]
},
"files": [
{
"paths": [ "-" ]
}
]
"stdin": {
"fields": { "type": "stdin" }
}
}
config

Expand All @@ -49,8 +47,11 @@
expect(e['message']).to eq "stdin line test #{i}"
expect(e['host']).to eq host
expect(e['path']).to eq '-'
expect(e['type']).to eq 'stdin'
i += 1
end

stdin_shutdown
end

it 'should split lines that are too long' do
Expand All @@ -59,12 +60,7 @@
"network": {
"ssl ca": "#{@ssl_cert.path}",
"servers": [ "127.0.0.1:#{server_port}" ]
},
"files": [
{
"paths": [ "-" ]
}
]
}
}
config

Expand All @@ -90,6 +86,8 @@
expect(e['path']).to eq '-'
i += 1
end

stdin_shutdown
end

it 'should follow a file from the end' do
Expand Down Expand Up @@ -496,12 +494,9 @@
"ssl ca": "#{@ssl_cert.path}",
"servers": [ "127.0.0.1:#{server_port}" ]
},
"files": [
{
"paths": [ "-" ],
"fields": { "array": [ 1, 2 ] }
}
]
"stdin": {
"fields": { "array": [ 1, 2 ] }
}
}
config

Expand All @@ -521,6 +516,8 @@
expect(e['path']).to eq '-'
i += 1
end

stdin_shutdown
end

it 'should allow dictionaries inside field configuration' do
Expand All @@ -530,12 +527,9 @@
"ssl ca": "#{@ssl_cert.path}",
"servers": [ "127.0.0.1:#{server_port}" ]
},
"files": [
{
"paths": [ "-" ],
"fields": { "dict": { "first": "first", "second": 5 } }
}
]
"stdin": {
"fields": { "dict": { "first": "first", "second": 5 } }
}
}
config

Expand All @@ -555,6 +549,8 @@
expect(e['path']).to eq '-'
i += 1
end

stdin_shutdown
end

it 'should accept globs of configuration files to include' do
Expand Down
17 changes: 17 additions & 0 deletions spec/lib/helpers/log-courier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def startup(args = {})
_write_config config

if args[:stdin]
args[:args] += ' ' if args[:args]
args[:args] += '-stdin=true'
@log_courier_mode = 'r+'
else
@log_courier_mode = 'r'
Expand Down Expand Up @@ -113,6 +115,21 @@ def _write_config(config)
@config.close
end

def stdin_shutdown
return unless @log_courier_mode == 'r+'
begin
# If this fails, don't bother closing write again
@log_courier_mode = 'r'
Timeout.timeout(30) do
# Close and wait
@log_courier.close_write
@log_courier_reader.join
end
rescue Timeout::Error
fail "Log-courier did not shutdown on stdin EOF"
end
end

def shutdown
puts 'Shutting down Log Courier'
return if @log_courier.nil?
Expand Down

0 comments on commit 44c6cfa

Please sign in to comment.