#!/usr/bin/env ruby
class PidFile
def initialize(filename, &code)
unless set_pid(filename)
raise RuntimeError.new("The process is already running")
end
code.call
File.delete(filename)
end
private
def set_pid(filename)
# Same code as before
end
end
And call it thus
PidFile.new("/var/run/app.pid") do
puts "What we want to do"
end
No comments:
Post a Comment