I'm trying to deploy a rails app using vlad the deployer.
I'm using nginx and passenger.
I have an issue with the vlad:start_app task.
When I deploy I get the following issue
touch: cannot touch `/var/www/mysite.com/releases/20100623130302/tmp/restart.txt': No such file or directory
rake aborted!
execution failed with status 1: ssh mysite.com touch /var/www/mysite.com/releases/20100623130302/tmp/restart.txt
The issue is obvious in that the 20100623130302 in releases does not exist.
I would rather use the following task but cant override the default vlad:start_app task by placing this in my config/deploy.rb file.
namespace :vlad do
desc 'Restart Passenger'
remote_task :start_app do
run "touch #{current_path}/tmp/restart.txt"
end
end
Any help appreciated. The options I though of are to either get the default vlad task to work or someway to override the default vlad task.
RAILS_ROOT/Rakefile is the file.
To override a task you have to remove the previous one first as defining the same task again just creates a second task that will run after the first one.
Here's an example from the vlad website how to replace a task:
namespace :vlad do
# Clear existing update task so that we can redefine instead of adding to it.
Rake.clear_tasks('vlad:update')
remote_task :update, :roles => :app do
#custom update stuff
end
end
Related
I'm seeking help concerning the whenever gem. Here my case:
I have the task I generated and that works when I run it through command line as such rake dashboard_data_t:collect.
namespace :dashboard_data_t do
desc "TODO"
task collect: :environment do
#task...
end
end
I then followed the documentation provided here in such a way that my config/schedule.rb looks like so:
# config/schedule.rb
every :day, at: '10:43 am' do
rake "dashboard_data_t:collect"
end
Happily done with that, I thought it would go on and run itself alone, without me needing to do anything more. But I noticed it didn't. I thought it might come from my task so I created an other one, this time way more simple than the 1st. Its purpose was solely to experiment and find what was going wrong:
namespace :test_name do
desc "TODO"
task test_task: :environment do
sh('echo', 'test task runned successfully')
end
end
I then added the following to my config/schedule.rb:
# config/schedule.rb
every 1.minutes do
rake "test_name:test_task"
end
Once again, the task didn't execute (periodically), but was still working manually.
I noticed by running the crontab -e command that RAILS_ENV was set to production, I understood why my dashboard_data_t:collect task wasn't working, because it relied on the development db. So I did the following:
# config/schedule.rb
set :environment, 'development'
Unfortunately, this didn't change anything as both tasks still don't execute. Now I'm stuck here with no ideas whatsoever. Can anyone help me.
Cheers.
I'm using Capistrano 3 and I want to create my own task. So I created a file my_new_thing.rake in lib/capistrano/tasks and I can see the task when I run cap -T. But... some of the methods aren't available. When I try to use upload! I get
cap aborted!
NoMethodError: undefined method `upload!' for main:Object
But if I move the same task into config/deploy.rb then then upload! method is available.
So what's going on? How do I create new Capistrano tasks put them in separate file and have them work?
I had the same problem, I created my own recipe in a separate file which I loaded in deploy but couldn't get upload! to work.
What fixed it for me was adding a role filter inside the task making my final recipe look something like this:
namespace :figaro do
desc "Transfer Figaro's application.yml to shared/config"
task :upload do
on roles(:all) do
upload! "config/application.yml", "#{shared_path}/config/application.yml"
end
end
end
before "deploy:check", "figaro:upload"
I hope that helps!
You can create a folder config/recipes for your capistrano recipes if you want to keep them in separate files.
Use the .rb extension since this isnt a regular rake task.
In config/deploy.rb add this line
load File.expand_path('../recipes/my_new_thing.rb', __FILE__)
If you want to use the rake tasks then you will need to create a task in the deploy file which calls that rake tasks which is not that smart of a move. So as #Sharagoz suggested the best route will be to create your own recipe file and include that in.
I have created a custom capistrano task located in the lib/capistrano/tasks directory.
I have placed the task under a namespace. When I run cap -T my task appears in the list.
I want to call the git:create_release task inside my task. Currently I have:
namespace :setup do
desc "Performs a setup"
task :run do
on roles(:all) do
git.create_release
end
end
end
However, the above does not work. It gives me the following error:
undefined local variable or method `git'
Now I assume the issue lies in not having some explicit import of the git submodules. I am not sure how to go about including them in the custom tasks module.
Instead of git.create_release I think you need invoke "git:create_release". See the Capistrano README.
I have this simple rake task which refuses to run. I just don't see why it looks correct. Who can pinpoint me to the probably very simple mistake I made? Thank you!
/lib/tasks/reindex.rb:
namespace :db do
desc "Tire reindex profiles"
task :reindex => :environment do
system "cd #{Rails.root} && rake environment tire:import CLASS='Profile' FORCE=true"
end
end
The error:
rake db:reindex
rake aborted!
Don't know how to build task 'db:reindex'
Rename your file to reindex.rake and it should work.
Related: How to build task 'db:populate'
You can also get this error if you forget to put the namespace before your task name. (i.e. :reindex instead of db:reindex)
The file extension for rake tasks must be '.rake'.
If you named your file as '.rb', then rake will not find it, and you will question your own sanity for several minutes before ending up here.
Don't forget to check that you call the name of the task and not the file name.
The best thing is that they be named the same.
This error happen to me is because the namespace name got underscore
As is: deploy_app (not work)
To be: deployapp (working)
I've an issue at the moment where we are running a CMS within a site
(browsercms) that lets the user upload files. However, every time I
do a deploy Capistrano runs a hard reset thus nuking any uploaded
files.
Does anyone have any suggestions as to how to prevent the hard reset,
and just do a pull, or a way of moving the uploaded files elsewhere,
without having to change the application code?
This might not be the right approach.
You should include your 'images' folder in your .gitignore and symlink the $current_release/images folder to $shared/images.
This may be done automatically on every deployment if you put in your deploy.rb:
task :link_imgs do
run "ln -s #{shared_path}/photos #{release_path}/photos"
end
after "deploy:update_code", :link_imgs
I've done the same with my CMS and it works like a charm
This doesn't quite meet your criteria of "without having to change the application code".
However after running into a similar issue I shifted my uploaded image from /public/images to /public/system/images the /public/system directory is not 'versioned' by each capistrano deployment so the images survive.
Could it be the capistrano 'versioning' causing the problem (instead of a git reset)?
cap deploy calls deploy:update and deploy:restart
deploy:update makes the versioning, copying stuff
deploy:restart does the true restart, overload it at your convenince, usually in your config/deploy.rb file
namespace :deploy do
desc "Softly restart the server"
task :restart, :roles => :app, :except => { :no_release => true } do
my_own.restart_recipe
end
end