1

I have a task in capistrano set up to execute a precompile and a db:migrate. For some reason when I run these tasks manually on the server they work perfectly fine, but when they're run through a rake task they give me errors.

Here are the capistrano tasks:

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      execute "cd #{current_path}; RAILS_ENV=production bundle exec rake assets:precompile"
      execute "cd '#{current_path}'; RAILS_ENV=production bundle exec rake db:migrate"
    end
  end

Here are the errors:

    INFO [96002080] Running cd /var/www/html/FingertipRails/current; RAILS_ENV=production bundle exec rake assets:precompile on 50.112.106.148
DEBUG [96002080] Command: cd /var/www/html/FingertipRails/current; RAILS_ENV=production bundle exec rake assets:precompile
DEBUG [96002080]    bash: bundle: command not found

I've tried dropping the bundle exec part of the tasks, but then I get errors saying that gems were not installed (when I clearly ran bundle install before)

Any ideas?

Rob
  • 7,028
  • 15
  • 63
  • 95
  • are you running the tasks manually are they running as the same user used by Capistrano? – creativereason Nov 27 '13 at 19:06
  • You could use `cap shell` and, through the shell, run `gem install bundler` – CDub Nov 27 '13 at 19:11
  • capistrano and manual both use ec2-user. what makes it so strange is that when I log in manually and use these commands they execute perfectly fine - it's only as capistrano tasks that they mess up – Rob Nov 27 '13 at 19:12
  • @CDub apparently `cap shell` isn't available in capistrano 3 :( – Rob Nov 27 '13 at 19:15
  • 1
    Here are some alternatives - http://stackoverflow.com/questions/18838930/how-to-run-shell-commands-on-server-in-capistrano-v3 – CDub Nov 27 '13 at 19:16
  • Great idea! I tried doing this and capistrano installed bundler successfully, but I still get bundle command not found. I also tried editing the PATH variable and it still doesn't work. what gives? – Rob Nov 27 '13 at 19:21
  • So I tried running export PATH=$PATH:/home/ec2-user/.rvm/rubies/ruby-2.0.0-p247/bin through capistrano but for some reason when I echo $PATH the changes don't show up. The $PATH variable is also different when I ssh into the server and when I run capistrano – Rob Nov 27 '13 at 19:35

0 Answers0