Last active
August 29, 2015 14:11
-
-
Save AfonsoTsukamoto/40c4e6f3407c8a6e37f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Most instructions for using Capistrano tell you how to make it restart Phusion | |
# Passenger by 'touch'ing the restart.txt file, but this doesn't immediately | |
# restart the app - instead the first person to try to use the application will | |
# cause it to be restarted, so they will see a delay of at least a few seconds. | |
# This shows how to add a post-deploy task to 'ping' the server, to cause it to | |
# restart immediately. | |
# First, (optionally) add a '/ping' route to config/routes.rb that immediately | |
# returns a blank page. This prevents any non-essential work being done, such as | |
# rendering the homepage. Test it to make sure you get a blank page not an | |
# error. | |
# Then add a deploy:ping task to config/deploy.rb and set it to run | |
# automatically after deploy:restart. Alternatively you could put it into the | |
# deploy:restart task directly. | |
# config/deploy.rb: | |
# Add this to the settings section at the top: | |
set :ping_url, "https://www.example.com/ping" | |
# This is the standard Phusion Passenger restart code. You will probably already | |
# have something like this (if you have already got Capistrano set up). | |
namespace :deploy do | |
task :start do ; end | |
task :stop do ; end | |
task :restart, roles: :app, except: { no_release: true } do | |
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}" | |
end | |
end | |
# Add this to add the deploy:ping task: | |
namespace :deploy do | |
task :ping do | |
system "curl --silent #{fetch(:ping_url)}" | |
end | |
end | |
# Add this to automatically ping the server after a restart: | |
after "deploy:restart", "deploy:ping" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/routes.rb: | |
SampleApp::Application.routes.draw do | |
# ... | |
# Add this line somewhere in the file: | |
# Note: If you have a catch-all route then this line must come before it | |
get 'ping' => proc {|env| [200, {}, []] } | |
# Alternatively you could output a short string to confirm it worked | |
# instead of showing a blank page | |
#get 'ping' => proc {|env| [200, {}, ['pong']] } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment