I have a capistrano script that works perfect, except it's not running a task after the deploy. I'm using rails_daemons to launch the rails application and a I need to restart the daemons.
#deploy.rb
namespace :deploy do
on roles :all do
execute :bundle, "exec rake daemons:restart"
end
end
Tryed this also:
task :restart_daemons, :roles => :app do
execute :bundle, "exec rake daemons:restart"
end
after "deploy", "deploy:restart_daemons"
First off, have you checked if bundle exec rake daemons:restart works locally? If so, try something like this:
namespace :deploy do
after :restart do
on roles(:web), in: :groups, limit: 3, wait: 10 do
within release_path do
execute :rake, 'daemons:restart'
end
end
end
end
Related
I have the following in my deploy script in which I inherited from other devs. Does any one know what the rake task db:full_reset does? I would think it resets the db but I can't find that actual task anywhere in the code. Running rake -T doesn't give any clues. Would it be located in a gem?
namespace :db do
task :full_reset do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :bundle, "exec rake db:full_reset"
end
end
end
end
end
You can use rake -W db:full_reset to see where that task is defined
I use the following deploy.rb :
# config valid only for current version of Capistrano
lock '3.4.0'
set :application, '*****'
set :rails_env, 'production'
set :repo_url, 'admin#test.*******.***:/srv/outils/repos/*****'
set :scm, :git
namespace :deploy do
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
#after 'deploy:publishing', 'deploy:restart'
end
after 'deploy:publishing', 'deploy:restart'
It correctly deploy the app but does not restart it. What should i modify to make it restart? There is no message, error or otherwise, about the restart.
In Capistrano 3, the restart task is available and will be called, but it is empty. See the Capistrano source code in capistrano/lib/capistrano/tasks/deploy.rake for the code:
[...]
task :restart
task :failed
end
If you want the restart task to actually do something, you can change the default behavior for restart by adding this code to your deploy.rb:
namespace :deploy do
task :restart do
invoke rake-restart-something-task
end
end
Where the rake-restart-something-task can be something like deploy:service:restart_apache, or some other task that you defined in the capistrano rake file.
I deployed my app to vps with capistrano.
Everything works fine but only :environment task.
This is my code
namespace :deploy do
desc 'Clear memcache'
task clear_memcache: :environment do
on roles(:app) , in: :sequence, wait: 2 do
::Rails.cache.clear
CACHE.flush
end
end
after :finishing, :clear_memcache
end
But i always got this error.
#<RuntimeError: Don't know how to build task 'environment' (see --tasks)>
How can i fix this?
Thanks!
I think you are mixing two concepts. A rake task and a capistrano task. Rake tasks do use the :environment subtask, whereas the capistrano ones don't. Capistrano tasks cannot (AFAIK) directly call ruby code in the context of the rails application on the server, this is what rake tasks do.
What you actually probably want is to define both a rake task to clear the cache and a capistrano task that will call the rake task on the deployment server.
Try these:
The rake task to clear the cache:
# put this in Rakefile or any other rake file under lib/tasks
desc 'Clear memcache'
task clear_memcache: :environment do
::Rails.cache.clear
CACHE.flush
end
The capistrano task to call the rake on the server:
# config/deploy/production.rb
namespace :deploy do
desc 'Clear memcache'
task :clear_memcache do
on roles(:app) , in: :sequence, wait: 2 do
within release_path do
with rails_env: fetch(:rails_env) do
execute 'rake', 'clear_memcache'
end
end
end
end
after :finishing, :clear_memcache
end
I've been trying this for days without success now. I am using Capistrano 3 to deploy my Ruby on Rails 4 code on my production server.
At the end of the deployment process, I want to restart my daemon scripts, which I would manually do by this command:
RAILS_ENV=production bundle exec ruby script/my_daemon restart
On my Capistrano 3 recipe (config/deploy.rb) I've tried a few different settings but none of those worked.
namespace :deploy do
desc 'Restart application'
task :restart do
invoke 'unicorn:restart'
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
within release_path do
execute :rake, 'tmp:cache:clear'
# Daemons
# This ends up with an error
execute :bundle, :exec, :ruby, "RAILS_ENV=production /var/www/MY_APP/current/script/my_daemon restart;"
# This starts the daemon, but in development environment
execute :bundle, :exec, :ruby, "/var/www/MY_APP/current/script/my_daemon restart RAILS_ENV=production;"
# This also starts the daemon, but in development environment
execute :bundle, :exec, :ruby, "/var/www/MY_APP/current/script/my_daemon restart;"
end
end
end
end
Could someone help me write the right recipe to restart my daemons in production environment? Thanks.
Try setting env via capistrano dsl
within release_path do
with rails_env: :production do
execute :bundle, :exec, :ruby, "#{current_path}/script/my_daemon restart"
end
end
I'm new to Capistrano and I was wondering how you can control the
order of execution of tasks in a certain name space.
For example, I have some extra tasks in my deploy namespace. I wanted
deploy:bundle and deploy:assets to run before deploy:restart so I
added these lines
after 'deploy:update_code', 'deploy:bundle'
after 'deploy:bundle', 'deploy:assets'
after 'deploy:assets', 'deploy:restart'
I'm not sure if this how you're supposed to do it. Please let me know
if you guys have any tips for me!
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true }
do
run "touch #{current_path}/tmp/restart.txt"
end
task :bundle do
run "cd #{current_path} && bundle install"
end
task :assets do
run "cd #{current_path} && bundle exec rake assets:precompile"
end
end
after 'deploy:update_code', 'deploy:bundle'
after 'deploy:bundle', 'deploy:assets'
after 'deploy:assets', 'deploy:restart'