sh:rake:在新安装的服务器上找不到

时间:2011-10-06 19:05:09

标签: ruby-on-rails-3 deployment capistrano

我第一次部署代码时遇到错误。我多次使用相同的脚本,并且它成功运行。

部署时出错:

 [out :: ***********] sh: rake: not found

我正在使用RVM,Ruby 1.9.2

部署脚本输出:

  executing `deploy:after_symlink'
  * executing "cp /home/me/my_app/shared/database.yml /home/me/my_app/current/config/database.yml"
    servers: ["**************"]
    ["**************"] executing command
    command finished in 1204ms
  * executing `deploy:migrate'
  * executing "cd /home/me/my_app/current && rake db:migrate RAILS_ENV=production"
    servers: ["**************"]
   ["**************"] executing command
 ** [out :: ***********] sh: rake: not found  // Here is the issue
    command finished in 1023ms
*** [deploy:symlink] rolling back
  * executing "ls -x /home/me/my_app/releases"

宝石清单:在服务器上

gem list

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.1.0, 3.0.10)
actionpack (3.1.0, 3.0.10)
activemodel (3.1.0, 3.0.10)
activerecord (3.1.0, 3.0.10)
activeresource (3.1.0, 3.0.10)
activesupport (3.1.0, 3.0.10)
arel (2.2.1, 2.0.10)
bcrypt-ruby (3.0.1)
builder (3.0.0, 2.1.2)
bundler (1.0.21)
daemon_controller (0.2.6)
erubis (2.7.0, 2.6.6)
fastthread (1.0.7)
hike (1.2.1)
i18n (0.6.0, 0.5.0)
mail (2.3.0, 2.2.19)
mime-types (1.16)
multi_json (1.0.3)
mysql2 (0.2.7)
passenger (3.0.9)
polyglot (0.3.2)
rack (1.3.4, 1.2.4)
rack-cache (1.0.3)
rack-mount (0.8.3, 0.6.14)
rack-ssl (1.3.2)
rack-test (0.6.1, 0.5.7)
rails (3.0.10)
railties (3.1.0, 3.0.10)
rake (0.9.2)
rdoc (3.9.4)
sprockets (2.0.2)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
tzinfo (0.3.30)

我用来部署的脚本:

set :stages, %w(production staging)
require 'capistrano/ext/multistage'

server "Server IP", :app, :web, :db, :primary => true

set(:application) { "app_name" }
set (:deploy_to) { "/home/binarymesh/#{application}" }
set :user, 'my_user'
set :keep_releases, 3
set :repository, "git@github.com:MyRepo"
set :use_sudo, false
set :scm, :git
default_run_options[:pty] = true
ssh_options[:forward_agent] = false
set :deploy_via, :remote_cache
set :git_shallow_clone, 1
set :git_enable_submodules, 1

namespace :deploy do
 desc "Restarting mod_rails with restart.txt"
 task :restart, :roles => :app, :except => { :no_release => true } do
   run "touch #{current_path}/tmp/restart.txt"
 end

 [:start, :stop].each do |t|
   desc "#{t} task is a no-op with mod_rails"
   task t, :roles => :app do ; end
 end

 desc "invoke the db migration"
 task:migrate, :roles => :app do
   send(run_method, "cd #{current_path} && rake db:migrate RAILS_ENV=#{stage} ")
 end


 desc "Deploy with migrations"
  task :long do
    transaction do
      update_code
      web.disable
      symlink
      migrate
    end

    restart
    web.enable
    cleanup
  end

 task :after_symlink, :roles => :app do
   run "cp #{shared_path}/database.yml #{current_path}/config/database.yml"
 end

  desc "Run cleanup after long_deploy"
  task :after_deploy do
    cleanup
  end

end

3 个答案:

答案 0 :(得分:2)

这里可能会有一些帮助:problems-with-capistranos-deploymigrate。答案显示了如何为rvm

设置capistrano扩展

答案 1 :(得分:2)

require "rvm/capistrano"
在我的情况下,在deploy.rb之上的

就足够了。

答案 2 :(得分:1)

添加此

$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'capistrano/ext/multistage'
require "rvm/capistrano"

在我的deploy.rb文件顶部解决了我的问题。