【问题标题】:SSHKit::Command::Failed: bundle stdout: Nothing written for capistranoSSHKit::Command::Failed:捆绑标准输出:没有为 capistrano 编写
【发布时间】:2025-12-16 06:50:01
【问题描述】:

当我在做cap production deploy 时,我收到以下错误:

cap aborted!
SSHKit::Command::Failed: bundle stdout: Nothing written
bundle stderr: Nothing written

宝石文件:

gem 'capistrano'
gem 'capistrano-rails', '~> 1.1'
gem 'rvm1-capistrano3', require: false
gem 'capistrano-bundler'

Capfile:

# Load DSL and Setup Up Stages
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/bundler'
require 'rvm1/capistrano3'

# Includes default deployment tasks

# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
#   https://github.com/capistrano/rvm
#   https://github.com/capistrano/rbenv
#   https://github.com/capistrano/chruby
#   https://github.com/capistrano/bundler
#   https://github.com/capistrano/rails/tree/master/assets
#   https://github.com/capistrano/rails/tree/master/migrations
#
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
# require 'capistrano/bundler'
# require 'capistrano/rails/assets'
# require 'capistrano/rails/migrations'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

部署.rb

require 'capistrano/bundler'
set :application, 'firm'
set :scm, :git
set :stage, :production
set :branch, "master"
set :repo_url, url
set :deploy_to, "/path/"
set :linked_files, fetch(:linked_files, []).push('config/database.yml')
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system', 'public/pdfs')
# specify how many releases Capistrano should store on server's harddrive
set :keep_releases, 5
set :bundle_without, [:development]
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
# set :deploy_to, '/var/www/my_app'
# set :scm, :git

# set :format, :pretty
set :log_level, :trace
#set :rvm_type, :system
# set :pty, true

# set :linked_files, %w{config/database.yml}
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# set :keep_releases, 5
set :rvm1_ruby_version, "2.2.1"
set :rvm_ruby_string,           :local
#SSHKit.config.command_map[:rake]  = "~/.rvm/bin/#{fetch(:application)}_bundle exec rake"
set :bundle_flags, '--deployment --quiet'
set :bundle_gemfile, -> { release_path.join('Gemfile') }
set :bundle_dir, -> { shared_path.join('bundle') }
set :bundle_without, %w{test development}.join(' ')
set :bundle_binstubs, -> { shared_path.join('bin') }
namespace :deploy do

  desc "Symlink shared config files"
  task :symlink_config_files do
    sh "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end

end

【问题讨论】:

  • 一般来说,这个错误仅仅意味着 capistrano 在远程服务器上执行的命令之一,failed with non-zero exit code。如果您需要更多帮助,请使用--trace 运行cap 命令并提供日志输出。

标签: ruby-on-rails ruby capistrano


【解决方案1】:

你有多少内存?

我自己刚刚解决了这个问题,确实是内存问题。

你可以试试:

  1. 重启服务器,再次尝试部署。
  2. 增加服务器上的 SWAP。

【讨论】:

  • 我正在尝试在我的本地机器上部署
  • 我不确定我是否理解?您正在部署到您从 ? 调用 cap production deploy 的同一台机器上?
  • 反对者,需要解释一下吗?这与您在 DigitalOcean 等平台上内存不足时收到的错误消息完全相同。