class RBDaemon::PidFile
Public Class Methods
new(pid_file = nil)
click to toggle source
# File lib/rbdaemon/pidfile.rb, line 8 def initialize(pid_file = nil) if pid_file @path = pid_file else program = File.basename($0).split(/\./)[0] @path = File.join(RBDaemon::PID_FILE_DIR, program + '.pid') end @file = File.new(@path, File::WRONLY | File::CREAT, 0644) unless @file.flock(File::LOCK_NB | File::LOCK_EX) raise PidFileError, 'failed to lock ' + @path end @file.truncate(0) @file.write("#{$$}\n") @file.flush end
Public Instance Methods
delete()
click to toggle source
# File lib/rbdaemon/pidfile.rb, line 24 def delete File.delete(@path) end