"bash: bundle: command not found" - 上限中止

"bash: bundle: command not found" - cap aborted

这是我的 deployment.rb 文件。

# config valid only for current version of Capistrano
lock '3.4.0'

set :stage, 'production'
set :application, "gobgob-ror"
set :repo_url, 'git@github.com:narhamah/gobgob-ror.git'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp

# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/home/ubuntu/gobgob-ror'

# Default value for :scm is :git
set :scm, :git
set :branch, "master"

#set :user, "ubuntu"
set :use_sudo, false
set :rails_env, "production"
set :deploy_via, :remote_cache
set :ssh_options, { user: 'ubuntu', :forward_agent => true, :port => 22, keys: ["#{ENV['HOME']}/.ssh/id_rsa"]}


# Default value for :format is :pretty
# set :format, :pretty

# Default value for :log_level is :debug
# set :log_level, :debug

# Default value for :pty is false
set :pty, true
server "xx.xx.xxx.xxx", roles: [:app, :web, :db], :primary => true

set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets}
# Default value for :linked_files is []
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')

# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

# Default value for keep_releases is 5
set :keep_releases, 5

namespace :deploy do
  desc "Start the application"
  task :start do
    on roles(:app) do
      execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{fetch(:stage)}.log 2>&1 &", :pty => false
    end
  end

  desc "Stop the application"
  task :stop do
    on roles => :app  do
      execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec pumactl -S #{shared_path}/pids/puma.state stop"
    end
  end

  desc "Restart the application"
  task :restart do
    on roles(:app) do
      execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec pumactl -S #{shared_path}/pids/puma.state restart"
    end
  end

  desc "Status of the application"
  task :status do 
    on roles(:app) do
      execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec pumactl -S #{shared_path}/pids/puma.state stats"
    end
  end
end

after "deploy", "deploy:restart"
after "deploy", "deploy:cleanup"

现在我做到了 bundle exec cap production deploy。在巨大的日志之后,我得到了以下错误。

DEBUG [cced60a1]        bash: bundle: command not found
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host <ip-snipped>: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart exit status: 127
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stdout: bash: bundle: command not found
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stderr: Nothing written

SSHKit::Command::Failed: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart exit status: 127
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stdout: bash: bundle: command not found
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stderr: Nothing written

Tasks: TOP => deploy:restart
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing on host <ip-snipped>: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart exit status: 127
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stdout: bash: bundle: command not found
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stderr: Nothing written
[arup@gobgob-ror (master)]$

您的服务器上似乎没有安装 bundler gem。它应该已安装并且 bundle 可执行文件应该在 $PATH.

中可用

尝试直接在服务器上执行 bundle --version 以确定 bundler 确实丢失了。

如果是这种情况,请安装 bundler gem,您应该可以开始使用了。或者为了真正保持自动化,您可以定义一个 capistrano 任务来检查 bundle 可执行文件是否可用,如果不可用则安装 bundler gem。您可以在 bundler:install 任务之前执行此任务。

UPDATE :如果您正在使用某些 ruby 管理器,例如 rvmchruby 或类似的东西, bundle 可执行文件可能不适用于您的 Capistrano 部署任务。在那种情况下,您必须确保您的部署任务获得登录 shell,以便执行所有这些 shell 脚本。

这是我现在所拥有的解决问题的方法。我从 Rustam A. Gasanov 那里得到了帮助以使其正常工作。非常感谢!!

deploy.rb

# config valid only for current version of Capistrano
lock '3.4.0'

set :stage, 'production'
set :application, "gobgob-ror"
set :repo_url, 'git@github.com:narhamah/gobgob-ror.git'
set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.2.2@gobgob'
set :rvm_binary, '~/.rvm/bin/rvm'

# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp

# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/home/ubuntu/gobgob-ror'

# Default value for :scm is :git
set :scm, :git
set :branch, "master"

#set :user, "ubuntu"
set :use_sudo, false
set :rails_env, "production"
set :deploy_via, :remote_cache
set :ssh_options, { user: 'ubuntu', :forward_agent => true, :port => 22, keys: ["#{ENV['HOME']}/.ssh/id_rsa"]}


# Default value for :format is :pretty
# set :format, :pretty

# Default value for :log_level is :debug
# set :log_level, :debug

# Default value for :pty is false
set :pty, true
server "xx.xx.xxx.xxx", roles: [:app, :web, :db], :primary => true

set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets}
# Default value for :linked_files is []
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')

# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

# Default value for keep_releases is 5
set :keep_releases, 5

namespace :deploy do
  desc "Start the application"
  task :start do
    on roles(:app) do
      execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{fetch(:stage)}.log 2>&1 &", :pty => false
    end
  end

  desc "Stop the application"
  task :stop do
    on roles => :app  do
      execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state stop"
    end
  end

  desc "Restart the application"
  task :restart do
    on roles(:app) do
      execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state restart"
    end
  end

  desc "Status of the application"
  task :status do 
    on roles(:app) do
      execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state stats"
    end
  end
end

after "deploy", "deploy:restart"
after "deploy", "deploy:cleanup"

确认其有效的最后输出..

INFO [12d4a428] Running /usr/bin/env cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.2.2@gobgob do bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart on xx.xx.xxx.xxx
DEBUG [12d4a428] Command: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.2.2@gobgob do bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart
DEBUG [12d4a428]        Command restart sent success
DEBUG [12d4a428]
INFO [12d4a428] Finished in 1.379 seconds with exit status 0 (successful).
[arup@gobgob-ror (master)]$