def kill_pid(sig, file)
begin
pid = pid_in_file(file)
Merb.logger.fatal! "Killing pid #{pid} with #{sig}"
Process.kill(sig, pid)
FileUtils.rm(file) if File.exist?(file)
rescue Errno::EINVAL
Merb.logger.fatal! "Failed to kill PID #{pid} with #{sig}: '#{sig}' is an invalid " \
"or unsupported signal number."
rescue Errno::EPERM
Merb.logger.fatal! "Failed to kill PID #{pid} with #{sig}: Insufficient permissions."
rescue Errno::ESRCH
FileUtils.rm file
Merb.logger.fatal! "Failed to kill PID #{pid} with #{sig}: Process is " \
"deceased or zombie."
rescue Errno::EACCES => e
Merb.logger.fatal! e.message
rescue Errno::ENOENT => e
Merb.logger.fatal! "Could not find a PID file at #{file}. " \
"Most likely the process is no longer running and the pid file was not cleaned up."
rescue Exception => e
if !e.is_a?(SystemExit)
Merb.logger.fatal! "Failed to kill PID #{pid.inspect} with #{sig.inspect}: #{e.message}"
end
end
end