当我尝试使用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:
要求“bundler / 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, "git@gitlab.conicrea.com: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"
我不知道该怎么办! 有人可以帮帮我吗?
非常感谢!
答案 0 :(得分:5)
这是非常旧版本的Capistrano(2.0.0是从2007年7月开始,不支持Ruby 1.9 / 2.0中的更改 - 在这种情况下,Ruby 1.9不再允许使用实例变量作为块的参数。)
您需要升级到最新的2.x版本(2.15.5)。
你也可以升级到Capistrano v3,但要记住它是完全重写的,你的现有配置不与v3兼容而没有一些工作。