I am using Capistrano to deploy to a server running Nginx. I'm running into some issues with APC and I need to reload PHP-FPM after Capistrano has completed the deployment. The issue itself is outlined here but like that author I don't want to have to SSH in and reload PHP-FPM remotely from the command line, I'd like Capistrano to do it as a post deployment hook.
The essence of the deploy.rb being used is below;
set :application, "deploytest"
set :repository, "[email protected]:gitaccount/git-repo.git"
set :scm, :git
set :deploy_via, :remote_cache
set :app_webroot, "/public"
default_run_options[:pty] = true
desc "Execute Capistrano tasks against Production server."
task :prod do
role :web, "123.45.67.89"
role :app, "123.45.67.89"
set :env, "prod"
set :domain, "deploy-domain.com"
set :deploy_to, "/var/www/vhosts/#{domain}/site"
set :branch, "master"
end
And I can push using the command;
bundle exec cap prod deploy
Works great. Boy have I struggled trying to get that command to automatically trigger another command once the deploy is complete.
What I have tried;
Here's a summary of the main approaches;
Creating a new namespace for my task
namespace :mcnab do
desc "Running hook post deploy"
task :fpmreload do
execute "service php-fpm reload"
end
end
after "deploy:create_symlink", "mcnab:fpmreload"
Wrapping both tasks in a 'deploy' namespace and using the following command to trigger the hook
after "deploy:create_symlink", "deploy:fpmreload"
Explicitly setting the roles again within the new task
task :fpmreload do
role :web, "178.62.13.10"
role :app, "178.62.13.10"
on roles(:all) do
execute "service php-fpm reload"
end
end
Setting the user explicitly
task :fpmreload do
on "[email protected]" do
execute "service php-fpm reload"
end
end
Using 'run' instead of execute
task :fpmreload do
on "[email protected]" do
run "service php-fpm reload"
end
end
Hrrmph, and about a million variations thereon. I'm really just guessing now, even with verbose error reporting the error messages are not helping much. Just one working example of a deploy.rb file with a simple post deploy hook running a command would be great but I can't find one.
This works for me
before :published, :fpm_reload
desc 'Fpm reload'
task :fpm_reload do
on release_roles :all do |host|
execute :service, 'php5-fpm', :reload
end
end
The docs: http://capistranorb.com/documentation/getting-started/flow/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With