Skip to content

Instantly share code, notes, and snippets.

@closer
Created August 20, 2014 09:37
Show Gist options
  • Select an option

  • Save closer/cf45e500bad6f22316a0 to your computer and use it in GitHub Desktop.

Select an option

Save closer/cf45e500bad6f22316a0 to your computer and use it in GitHub Desktop.
class Daemon
def self.run &block
new &block
end
def initialize &block
Process.daemon
@pid = Process.pid
File.write '/tmp/daemon.pid', @pid
yield
end
end
Daemon.run do
file = File.new('/tmp/daemon.log', 'a')
count = 0
loop { file.write "#{count += 1}\n" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment