eventmachine-tail
eventmachine-tail copied to clipboard
No such file or directory after logrotation
Hi,
I'm using em-tail to tail apache log files but I'm running into problems when the files are rotated by Apache. I get the following exception
Tailing started
Tailer(/mnt/var/log/apache2/access-20101218130000.log) @ pos:
Found: /mnt/var/log/apache2/access-20101218130000.log
Tailer(/mnt/var/log/apache2/access-20101218131500.log) @ pos:
Found: /mnt/var/log/apache2/access-20101218131500.log
/home/daniel/.rvm/gems/ruby-1.9.2-p0@zen/gems/eventmachine-tail-0.5.20101204110840/lib/em/filetail.rb:178:in `initialize': No such file or directory - /mnt/var/log/apache2/access-20101218130000.log (Errno::ENOENT)
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@zen/gems/eventmachine-tail-0.5.20101204110840/lib/em/filetail.rb:178:in `open'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@zen/gems/eventmachine-tail-0.5.20101204110840/lib/em/filetail.rb:178:in `open'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@zen/gems/eventmachine-tail-0.5.20101204110840/lib/em/filetail.rb:280:in `block in schedule_reopen'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@zen/gems/eventmachine-0.12.10/lib/eventmachine.rb:996:in `call'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@zen/gems/eventmachine-0.12.10/lib/eventmachine.rb:996:in `block in run_deferred_callbacks'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@zen/gems/eventmachine-0.12.10/lib/eventmachine.rb:996:in `each'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@zen/gems/eventmachine-0.12.10/lib/eventmachine.rb:996:in `run_deferred_callbacks'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@zen/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@zen/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
from tailer.rb:41:in `'
You can see the code I'm testing with here: https://gist.github.com/746500
It seems it's trying to recreate a FileTail with the old path.
Watching the log just now I saw that the exception was thrown several seconds after it created a new tailer for the new file. Perhaps it received an updated/new event instead of deleted once apache finished the logrotation.
Since the errors is in the initialize method it feels like it's actually trying to create a new tailer for that log.
After adding
return unless File.exists?(@path)
to line 178 and 202 solves the issue but that feels like a hack.
Thanks for filing :)
I'll work on a test case that reproduces it (I can reproduce it by hand) and get a fix committed, soon.
Any progress on this?
Not yet, I've been busy managing SysAdvent this month. Today's the last day for it, so I'll have free time to fix this (and other pending todos) after it's all over ;)