2013-12-19 24 views
1

部署当我尝试用Capistrano的部署,i'hve得到了一个错误:不能与Capistrano的

帽生产部署:安装

我有此错误消息:

/home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano/gateway.rb:55: formal argument cannot be an instance variable (SyntaxError) 
      SSH.connect(server, @options) do |@session| 
                ^
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require' 
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano/configuration/connections.rb:1:in `<top (required)>' 
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require' 
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require' 
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano/configuration.rb:4:in `<top (required)>' 
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require' 
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require' 
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano.rb:1:in `<top (required)>' 
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require' 
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require' 
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano/cli.rb:1:in `<top (required)>' 
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require' 
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require' 
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/bin/cap:3:in `<top (required)>' 
from /home/paul/.rbenv/versions/2.0.0-p247/bin/cap:23:in `load' 
from /home/paul/.rbenv/versions/2.0.0-p247/bin/cap:23:in `<main>' 

这里是我的Capfile:

load 'deploy' if respond_to?(:namespace) # cap2 differentiator 
load 'config/deploy' 

而且我deploy.rb:

需要 “捆绑/ Capistrano的”

# allowing shell interactions 
default_run_options[:pty] = true 

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

set :application, "myapp" 
set :user, "myapp" 
set :repository, "[email protected]:conicrea/myapp.git" 
set :ssh_options, { :forward_agent => true } 
set :deploy_to, "/var/www/#{application}" 

set :scm, :git 
set :deploy_via, :remote_cache 

# number of releases we want to keep 
set :keep_releases, 3 

set :use_sudo, false 
# default rails_env, should be overrided in config/deploy/#{environnement}.rb 
set :rails_env, "staging" 

# unicorn informations 
set :unicorn_config, "#{current_path}/config/unicorn.rb" 
set :unicorn_pid, "#{shared_path}/pids/unicorn.pid" 
set :unicorn_bin, "#{current_path}/bin/unicorn" 

# useful for rbenv 
set :default_environment, { 
    'PATH' => "/home/synbioz/.rbenv/shims:/home/synbioz/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 
} 

namespace :maintenance do 
    task :start do 
    run "ln -nfs #{shared_path}/system/_maintenance.html #{shared_path}/system/maintenance.html" 
    end 

    task :stop do 
    run "rm -f #{shared_path}/system/maintenance.html" 
    end 
end 

namespace :deploy do 
    task :start, :roles => :app, :except => { :no_release => true } do 
    run <<-CMD 
     cd #{current_path} && #{unicorn_bin} -C#{unicorn_config} -E #{rails_env} -D 
    CMD 
    end 

    task :force_stop, :roles => :app, :except => { :no_release => true } do 
    run <<-CMD 
     if [ -e #{unicorn_pid} ]; then 
     kill -9 $(cat #{unicorn_pid}); 
     fi 
    CMD 
    end 

    task :stop, :roles => :app, :except => { :no_release => true } do 
    run <<-CMD 
     if [ -e #{unicorn_pid} ]; then 
     kill $(cat #{unicorn_pid}); 
     fi 
    CMD 
    end 

    task :graceful_stop, :roles => :app, :except => { :no_release => true } do 
    run <<-CMD 
     if [ -e #{unicorn_pid} ]; then 
     kill -s QUIT $(cat #{unicorn_pid}); 
     fi 
    CMD 
    end 

    task :reload, :roles => :app, :except => { :no_release => true } do 
    run <<-CMD 
     if [ -e #{unicorn_pid} ]; then 
     kill -s USR2 $(cat #{unicorn_pid}); 
     fi 
    CMD 
    end 

    task :restart, :roles => :app, :except => { :no_release => true } do 
    run <<-CMD 
     if [ -e #{unicorn_pid} ]; then 
     kill -9 $(cat #{unicorn_pid}); 
     sleep 5; 
     cd #{current_path} && #{unicorn_bin} -C#{unicorn_config} -E #{rails_env} -D; 
     fi 
    CMD 
    end 
end 

desc "Create shared folders." 
after 'deploy:setup', :roles => :app do 
    # for unicorn 
    run "mkdir -p #{shared_path}/sockets" 
    run "mkdir -p #{shared_path}/config" 
    # only for sqlite 
    run "mkdir -p #{shared_path}/db" 
end 

desc "Link db.yml." 
after 'deploy:update_code', :roles => :app do 
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" 
end 

desc "Seed datas when cold deploying." 
after 'deploy:migrate', :roles => :app, :only => { :no_release => true } do 
    run "cd #{release_path} && bin/rake db:seed RAILS_ENV=#{rails_env}" 
end 

desc "Link maintenance, rbenv and precompile assets." 
after 'deploy:symlink', :roles => [:web, :app] do 
    run "ln -nfs #{shared_path}/config/.rbenv-version #{release_path}/config/.rbenv-version" 
    run "cp #{release_path}/public/_maintenance.html #{shared_path}/system/" 
    run "cd #{release_path}; RAILS_ENV=#{rails_env} bin/rake assets:precompile" 
end 

desc "remove unused releases." 
after "deploy", "deploy:cleanup" 

我不知道该怎么办! 有人能帮助我吗?

非常感谢!

回答

5

这是一个非常旧版本的Capistrano(2.0.0是从2007年7月开始的,不支持Ruby 1.9/2.0中的更改 - 在这种情况下,Ruby 1.9不再允许使用实例变量作为参数到块)。

您需要升级到最新的2.x版本(2.15.5)。

您也可以升级到Capistrano v3,但请记住它是一个完整的重写,您现有的配置将而不是与v3兼容,没有一些工作。