Browse files

Add protection from starting logger multiple times.

  • Loading branch information...
1 parent 0a5edbd commit 5bc7ba116dd3309f9a537b83d90733ff41b679a3 @whitequark committed Jun 9, 2013
Showing with 9 additions and 0 deletions.
  1. +9 −0 logger.rb
View
9 logger.rb
@@ -7,6 +7,15 @@
require 'redis'
pidfile = File.join(File.dirname(__FILE__), 'tmp', 'logger.pid')
+
+begin
+ old_pid = File.read(pidfile).to_i
+ Process.kill 0, old_pid
+
+ raise "An existing logger process is running with pid #{old_pid}. Refusing to start"
+rescue Errno::ESRCH
+end
+
File.open(pidfile, 'w') do |f|
f.write Process.pid
end

0 comments on commit 5bc7ba1

Please sign in to comment.