def initialize(*args)
opts = {}
case
when args.length == 0 then
when args.length == 1 && args[0].class == Hash then
arg = args.shift
if arg.class == Hash
opts = arg
end
else
raise ArgumentError, "new() expects hash or hashref as argument"
end
opts = DEFAULT_OPTIONS.merge opts
@piddir = opts[:piddir]
@pidfile = opts[:pidfile]
@pidpath = File.join(@piddir, @pidfile)
@fh = nil
if self.pidfile_exists?
if self.class.running?(@pidpath)
raise DuplicateProcessError, "Process (#{$0} - #{self.class.pid(@pidpath)}) is already running."
exit!
end
self.release
end
create_pidfile
at_exit { release }
end