简体   繁体   中英

Can't deploy with capistrano

When I try to deploy with capistrano, i'hve got an error :

cap production deploy:setup

I've this error message :

/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>'

Here is my Capfile :

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

And my deploy.rb :

require "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"

I don't know what to do ! Can somebody help me ?

Thanks a lot !

That is a very old version of Capistrano (2.0.0 is from July 2007, and doesn't support changes in Ruby 1.9/2.0 -- in this case, Ruby 1.9 no longer allowed using instance variables as arguments to blocks).

You'll need to upgrade to the newest 2.x release (2.15.5).

You could also upgrade to Capistrano v3, but keep in mind it was a complete rewrite and your existing configuration will not be compatible with v3 without some work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM