fluentd 1.11.1-x86-mingw32 → 1.12.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fluentd might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
- data/.github/ISSUE_TEMPLATE/config.yml +5 -0
- data/.github/workflows/stale-actions.yml +22 -0
- data/.travis.yml +22 -2
- data/CHANGELOG.md +111 -0
- data/README.md +1 -1
- data/appveyor.yml +3 -0
- data/bin/fluent-cap-ctl +7 -0
- data/bin/fluent-ctl +7 -0
- data/example/copy_roundrobin.conf +3 -3
- data/example/counter.conf +1 -1
- data/example/filter_stdout.conf +2 -2
- data/example/{in_dummy_blocks.conf → in_sample_blocks.conf} +4 -4
- data/example/{in_dummy_with_compression.conf → in_sample_with_compression.conf} +3 -3
- data/example/logevents.conf +5 -5
- data/example/multi_filters.conf +1 -1
- data/example/out_exec_filter.conf +2 -2
- data/example/out_forward.conf +1 -1
- data/example/out_forward_buf_file.conf +1 -1
- data/example/out_forward_client.conf +5 -5
- data/example/out_forward_heartbeat_none.conf +1 -1
- data/example/out_forward_sd.conf +1 -1
- data/example/out_forward_shared_key.conf +2 -2
- data/example/out_forward_tls.conf +1 -1
- data/example/out_forward_users.conf +3 -3
- data/example/out_null.conf +4 -4
- data/example/secondary_file.conf +1 -1
- data/fluentd.gemspec +7 -6
- data/lib/fluent/capability.rb +87 -0
- data/lib/fluent/command/cap_ctl.rb +174 -0
- data/lib/fluent/command/ctl.rb +177 -0
- data/lib/fluent/command/plugin_config_formatter.rb +2 -1
- data/lib/fluent/env.rb +4 -0
- data/lib/fluent/log.rb +33 -3
- data/lib/fluent/match.rb +9 -0
- data/lib/fluent/plugin.rb +5 -0
- data/lib/fluent/plugin/buffer.rb +32 -42
- data/lib/fluent/plugin/buffer/chunk.rb +2 -1
- data/lib/fluent/plugin/formatter.rb +24 -0
- data/lib/fluent/plugin/formatter_csv.rb +1 -1
- data/lib/fluent/plugin/formatter_hash.rb +3 -1
- data/lib/fluent/plugin/formatter_json.rb +3 -1
- data/lib/fluent/plugin/formatter_ltsv.rb +5 -3
- data/lib/fluent/plugin/formatter_out_file.rb +6 -4
- data/lib/fluent/plugin/formatter_single_value.rb +4 -2
- data/lib/fluent/plugin/formatter_tsv.rb +4 -2
- data/lib/fluent/plugin/in_dummy.rb +2 -123
- data/lib/fluent/plugin/in_exec.rb +4 -2
- data/lib/fluent/plugin/in_http.rb +25 -4
- data/lib/fluent/plugin/in_sample.rb +141 -0
- data/lib/fluent/plugin/in_tail.rb +109 -41
- data/lib/fluent/plugin/in_tail/position_file.rb +39 -14
- data/lib/fluent/plugin/in_tcp.rb +1 -0
- data/lib/fluent/plugin/out_http.rb +20 -2
- data/lib/fluent/plugin/output.rb +15 -6
- data/lib/fluent/plugin/parser_json.rb +5 -2
- data/lib/fluent/plugin_helper/cert_option.rb +5 -8
- data/lib/fluent/plugin_helper/http_server/compat/server.rb +1 -1
- data/lib/fluent/plugin_helper/inject.rb +4 -1
- data/lib/fluent/plugin_helper/retry_state.rb +4 -0
- data/lib/fluent/plugin_helper/socket.rb +1 -1
- data/lib/fluent/supervisor.rb +151 -48
- data/lib/fluent/system_config.rb +2 -1
- data/lib/fluent/time.rb +1 -0
- data/lib/fluent/version.rb +1 -1
- data/lib/fluent/winsvc.rb +22 -4
- data/test/command/test_binlog_reader.rb +22 -6
- data/test/command/test_cap_ctl.rb +100 -0
- data/test/command/test_ctl.rb +57 -0
- data/test/command/test_plugin_config_formatter.rb +57 -2
- data/test/plugin/in_tail/test_position_file.rb +45 -25
- data/test/plugin/test_buffer.rb +4 -0
- data/test/plugin/test_filter_stdout.rb +6 -1
- data/test/plugin/test_formatter_hash.rb +6 -3
- data/test/plugin/test_formatter_json.rb +14 -4
- data/test/plugin/test_formatter_ltsv.rb +13 -5
- data/test/plugin/test_formatter_out_file.rb +35 -14
- data/test/plugin/test_formatter_single_value.rb +12 -6
- data/test/plugin/test_formatter_tsv.rb +12 -4
- data/test/plugin/test_in_exec.rb +18 -0
- data/test/plugin/test_in_http.rb +25 -0
- data/test/plugin/{test_in_dummy.rb → test_in_sample.rb} +25 -25
- data/test/plugin/test_in_tail.rb +433 -30
- data/test/plugin/test_out_file.rb +23 -18
- data/test/plugin/test_output.rb +12 -0
- data/test/plugin/test_parser_syslog.rb +2 -2
- data/test/plugin_helper/data/cert/empty.pem +0 -0
- data/test/plugin_helper/test_cert_option.rb +7 -0
- data/test/plugin_helper/test_compat_parameters.rb +7 -2
- data/test/plugin_helper/test_http_server_helper.rb +5 -0
- data/test/plugin_helper/test_inject.rb +42 -0
- data/test/plugin_helper/test_server.rb +34 -0
- data/test/plugin_helper/test_socket.rb +8 -0
- data/test/test_capability.rb +74 -0
- data/test/test_formatter.rb +34 -10
- data/test/test_log.rb +44 -0
- data/test/test_match.rb +11 -0
- data/test/test_output.rb +6 -1
- data/test/test_static_config_analysis.rb +2 -2
- data/test/test_supervisor.rb +119 -1
- metadata +50 -18
data/example/out_forward_sd.conf
CHANGED
data/example/out_null.conf
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
# bundle exec bin/fluentd -c example/out_buffered_null.conf
|
3
3
|
# (+ --emit-error-log-interval 10)
|
4
4
|
<source>
|
5
|
-
@type
|
6
|
-
tag
|
5
|
+
@type sample
|
6
|
+
tag sample
|
7
7
|
rate 500000000
|
8
|
-
|
8
|
+
sample [
|
9
9
|
{"message": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
|
10
10
|
{"message": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"},
|
11
11
|
{"message": "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"}
|
12
12
|
]
|
13
13
|
</source>
|
14
14
|
|
15
|
-
<match
|
15
|
+
<match sample.**>
|
16
16
|
@type null
|
17
17
|
<buffer>
|
18
18
|
flush_interval 60s
|
data/example/secondary_file.conf
CHANGED
data/fluentd.gemspec
CHANGED
@@ -18,10 +18,11 @@ Gem::Specification.new do |gem|
|
|
18
18
|
|
19
19
|
gem.required_ruby_version = '>= 2.4'
|
20
20
|
|
21
|
+
gem.add_runtime_dependency("bundler")
|
21
22
|
gem.add_runtime_dependency("msgpack", [">= 1.3.1", "< 2.0.0"])
|
22
23
|
gem.add_runtime_dependency("yajl-ruby", ["~> 1.0"])
|
23
24
|
gem.add_runtime_dependency("cool.io", [">= 1.4.5", "< 2.0.0"])
|
24
|
-
gem.add_runtime_dependency("serverengine", [">= 2.
|
25
|
+
gem.add_runtime_dependency("serverengine", [">= 2.2.2", "< 3.0.0"])
|
25
26
|
gem.add_runtime_dependency("http_parser.rb", [">= 0.5.1", "< 0.7.0"])
|
26
27
|
gem.add_runtime_dependency("sigdump", ["~> 0.2.2"])
|
27
28
|
gem.add_runtime_dependency("tzinfo", [">= 1.0", "< 3.0"])
|
@@ -32,11 +33,11 @@ Gem::Specification.new do |gem|
|
|
32
33
|
fake_platform = ENV['GEM_BUILD_FAKE_PLATFORM'].to_s
|
33
34
|
gem.platform = fake_platform unless fake_platform.empty?
|
34
35
|
if /mswin|mingw/ =~ fake_platform || (/mswin|mingw/ =~ RUBY_PLATFORM && fake_platform.empty?)
|
35
|
-
gem.add_runtime_dependency("win32-service", ["~>
|
36
|
-
gem.add_runtime_dependency("win32-ipc", ["~> 0.
|
37
|
-
gem.add_runtime_dependency("win32-event", ["~> 0.6.
|
38
|
-
gem.add_runtime_dependency("windows-pr", ["~> 1.2.
|
39
|
-
gem.add_runtime_dependency("certstore_c", ["~> 0.1.
|
36
|
+
gem.add_runtime_dependency("win32-service", ["~> 2.1.5"])
|
37
|
+
gem.add_runtime_dependency("win32-ipc", ["~> 0.7.0"])
|
38
|
+
gem.add_runtime_dependency("win32-event", ["~> 0.6.3"])
|
39
|
+
gem.add_runtime_dependency("windows-pr", ["~> 1.2.6"])
|
40
|
+
gem.add_runtime_dependency("certstore_c", ["~> 0.1.7"])
|
40
41
|
end
|
41
42
|
|
42
43
|
gem.add_development_dependency("rake", ["~> 13.0"])
|
@@ -0,0 +1,87 @@
|
|
1
|
+
#
|
2
|
+
# Fluent
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require "fluent/env"
|
18
|
+
|
19
|
+
if Fluent.linux?
|
20
|
+
begin
|
21
|
+
require 'capng'
|
22
|
+
rescue LoadError
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Fluent
|
27
|
+
if defined?(CapNG)
|
28
|
+
class Capability
|
29
|
+
def initialize(target = nil, pid = nil)
|
30
|
+
@capng = CapNG.new(target, pid)
|
31
|
+
end
|
32
|
+
|
33
|
+
def usable?
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
def apply(select_set)
|
38
|
+
@capng.apply(select_set)
|
39
|
+
end
|
40
|
+
|
41
|
+
def clear(select_set)
|
42
|
+
@capng.clear(select_set)
|
43
|
+
end
|
44
|
+
|
45
|
+
def have_capability?(type, capability)
|
46
|
+
@capng.have_capability?(type, capability)
|
47
|
+
end
|
48
|
+
|
49
|
+
def update(action, type, capability_or_capability_array)
|
50
|
+
@capng.update(action, type, capability_or_capability_array)
|
51
|
+
end
|
52
|
+
|
53
|
+
def have_capabilities?(select_set)
|
54
|
+
@capng.have_capabilities?(select_set)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
else
|
58
|
+
class Capability
|
59
|
+
def initialize(target = nil, pid = nil)
|
60
|
+
end
|
61
|
+
|
62
|
+
def usable?
|
63
|
+
false
|
64
|
+
end
|
65
|
+
|
66
|
+
def apply(select_set)
|
67
|
+
false
|
68
|
+
end
|
69
|
+
|
70
|
+
def clear(select_set)
|
71
|
+
false
|
72
|
+
end
|
73
|
+
|
74
|
+
def have_capability?(type, capability)
|
75
|
+
false
|
76
|
+
end
|
77
|
+
|
78
|
+
def update(action, type, capability_or_capability_array)
|
79
|
+
false
|
80
|
+
end
|
81
|
+
|
82
|
+
def have_capabilities?(select_set)
|
83
|
+
false
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'optparse'
|
18
|
+
require 'fluent/log'
|
19
|
+
require 'fluent/env'
|
20
|
+
require 'fluent/capability'
|
21
|
+
|
22
|
+
module Fluent
|
23
|
+
class CapCtl
|
24
|
+
def prepare_option_parser
|
25
|
+
@op = OptionParser.new
|
26
|
+
|
27
|
+
@op.on('--clear', "Clear Fluentd Ruby capability") {|s|
|
28
|
+
@opts[:clear_capabilities] = true
|
29
|
+
}
|
30
|
+
|
31
|
+
@op.on('--add [CAPABILITITY1,CAPABILITY2, ...]', "Add capabilities into Fluentd Ruby") {|s|
|
32
|
+
@opts[:add_capabilities] = s
|
33
|
+
}
|
34
|
+
|
35
|
+
@op.on('--drop [CAPABILITITY1,CAPABILITY2, ...]', "Drop capabilities from Fluentd Ruby") {|s|
|
36
|
+
@opts[:drop_capabilities] = s
|
37
|
+
}
|
38
|
+
|
39
|
+
@op.on('--get', "Get capabilities for Fluentd Ruby") {|s|
|
40
|
+
@opts[:get_capabilities] = true
|
41
|
+
}
|
42
|
+
|
43
|
+
@op.on('-f', '--file FILE', "Specify target file to add Linux capabilities") {|s|
|
44
|
+
@opts[:target_file] = s
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def usage(msg)
|
49
|
+
puts @op.to_s
|
50
|
+
puts "error: #{msg}" if msg
|
51
|
+
exit 1
|
52
|
+
end
|
53
|
+
|
54
|
+
def initialize(argv = ARGV)
|
55
|
+
@opts = {}
|
56
|
+
@argv = argv
|
57
|
+
|
58
|
+
if Fluent.linux?
|
59
|
+
begin
|
60
|
+
require 'capng'
|
61
|
+
|
62
|
+
@capng = CapNG.new
|
63
|
+
rescue LoadError
|
64
|
+
puts "Error: capng_c is not loaded. Please install it first."
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
else
|
68
|
+
puts "Error: This environment is not supported."
|
69
|
+
exit 2
|
70
|
+
end
|
71
|
+
|
72
|
+
prepare_option_parser
|
73
|
+
end
|
74
|
+
|
75
|
+
def call
|
76
|
+
parse_options!(@argv)
|
77
|
+
|
78
|
+
target_file = if !!@opts[:target_file]
|
79
|
+
@opts[:target_file]
|
80
|
+
else
|
81
|
+
File.readlink("/proc/self/exe")
|
82
|
+
end
|
83
|
+
|
84
|
+
if @opts[:clear_capabilities]
|
85
|
+
clear_capabilities(@opts, target_file)
|
86
|
+
elsif @opts[:add_capabilities]
|
87
|
+
add_capabilities(@opts, target_file)
|
88
|
+
elsif @opts[:drop_capabilities]
|
89
|
+
drop_capabilities(@opts, target_file)
|
90
|
+
end
|
91
|
+
if @opts[:get_capabilities]
|
92
|
+
get_capabilities(@opts, target_file)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def clear_capabilities(opts, target_file)
|
97
|
+
if !!opts[:clear_capabilities]
|
98
|
+
@capng.clear(:caps)
|
99
|
+
ret = @capng.apply_caps_file(target_file)
|
100
|
+
puts "Clear capabilities #{ret ? 'done' : 'fail'}."
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def add_capabilities(opts, target_file)
|
105
|
+
if add_caps = opts[:add_capabilities]
|
106
|
+
@capng.clear(:caps)
|
107
|
+
@capng.caps_file(target_file)
|
108
|
+
capabilities = add_caps.split(/\s*,\s*/)
|
109
|
+
check_capabilities(capabilities, get_valid_capabilities)
|
110
|
+
ret = @capng.update(:add,
|
111
|
+
CapNG::Type::EFFECTIVE | CapNG::Type::INHERITABLE | CapNG::Type::PERMITTED,
|
112
|
+
capabilities)
|
113
|
+
puts "Updating #{add_caps} #{ret ? 'done' : 'fail'}."
|
114
|
+
ret = @capng.apply_caps_file(target_file)
|
115
|
+
puts "Adding #{add_caps} #{ret ? 'done' : 'fail'}."
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def drop_capabilities(opts, target_file)
|
120
|
+
if drop_caps = opts[:drop_capabilities]
|
121
|
+
@capng.clear(:caps)
|
122
|
+
@capng.caps_file(target_file)
|
123
|
+
capabilities = drop_caps.split(/\s*,\s*/)
|
124
|
+
check_capabilities(capabilities, get_valid_capabilities)
|
125
|
+
ret = @capng.update(:drop,
|
126
|
+
CapNG::Type::EFFECTIVE | CapNG::Type::INHERITABLE | CapNG::Type::PERMITTED,
|
127
|
+
capabilities)
|
128
|
+
puts "Updating #{drop_caps} #{ret ? 'done' : 'fail'}."
|
129
|
+
@capng.apply_caps_file(target_file)
|
130
|
+
puts "Dropping #{drop_caps} #{ret ? 'done' : 'fail'}."
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def get_capabilities(opts, target_file)
|
135
|
+
if opts[:get_capabilities]
|
136
|
+
@capng.caps_file(target_file)
|
137
|
+
print = CapNG::Print.new
|
138
|
+
puts "Capabilities in '#{target_file}',"
|
139
|
+
puts "Effective: #{print.caps_text(:buffer, :effective)}"
|
140
|
+
puts "Inheritable: #{print.caps_text(:buffer, :inheritable)}"
|
141
|
+
puts "Permitted: #{print.caps_text(:buffer, :permitted)}"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def get_valid_capabilities
|
146
|
+
capabilities = []
|
147
|
+
cap = CapNG::Capability.new
|
148
|
+
cap.each do |_code, capability|
|
149
|
+
capabilities << capability
|
150
|
+
end
|
151
|
+
capabilities
|
152
|
+
end
|
153
|
+
|
154
|
+
def check_capabilities(capabilities, valid_capabilities)
|
155
|
+
capabilities.each do |capability|
|
156
|
+
unless valid_capabilities.include?(capability)
|
157
|
+
raise ArgumentError, "'#{capability}' is not valid capability. Valid Capabilities are: #{valid_capabilities.join(", ")}"
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def parse_options!(argv)
|
163
|
+
begin
|
164
|
+
rest = @op.parse(argv)
|
165
|
+
|
166
|
+
if rest.length != 0
|
167
|
+
usage nil
|
168
|
+
end
|
169
|
+
rescue
|
170
|
+
usage $!.to_s
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'optparse'
|
18
|
+
require 'fluent/env'
|
19
|
+
require 'fluent/version'
|
20
|
+
if Fluent.windows?
|
21
|
+
require 'win32/event'
|
22
|
+
require 'win32/service'
|
23
|
+
end
|
24
|
+
|
25
|
+
module Fluent
|
26
|
+
class Ctl
|
27
|
+
DEFAULT_OPTIONS = {}
|
28
|
+
|
29
|
+
if Fluent.windows?
|
30
|
+
include Windows::ServiceConstants
|
31
|
+
include Windows::ServiceStructs
|
32
|
+
include Windows::ServiceFunctions
|
33
|
+
|
34
|
+
COMMAND_MAP = {
|
35
|
+
shutdown: "",
|
36
|
+
restart: "HUP",
|
37
|
+
flush: "USR1",
|
38
|
+
reload: "USR2",
|
39
|
+
}
|
40
|
+
WINSVC_CONTROL_CODE_MAP = {
|
41
|
+
shutdown: SERVICE_CONTROL_STOP,
|
42
|
+
# 128 - 255: user-defined control code
|
43
|
+
# See https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-controlservice
|
44
|
+
restart: 128,
|
45
|
+
flush: 129,
|
46
|
+
reload: SERVICE_CONTROL_PARAMCHANGE,
|
47
|
+
}
|
48
|
+
else
|
49
|
+
COMMAND_MAP = {
|
50
|
+
shutdown: :TERM,
|
51
|
+
restart: :HUP,
|
52
|
+
flush: :USR1,
|
53
|
+
reload: :USR2,
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def initialize(argv = ARGV)
|
58
|
+
@argv = argv
|
59
|
+
@options = {}
|
60
|
+
@opt_parser = OptionParser.new
|
61
|
+
configure_option_parser
|
62
|
+
@options.merge!(DEFAULT_OPTIONS)
|
63
|
+
parse_options!
|
64
|
+
end
|
65
|
+
|
66
|
+
def help_text
|
67
|
+
text = "\n"
|
68
|
+
if Fluent.windows?
|
69
|
+
text << "Usage: #{$PROGRAM_NAME} COMMAND [PID_OR_SVCNAME]\n"
|
70
|
+
else
|
71
|
+
text << "Usage: #{$PROGRAM_NAME} COMMAND PID\n"
|
72
|
+
end
|
73
|
+
text << "\n"
|
74
|
+
text << "Commands: \n"
|
75
|
+
COMMAND_MAP.each do |key, value|
|
76
|
+
text << " #{key}\n"
|
77
|
+
end
|
78
|
+
text
|
79
|
+
end
|
80
|
+
|
81
|
+
def usage(msg = nil)
|
82
|
+
puts help_text
|
83
|
+
if msg
|
84
|
+
puts
|
85
|
+
puts "Error: #{msg}"
|
86
|
+
end
|
87
|
+
exit 1
|
88
|
+
end
|
89
|
+
|
90
|
+
def call
|
91
|
+
if Fluent.windows?
|
92
|
+
if @pid_or_svcname =~ /^[0-9]+$/
|
93
|
+
# Use as PID
|
94
|
+
return call_windows_event(@command, "fluentd_#{@pid_or_svcname}")
|
95
|
+
end
|
96
|
+
|
97
|
+
unless call_winsvc_control_code(@command, @pid_or_svcname)
|
98
|
+
puts "Cannot send control code to #{@pid_or_svcname} service, try to send an event with this name ..."
|
99
|
+
call_windows_event(@command, @pid_or_svcname)
|
100
|
+
end
|
101
|
+
else
|
102
|
+
call_signal(@command, @pid_or_svcname)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def call_signal(command, pid)
|
109
|
+
signal = COMMAND_MAP[command.to_sym]
|
110
|
+
Process.kill(signal, pid.to_i)
|
111
|
+
end
|
112
|
+
|
113
|
+
def call_winsvc_control_code(command, pid_or_svcname)
|
114
|
+
status = SERVICE_STATUS.new
|
115
|
+
|
116
|
+
begin
|
117
|
+
handle_scm = OpenSCManager(nil, nil, SC_MANAGER_CONNECT)
|
118
|
+
FFI.raise_windows_error('OpenSCManager') if handle_scm == 0
|
119
|
+
|
120
|
+
handle_scs = OpenService(handle_scm, "fluentdwinsvc", SERVICE_STOP | SERVICE_PAUSE_CONTINUE | SERVICE_USER_DEFINED_CONTROL)
|
121
|
+
FFI.raise_windows_error('OpenService') if handle_scs == 0
|
122
|
+
|
123
|
+
control_code = WINSVC_CONTROL_CODE_MAP[command.to_sym]
|
124
|
+
|
125
|
+
unless ControlService(handle_scs, control_code, status)
|
126
|
+
FFI.raise_windows_error('ControlService')
|
127
|
+
end
|
128
|
+
rescue => e
|
129
|
+
puts e
|
130
|
+
state = status[:dwCurrentState]
|
131
|
+
return state == SERVICE_STOPPED || state == SERVICE_STOP_PENDING
|
132
|
+
ensure
|
133
|
+
CloseServiceHandle(handle_scs)
|
134
|
+
CloseServiceHandle(handle_scm)
|
135
|
+
end
|
136
|
+
|
137
|
+
return true
|
138
|
+
end
|
139
|
+
|
140
|
+
def call_windows_event(command, pid_or_svcname)
|
141
|
+
prefix = pid_or_svcname
|
142
|
+
event_name = COMMAND_MAP[command.to_sym]
|
143
|
+
suffix = event_name.empty? ? "" : "_#{event_name}"
|
144
|
+
|
145
|
+
begin
|
146
|
+
event = Win32::Event.open("#{prefix}#{suffix}")
|
147
|
+
event.set
|
148
|
+
event.close
|
149
|
+
rescue Errno::ENOENT => e
|
150
|
+
puts "Error: Cannot find the fluentd process with the event name: \"#{prefix}\""
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def configure_option_parser
|
155
|
+
@opt_parser.banner = help_text
|
156
|
+
@opt_parser.version = Fluent::VERSION
|
157
|
+
end
|
158
|
+
|
159
|
+
def parse_options!
|
160
|
+
@opt_parser.parse!(@argv)
|
161
|
+
|
162
|
+
@command = @argv[0]
|
163
|
+
@pid_or_svcname = @argv[1] || "fluentdwinsvc"
|
164
|
+
|
165
|
+
usage("Command isn't specified!") if @command.nil? || @command.empty?
|
166
|
+
usage("Unknown command: #{@command}") unless COMMAND_MAP.has_key?(@command.to_sym)
|
167
|
+
|
168
|
+
if Fluent.windows?
|
169
|
+
usage("PID or SVCNAME isn't specified!") if @pid_or_svcname.nil? || @pid_or_svcname.empty?
|
170
|
+
else
|
171
|
+
usage("PID isn't specified!") if @pid_or_svcname.nil? || @pid_or_svcname.empty?
|
172
|
+
usage("Invalid PID: #{pid}") unless @pid_or_svcname =~ /^[0-9]+$/
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|