diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index dbe628bea7..67bbec48de 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -185,6 +185,8 @@ def start super if @pos_file + pos_file_dir = File.dirname(@pos_file) + FileUtils.mkdir_p(pos_file_dir) unless Dir.exist?(pos_file_dir) @pf_file = File.open(@pos_file, File::RDWR|File::CREAT|File::BINARY, @file_perm) @pf_file.sync = true @pf = PositionFile.parse(@pf_file) @@ -946,7 +948,7 @@ def initialize(file, file_mutex, seek, pos, inode) @file = file @file_mutex = file_mutex @seek = seek - @pos = pos + @pos = pos @inode = inode end diff --git a/test/plugin/test_in_tail.rb b/test/plugin/test_in_tail.rb index 40ffa0d0a0..ef5b5a5a90 100644 --- a/test/plugin/test_in_tail.rb +++ b/test/plugin/test_in_tail.rb @@ -1011,6 +1011,25 @@ def count_timer_object end end + def test_pos_file_dir_creation + config = config_element("", "", { + "tag" => "tail", + "path" => "#{TMP_DIR}/*.txt", + "format" => "none", + "pos_file" => "#{TMP_DIR}/pos/tail.pos", + "read_from_head" => true, + "refresh_interval" => 1 + }) + d = create_driver(config, false) + d.run(expect_emits: 1, shutdown: false) do + File.open("#{TMP_DIR}/tail.txt", "ab") { |f| f.puts "test3\n" } + end + assert_path_exist("#{TMP_DIR}/pos/tail.pos") + cleanup_directory(TMP_DIR) + + d.instance_shutdown + end + def test_z_refresh_watchers plugin = create_driver(EX_CONFIG, false).instance sio = StringIO.new