--- bin/mongrel_rails-orig 2007-04-13 09:44:11.000000000 +0300 +++ bin/mongrel_rails 2007-04-13 10:00:39.000000000 +0300 @@ -83,10 +83,18 @@ config = Mongrel::Rails::RailsConfigurator.new(settings) do if defaults[:daemon] if File.exist? defaults[:pid_file] - log "!!! PID file #{defaults[:pid_file]} already exists. Mongrel could be running already. Check your #{defaults[:log_file]} for errors." - log "!!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start." - exit 1 - end + # mongrels that crash can leave stale PID files behind, and these + # should not stop mongrel from being restarted by monitors... + pid = File.new(defaults[:pid_file]).readline + unless `ps -ef | grep #{pid} | grep -v grep`.length > 0 + # use "ps ax" for freebsd + log "!!! PID file #{defaults[:pid_file]} exists, but is stale, and will be deleted so that this mongrel can run." + File.delete(defaults[:pid_file]) + else + log "!!! PID file #{defaults[:pid_file]} already exists and the process id referred to in it is running. This mongrel is probably already run ning. #{defaults[:log_file]} for errors. EXITING." + exit 1 + end + end daemonize log "Daemonized, any open files are closed. Look at #{defaults[:pid_file]} and #{defaults[:log_file]} for info."