# File lib/pidfile.rb, line 13
  def initialize(*args)
    opts = {}

    #----- set options -----#
    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

    #----- Does the pidfile or pid exist? -----#
    if self.pidfile_exists?
      if self.class.running?(@pidpath)
        raise DuplicateProcessError, "Process (#{$0} - #{self.class.pid(@pidpath)}) is already running."
        
        exit! # exit without removing the existing pidfile
      end

      self.release
    end

    #----- create the pidfile -----#
    create_pidfile

    at_exit { release }
  end