app/models/fluentd/agent/local_common.rb in fluentd-ui-0.3.13 vs app/models/fluentd/agent/local_common.rb in fluentd-ui-0.3.14

- old
+ new

@@ -71,12 +71,26 @@ def backup_files_in_new_order backup_files_in_old_order.reverse end + def dryrun(file_path = nil) + dryrun!(file_path) + true + rescue ::Fluentd::Agent::ConfigError + false + end + private + def exec_dryrun(command, file_path = nil) + Bundler.with_clean_env do + system("#{command} -q --dry-run #{options_to_argv(config_file: file_path)}", out: File::NULL, err: File::NULL) + raise ::Fluentd::Agent::ConfigError, last_error_message unless $?.exitstatus.zero? + end + end + def backup_config return unless File.exists? config_file FileUtils.cp config_file, File.join(config_backup_dir, "#{Time.zone.now.strftime('%Y%m%d_%H%M%S')}.conf") @@ -170,9 +184,18 @@ pid = spawn(cmd) Process.detach(pid) end thread.join thread.value.exitstatus.zero? + end + + def options_to_argv(opts = {}) + argv = "" + argv << " --use-v1-config" + argv << " -c #{opts[:config_file] || config_file}" + argv << " -d #{opts[:pid_file] || pid_file}" + argv << " -o #{opts[:log_file] || log_file}" + argv end end end end