2011-02-15 20 views
3

我正在使用capistrano部署我的Rails 3應用程序。當使用Capistrano進行部署時,Sudo無法訪問shell命令

我在用戶(部署)誰已被添加到sudoers。這是我正在部署的用戶。

當我登錄到服務器部署我可以訪問所有的寶石命令我需要.IE:捆綁,只要等

Capistrano的似乎儘管人作爲運行sudo的,當我嘗試:

sudo whenever 

我得到

sudo: whenever: command not found 

這意味着每一個我嘗試部署時,它失敗並回滾。

我試過設置:use_sudo爲false我deploy.rb文件,但仍然沒有運氣

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

有什麼建議?

這裏是萬一我的完整部署腳本那裏面有什麼我已經錯過了:

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, "[email protected]: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" 
+0

我應該補充一點,我使用Capistrano多級,因此rails_env變量設置在/deploy/staging.rb中 – bodacious 2011-02-15 18:00:24

+1

Gavin,請添加你得到的錯誤和堆棧跟蹤? – Augusto 2011-02-15 18:12:37

回答

4

在服務器上運行which wheneverwhereis whenever你應該得到完整路徑命令把它變成腳本:

set :whenever_command, "path_to-whenever" 

這不是乾淨的解決方案,但可能工作。


另一種解決方案可能是sudo的重新配置,去/etc/sudoers和對env_keep添加PATH一看可能是重要的,讓所有的工具和應用具有重要的,你可以使用RVM,Capistrano的-RVM整合,並把所有顯示的變量從rvm info env_keep,理論上它應該工作,只是要小心,不要弄髒任何東西

相關問題