3

I'm deploying my Rails 3 app using capistrano.

I have on user (deploy) who's been added to sudoers. This is the user I'm deploying with.

When I log on to the server as deploy I have access to all of the gem commands I need .ie: bundle, whenever etc.

Capistrano seems to be running as sudo though, and when I try:

sudo whenever

I get

sudo: whenever: command not found

This means each time I try to deploy, it fails and rolls back.

I've tried setting :use_sudo to false in my deploy.rb file but still no luck

set :user, "deploy"
set :runner, user
set :use_sudo, false

Any suggestions?

Here's my complete deploy script in case there's anything in there I've missed:

require 'config/boot'
require 'hoptoad_notifier/capistrano'
require 'capistrano/ext/multistage'
require "whenever/capistrano"
# 
set :whenever_command, "bundle exec whenever"

set :application, "MYAPP"
set :repository,  "git@github.com:myAccount/myRepos.git"

# only keep 3 previous releases after cleanup
set :keep_releases, 3

set :scm, "git"
set :scm_user, "me"
set :branch, lambda {rails_env}
set :deploy_to, lambda {"/var/www/#{application}/#{rails_env}"}


default_run_options[:pty] = true

role :web, "xxx.xxx.xxx.xxx"                          # Your HTTP server, Apache/etc
role :app, "xxx.xxx.xxx.xxx"                          # This may be the same as your `Web` server
role :db,  "xxx.xxx.xxx.xxx", :primary => true        # This is where Rails migrations will run

set :user, "deploy"
set :runner, user
set :use_sudo, false

ssh_options[:paranoid] = false 
ssh_options[:port] = 22 

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app do
    run " touch #{File.join(current_path,'tmp','restart.txt')}"
  end

end

namespace :bundle do

  desc "run bundle install"
  task :install do
    run "cd #{current_release} && bundle install"
  end

end

namespace :tail do

  desc "Tail the current environment's log file"
  task :log, :roles => :app do
    stream "tail -f #{shared_path}/log/#{rails_env}.log"  
  end

  desc "Tail the new relic log file"
  task :new_relic, :roles => :app do
    stream "tail -f #{shared_path}/log/new_relic.log"  
  end

end


before "deploy:restart", "bundle:install"
after "deploy:restart", "deploy:cleanup"
after "deploy:restart", "whenever:update_crontab"
bodacious
  • 6,608
  • 9
  • 45
  • 74
  • I should add that I'm using Capistrano multistage so the rails_env variable is set in /deploy/staging.rb – bodacious Feb 15 '11 at 18:00
  • 1
    Gavin, please add the error and stacktrace you get? – Augusto Feb 15 '11 at 18:12
  • This is the relevant part: ** [out :: xxx.xxx.xxx.xxx] sh: whenever: not found command finished *** [deploy:update_code] rolling back * executing "rm -rf /var/www/mysite/staging/releases/20110215174217; true" servers: ["xxx.xxx.xxx.xxx"] [xxx.xxx.xxx.xxx] executing command command finished failed: "sh -c 'cd /var/www/mysite/staging/releases/20110215174217 && whenever --clear-crontab mysite'" on xxx.xxx.xxx.xxx – bodacious Feb 15 '11 at 19:23
  • Remember that Capistrano is by default not starting the session and running ~/.bashrc etc. files that setup the env (so for example the PATH variable is not set as needed). Another issue is a badly configured /etc/sudoers file. Can you paste it here? – Szymon Jeż Feb 16 '11 at 09:52

1 Answers1

4

on server run which whenever or whereis whenever you should get full path to the command put it into script:

set :whenever_command, "path_to-whenever"

It's not clean solution but might work.


Another solution might be sudo reconfiguration, go to /etc/sudoers and have a look on env_keep adding PATH might have been important, to keep all the stuff important for application you could use rvm, capistrano-rvm integration and put all the displayed variables from rvm info to env_keep, theoreticaly it should work, just be careful to not mess anything

mpapis
  • 52,729
  • 14
  • 121
  • 158
  • That's a quick workaround for the whenever command but it doesn't fix the other gem commands Does sudo _cmd_ use a different path from _cmd_ ? – bodacious Feb 15 '11 at 20:49
  • RVM was a point in the right direction... Now I've installed RVM on my server too and I'm using a gemset for my specific app. ree@myapp Works a treat now as gem executables are now available to my deploy user – bodacious Feb 17 '11 at 15:42