3

I have a very simple task called update_feeds:

desc "Update feeds"
task :update_feeds do
  run "cd #{release_path}"
  run "script/console production"
  run "FeedEntry.update_all"
end

Whenever I try to run this task, I get the following message:

[out :: mysite.com] sh: script/console: No such file or directory

I figured it's because I am not in the right directory, but trying

run "cd ~/user/mysite.com/current"

instead of

run "cd #{release_path}"

Also fails. Running the exact same commands manually (through ssh) works perfectly. Why can't capistrano properly cd (change directory) into the site directory to run the command?

Thanks!

6

Each run command basically executes within its own shell environment. So you would need to do something like:

run "cd #{release_path} && script/console production"

However, you cannot run commands in script/console this way as script/console is for interactive usage.

What you want is script/runner like so:

run "cd #{release_path} && script/runner -e production 'FeedEntry.update_all'"

I hope that helps.

5

You should use:

execute "cd #{release_path} && script/console production"

With capistrano 3.x

  • What's the difference between execute and run? Is it just that the name's changed? – mwfearnley Aug 15 '16 at 16:16
1

The proper way of doing this is using within like that:

within variable_with_the_folder_path do
    execute :command, parameter
end

for example:

    # Bower Cache Clean:
    bower_path = fetch(:bower_path)
    within bower_path do
      execute :node, "#{bower_path_to_bin}", 'cache clean'
    end
  • How can I take the output of an execute command in a variable ? – Arihant Godha Jan 7 '15 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.