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 seem开发者_如何学Gos 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"
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
精彩评论