The following task definition works for me (put it in the * .rake file in the lib \ tasks folder):
namespace :server do # --------------------------------------------------------------------------- desc "Clear the previous server instance clutter." task :cleanup => :environment do pidfile = 'tmp/pids/server.pid' if File.exists? pidfile pid = File.read(pidfile).to_i if RbConfig::CONFIG['host_os'] =~ /mswin32/ sh "taskkill /f /pid #{pid}" sh "del tmp\\pids\\server.pid" else sh "kill #{pid}" sh "rm #{pidfile}" end puts "All cleaned up. Yay!" else puts "Already clean. Whew!" end end # --------------------------------------------------------------------------- desc "Start an instance of the server cleanly." task :startup => :cleanup do sh "rails server" end # --------------------------------------------------------------------------- end
Now just run
rake server:startup
It cleans up all remaining processes and pid files on Windoze before attempting to start the rails server again.
Bob calco
source share