4

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!

3 Answers 3

7

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.

7

You should use:

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

With capistrano 3.x

1
  • 1
    What's the difference between execute and run? Is it just that the name's changed?
    – mwfearnley
    Aug 15, 2016 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
1
  • How can I take the output of an execute command in a variable ? Jan 7, 2015 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .