views:

46

answers:

2

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!


Update: Picked an answer, and thank you so much to all who replied. The best answer may actually be the one on server fault, though the gist of both (the one on server fault and the one on stack overflow) is the same.

+1  A: 

I cannot imagine that you would be able to remotely log into rails console from capistrano. I suggest you call your model method from a rake task.

http://stackoverflow.com/questions/312214/how-do-i-run-a-rake-task-from-capistrano

As for the latter part of your question, are you logging into the server with the same user account as capistrano?

mark
+1  A: 

You want to use script/runner. It starts an instance of the app to execute the method you want to call. Its slow though as it has to load all of your rails app.

~/user/mysite.com/current/script/runner -e production FeedEntry.update_all 2>&1

You can run that from the capistrano task.

inkdeep