|
26 | 26 | op = OptionParser.new |
27 | 27 | op.version = Fluent::VERSION |
28 | 28 |
|
29 | | -opts = Fluent::Supervisor.default_options |
| 29 | +default_opts = Fluent::Supervisor.default_options |
| 30 | +cmd_opts = {} |
30 | 31 |
|
31 | 32 | op.on('-s', "--setup [DIR=#{File.dirname(Fluent::DEFAULT_CONFIG_PATH)}]", "install sample configuration file to the directory") {|s| |
32 | | - opts[:setup_path] = s || File.dirname(Fluent::DEFAULT_CONFIG_PATH) |
| 33 | + cmd_opts[:setup_path] = s || File.dirname(Fluent::DEFAULT_CONFIG_PATH) |
33 | 34 | } |
34 | 35 |
|
35 | 36 | op.on('-c', '--config PATH', "config file path (default: #{Fluent::DEFAULT_CONFIG_PATH})") {|s| |
36 | | - opts[:config_path] = s |
| 37 | + cmd_opts[:config_path] = s |
37 | 38 | } |
38 | 39 |
|
39 | 40 | op.on('--dry-run', "Check fluentd setup is correct or not", TrueClass) {|b| |
40 | | - opts[:dry_run] = b |
| 41 | + cmd_opts[:dry_run] = b |
41 | 42 | } |
42 | 43 |
|
43 | 44 | op.on('--show-plugin-config=PLUGIN', "[DEPRECATED] Show PLUGIN configuration and exit(ex: input:dummy)") {|plugin| |
44 | | - opts[:show_plugin_config] = plugin |
| 45 | + cmd_opts[:show_plugin_config] = plugin |
45 | 46 | } |
46 | 47 |
|
47 | 48 | op.on('-p', '--plugin DIR', "add plugin directory") {|s| |
48 | | - opts[:plugin_dirs] << s |
| 49 | + (cmd_opts[:plugin_dirs] ||= []) << s |
49 | 50 | } |
50 | 51 |
|
51 | 52 | op.on('-I PATH', "add library path") {|s| |
52 | 53 | $LOAD_PATH << s |
53 | 54 | } |
54 | 55 |
|
55 | 56 | op.on('-r NAME', "load library") {|s| |
56 | | - opts[:libs] << s |
| 57 | + (cmd_opts[:libs] ||= []) << s |
57 | 58 | } |
58 | 59 |
|
59 | 60 | op.on('-d', '--daemon PIDFILE', "daemonize fluent process") {|s| |
60 | | - opts[:daemonize] = s |
| 61 | + cmd_opts[:daemonize] = s |
61 | 62 | } |
62 | 63 |
|
63 | 64 | op.on('--under-supervisor', "run fluent worker under supervisor (this option is NOT for users)") { |
64 | | - opts[:supervise] = false |
| 65 | + cmd_opts[:supervise] = false |
65 | 66 | } |
66 | 67 |
|
67 | 68 | op.on('--no-supervisor', "run fluent worker without supervisor") { |
68 | | - opts[:supervise] = false |
69 | | - opts[:standalone_worker] = true |
| 69 | + cmd_opts[:supervise] = false |
| 70 | + cmd_opts[:standalone_worker] = true |
70 | 71 | } |
71 | 72 |
|
72 | 73 | op.on('--workers NUM', "specify the number of workers under supervisor") { |i| |
73 | | - opts[:workers] = i.to_i |
| 74 | + cmd_opts[:workers] = i.to_i |
74 | 75 | } |
75 | 76 |
|
76 | 77 | op.on('--user USER', "change user") {|s| |
77 | | - opts[:chuser] = s |
| 78 | + cmd_opts[:chuser] = s |
78 | 79 | } |
79 | 80 |
|
80 | 81 | op.on('--group GROUP', "change group") {|s| |
81 | | - opts[:chgroup] = s |
| 82 | + cmd_opts[:chgroup] = s |
82 | 83 | } |
83 | 84 |
|
84 | 85 | op.on('--umask UMASK', "change umask") {|s| |
85 | | - opts[:chumask] = s |
| 86 | + cmd_opts[:chumask] = s |
86 | 87 | } |
87 | 88 |
|
88 | 89 | op.on('-o', '--log PATH', "log file path") {|s| |
89 | | - opts[:log_path] = s |
| 90 | + cmd_opts[:log_path] = s |
90 | 91 | } |
91 | 92 |
|
92 | 93 | op.on('--log-rotate-age AGE', 'generations to keep rotated log files') {|age| |
93 | 94 | if Fluent::Log::LOG_ROTATE_AGE.include?(age) |
94 | | - opts[:log_rotate_age] = age |
| 95 | + cmd_opts[:log_rotate_age] = age |
95 | 96 | else |
96 | 97 | begin |
97 | | - opts[:log_rotate_age] = Integer(age) |
| 98 | + cmd_opts[:log_rotate_age] = Integer(age) |
98 | 99 | rescue TypeError, ArgumentError |
99 | 100 | usage "log-rotate-age should be #{ROTATE_AGE.join(', ')} or a number" |
100 | 101 | end |
101 | 102 | end |
102 | 103 | } |
103 | 104 |
|
104 | 105 | op.on('--log-rotate-size BYTES', 'sets the byte size to rotate log files') {|s| |
105 | | - opts[:log_rotate_size] = s.to_i |
| 106 | + cmd_opts[:log_rotate_size] = s.to_i |
106 | 107 | } |
107 | 108 |
|
108 | 109 | op.on('--log-event-verbose', 'enable log events during process startup/shutdown') {|b| |
109 | | - opts[:log_event_verbose] = b |
| 110 | + cmd_opts[:log_event_verbose] = b |
110 | 111 | } |
111 | 112 |
|
112 | 113 | op.on('-i', '--inline-config CONFIG_STRING', "inline config which is appended to the config file on-the-fly") {|s| |
113 | | - opts[:inline_config] = s |
| 114 | + cmd_opts[:inline_config] = s |
114 | 115 | } |
115 | 116 |
|
116 | 117 | op.on('--emit-error-log-interval SECONDS', "suppress interval seconds of emit error logs") {|s| |
117 | | - opts[:suppress_interval] = s.to_i |
| 118 | + cmd_opts[:suppress_interval] = s.to_i |
118 | 119 | } |
119 | 120 |
|
120 | 121 | op.on('--suppress-repeated-stacktrace [VALUE]', "suppress repeated stacktrace", TrueClass) {|b| |
121 | 122 | b = true if b.nil? |
122 | | - opts[:suppress_repeated_stacktrace] = b |
| 123 | + cmd_opts[:suppress_repeated_stacktrace] = b |
123 | 124 | } |
124 | 125 |
|
125 | 126 | op.on('--without-source', "invoke a fluentd without input plugins", TrueClass) {|b| |
126 | | - opts[:without_source] = b |
| 127 | + cmd_opts[:without_source] = b |
127 | 128 | } |
128 | 129 |
|
129 | 130 | op.on('--config-file-type VALU', 'guessing file type of fluentd configuration. yaml/yml or guess') { |s| |
130 | 131 | if (s == 'yaml') || (s == 'yml') |
131 | | - opts[:config_file_type] = s.to_sym |
| 132 | + cmd_opts[:config_file_type] = s.to_sym |
132 | 133 | elsif (s == 'guess') |
133 | | - opts[:config_file_type] = s.to_sym |
| 134 | + cmd_opts[:config_file_type] = s.to_sym |
134 | 135 | else |
135 | 136 | usage '--config-file-type accepts yaml/yml or guess' |
136 | 137 | end |
137 | 138 | } |
138 | 139 |
|
139 | 140 | op.on('--use-v1-config', "Use v1 configuration format (default)", TrueClass) {|b| |
140 | | - opts[:use_v1_config] = b |
| 141 | + cmd_opts[:use_v1_config] = b |
141 | 142 | } |
142 | 143 |
|
143 | 144 | op.on('--use-v0-config', "Use v0 configuration format", TrueClass) {|b| |
144 | | - opts[:use_v1_config] = !b |
| 145 | + cmd_opts[:use_v1_config] = !b |
145 | 146 | } |
146 | 147 |
|
147 | 148 | op.on('--strict-config-value', "Parse config values strictly", TrueClass) {|b| |
148 | | - opts[:strict_config_value] = b |
| 149 | + cmd_opts[:strict_config_value] = b |
149 | 150 | } |
150 | 151 |
|
151 | 152 | op.on('--enable-input-metrics', "Enable input plugin metrics on fluentd", TrueClass) {|b| |
152 | | - opts[:enable_input_metrics] = b |
| 153 | + cmd_opts[:enable_input_metrics] = b |
153 | 154 | } |
154 | 155 |
|
155 | 156 | op.on('--enable-size-metrics', "Enable plugin record size metrics on fluentd", TrueClass) {|b| |
156 | | - opts[:enable_size_metrics] = b |
| 157 | + cmd_opts[:enable_size_metrics] = b |
157 | 158 | } |
158 | 159 |
|
159 | 160 | op.on('-v', '--verbose', "increase verbose level (-v: debug, -vv: trace)", TrueClass) {|b| |
160 | | - if b |
161 | | - opts[:log_level] = [opts[:log_level] - 1, Fluent::Log::LEVEL_TRACE].max |
162 | | - end |
| 161 | + return unless b |
| 162 | + cur_level = cmd_opts.fetch(:log_level, default_opts[:log_level]) |
| 163 | + cmd_opts[:log_level] = [cur_level - 1, Fluent::Log::LEVEL_TRACE].max |
163 | 164 | } |
164 | 165 |
|
165 | 166 | op.on('-q', '--quiet', "decrease verbose level (-q: warn, -qq: error)", TrueClass) {|b| |
166 | | - if b |
167 | | - opts[:log_level] = [opts[:log_level] + 1, Fluent::Log::LEVEL_ERROR].min |
168 | | - end |
| 167 | + return unless b |
| 168 | + cur_level = cmd_opts.fetch(:log_level, default_opts[:log_level]) |
| 169 | + cmd_opts[:log_level] = [cur_level + 1, Fluent::Log::LEVEL_TRACE].max |
169 | 170 | } |
170 | 171 |
|
171 | 172 | op.on('--suppress-config-dump', "suppress config dumping when fluentd starts", TrueClass) {|b| |
172 | | - opts[:suppress_config_dump] = b |
| 173 | + cmd_opts[:suppress_config_dump] = b |
173 | 174 | } |
174 | 175 |
|
175 | 176 | op.on('-g', '--gemfile GEMFILE', "Gemfile path") {|s| |
176 | | - opts[:gemfile] = s |
| 177 | + cmd_opts[:gemfile] = s |
177 | 178 | } |
178 | 179 |
|
179 | 180 | op.on('-G', '--gem-path GEM_INSTALL_PATH', "Gemfile install path (default: $(dirname $gemfile)/vendor/bundle)") {|s| |
180 | | - opts[:gem_install_path] = s |
| 181 | + cmd_opts[:gem_install_path] = s |
181 | 182 | } |
182 | 183 |
|
183 | 184 | op.on('--conf-encoding ENCODING', "specify configuration file encoding") { |s| |
184 | | - opts[:conf_encoding] = s |
| 185 | + cmd_opts[:conf_encoding] = s |
185 | 186 | } |
186 | 187 |
|
187 | 188 | op.on('--disable-shared-socket', "Don't open shared socket for multiple workers") { |b| |
188 | | - opts[:disable_shared_socket] = b |
| 189 | + cmd_opts[:disable_shared_socket] = b |
189 | 190 | } |
190 | 191 |
|
191 | 192 | if Fluent.windows? |
192 | | - opts.merge!( |
| 193 | + cmd_opts.merge!( |
193 | 194 | :winsvc_name => 'fluentdwinsvc', |
194 | 195 | :winsvc_display_name => 'Fluentd Windows Service', |
195 | 196 | :winsvc_desc => 'Fluentd is an event collector system.', |
196 | 197 | ) |
197 | 198 |
|
198 | 199 | op.on('-x', '--signame INTSIGNAME', "an object name which is used for Windows Service signal (Windows only)") {|s| |
199 | | - opts[:signame] = s |
| 200 | + cmd_opts[:signame] = s |
200 | 201 | } |
201 | 202 |
|
202 | 203 | op.on('--reg-winsvc MODE', "install/uninstall as Windows Service. (i: install, u: uninstall) (Windows only)") {|s| |
203 | | - opts[:regwinsvc] = s |
| 204 | + cmd_opts[:regwinsvc] = s |
204 | 205 | } |
205 | 206 |
|
206 | 207 | op.on('--[no-]reg-winsvc-auto-start', "Automatically start the Windows Service at boot. (only effective with '--reg-winsvc i') (Windows only)") {|s| |
207 | | - opts[:regwinsvcautostart] = s |
| 208 | + cmd_opts[:regwinsvcautostart] = s |
208 | 209 | } |
209 | 210 |
|
210 | 211 | op.on('--[no-]reg-winsvc-delay-start', "Automatically start the Windows Service at boot with delay. (only effective with '--reg-winsvc i' and '--reg-winsvc-auto-start') (Windows only)") {|s| |
211 | | - opts[:regwinsvcdelaystart] = s |
| 212 | + cmd_opts[:regwinsvcdelaystart] = s |
212 | 213 | } |
213 | 214 |
|
214 | 215 | op.on('--reg-winsvc-fluentdopt OPTION', "specify fluentd option parameters for Windows Service. (Windows only)") {|s| |
215 | | - opts[:fluentdopt] = s |
| 216 | + cmd_opts[:fluentdopt] = s |
216 | 217 | } |
217 | 218 |
|
218 | 219 | op.on('--winsvc-name NAME', "The Windows Service name to run as (Windows only)") {|s| |
219 | | - opts[:winsvc_name] = s |
| 220 | + cmd_opts[:winsvc_name] = s |
220 | 221 | } |
221 | 222 |
|
222 | 223 | op.on('--winsvc-display-name DISPLAY_NAME', "The Windows Service display name (Windows only)") {|s| |
223 | | - opts[:winsvc_display_name] = s |
| 224 | + cmd_opts[:winsvc_display_name] = s |
224 | 225 | } |
225 | 226 |
|
226 | 227 | op.on('--winsvc-desc DESC', "The Windows Service description (Windows only)") {|s| |
227 | | - opts[:winsvc_desc] = s |
| 228 | + cmd_opts[:winsvc_desc] = s |
228 | 229 | } |
229 | 230 | end |
230 | 231 |
|
|
247 | 248 | usage $!.to_s |
248 | 249 | end |
249 | 250 |
|
| 251 | +opts = default_opts.merge(cmd_opts) |
250 | 252 |
|
251 | 253 | ## |
252 | 254 | ## Bundler injection |
|
345 | 347 | exit 0 if early_exit |
346 | 348 |
|
347 | 349 | if opts[:supervise] |
348 | | - supervisor = Fluent::Supervisor.new(opts) |
| 350 | + supervisor = Fluent::Supervisor.new(cmd_opts) |
349 | 351 | supervisor.configure(supervisor: true) |
350 | 352 | supervisor.run_supervisor(dry_run: opts[:dry_run]) |
351 | 353 | else |
352 | 354 | if opts[:standalone_worker] && opts[:workers] && opts[:workers] > 1 |
353 | 355 | puts "Error: multi workers is not supported with --no-supervisor" |
354 | 356 | exit 2 |
355 | 357 | end |
356 | | - worker = Fluent::Supervisor.new(opts) |
| 358 | + worker = Fluent::Supervisor.new(cmd_opts) |
357 | 359 | worker.configure |
358 | 360 |
|
359 | 361 | if opts[:daemonize] && opts[:standalone_worker] |
|
0 commit comments