diff --git a/app/models/fluentd/agent/local_common.rb b/app/models/fluentd/agent/local_common.rb index 06f2f75..a9b7e1e 100644 --- a/app/models/fluentd/agent/local_common.rb +++ b/app/models/fluentd/agent/local_common.rb @@ -55,6 +55,7 @@ class Fluentd def pid return unless File.exists?(pid_file) + return if File.zero?(pid_file) File.read(pid_file).to_i rescue nil end diff --git a/spec/models/fluentd/agent/local_common_spec.rb b/spec/models/fluentd/agent/local_common_spec.rb index a928ce9..582804d 100644 --- a/spec/models/fluentd/agent/local_common_spec.rb +++ b/spec/models/fluentd/agent/local_common_spec.rb @@ -20,10 +20,10 @@ describe 'Fluentd::Agent::LocalCommon' do end context 'valid pid file given' do - before { File.write pid_file_path, '99999' } + before { File.write pid_file_path, '9999' } after { FileUtils.rm pid_file_path } - its(:pid) { should eq(99999) } + its(:pid) { should eq(9999) } end end end