Skip to content

Instantly share code, notes, and snippets.

@victorcreed
Created September 3, 2013 06:44
Show Gist options
  • Save victorcreed/6420403 to your computer and use it in GitHub Desktop.
Save victorcreed/6420403 to your computer and use it in GitHub Desktop.
automating restart server task for demonized rails server
namespace :vf do
namespace :server do
desc "stop server"
task :stop => :environment do
puts "-----------------Stoping Server----------------"
pid_file = "tmp/pids/server.pid"
pid = File.read(pid_file).to_i
puts "************pid = #{pid}"
Process.kill 9, pid
File.delete pid_file
puts "-----------------Server Stopped----------------"
end
desc "start server"
task :start => :environment do
puts "-----------------Starting Server----------------"
`bundle exec rails s -d`
puts "-----------------Server Started----------------"
end
desc "start server"
task :restart => :environment do
puts "-----------------Restarting Server----------------"
Rake::Task["vf:server:stop"].invoke rescue puts "server is already stopped"
Rake::Task["vf:server:start"].invoke rescue puts "server is already running"
puts "-----------------Server Restarted----------------"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment