【问题标题】:Rails 4 doesn't detect application after capistrano deployment在 capistrano 部署后 Rails 4 未检测到应用程序
【发布时间】:2015-03-14 07:12:19
【问题描述】:

我目前正在尝试使用 Capistrano 3 部署 Rails 4 应用程序。一切顺利,但我遇到了一个问题,是的!我无法在我的应用程序中运行任何 rails 命令。

这是我相关的 capistrano 插件:

gem 'capistrano-rails'
gem 'capistrano-unicorn-nginx'
gem 'capistrano-rbenv'
gem 'capistrano-secrets-yml'
gem 'capistrano-rails-console'

所以当我运行 cap production rails:console 时,它会给出以下输出:

    [b2458a1e] Running /usr/bin/env [ -d ~/.rbenv/versions/2.1.1 ] as user@x.x.x.x
DEBUG [b2458a1e] Command: [ -d ~/.rbenv/versions/2.1.1 ]
DEBUG [b2458a1e] Finished in 0.528 seconds with exit status 0 (successful).
INFO [2d552562] Running ~/.rbenv/bin/rbenv exec bundle exec rails console production as user@x.x.x.x
DEBUG [2d552562] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.1 ~/.rbenv/bin/rbenv exec bundle exec rails console production )
Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]                                      # Path to the Ruby binary of your choice
                                                         # Default: /home/rails_app/.rbenv/versions/2.1.1/bin/ruby
  -m, [--template=TEMPLATE]                              # Path to some application template (can be a filesystem path or URL)
      [--skip-gemfile], [--no-skip-gemfile]              # Don't create a Gemfile
  -B, [--skip-bundle], [--no-skip-bundle]                # Don't run bundle install
  -G, [--skip-git], [--no-skip-git]                      # Skip .gitignore file
      [--skip-keeps], [--no-skip-keeps]                  # Skip source control .keep files
  -O, [--skip-active-record], [--no-skip-active-record]  # Skip Active Record files
  -S, [--skip-sprockets], [--no-skip-sprockets]          # Skip Sprockets files
      [--skip-spring], [--no-skip-spring]                # Don't install Spring application preloader
  -d, [--database=DATABASE]                              # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/    frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
                                                         # Default: sqlite3
  -j, [--javascript=JAVASCRIPT]                          # Preconfigure for selected JavaScript library
                                                         # Default: jquery
  -J, [--skip-javascript], [--no-skip-javascript]        # Skip JavaScript files
      [--dev], [--no-dev]                                # Setup the application with Gemfile pointing to your Rails checkout
      [--edge], [--no-edge]                              # Setup the application with Gemfile pointing to Rails repository
      [--skip-turbolinks], [--no-skip-turbolinks]        # Skip turbolinks gem
  -T, [--skip-test-unit], [--no-skip-test-unit]          # Skip Test::Unit files
      [--rc=RC]

有什么想法吗?

13/03 更新 - 添加 deploy.rb

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

set :application, 'my_app'
set :repo_url, 'git@github.com:foo/my_app.git'

# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
set :branch, 'master'

# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/var/www/my_app'

# Default value for :linked_files is []
set :linked_files, fetch(:linked_files, []).push('config/database.yml')

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

set :rbenv_ruby, '2.1.1'

【问题讨论】:

  • rails:console 任务从何而来?我没有看到您列出的任何 capistrano gem 提供它。
  • 您确认调用的是什么 Rails 环境? (我正在查看您的INFO [2d552562] Running ~/.rbenv/bin/rbenv exec bundle exec rails console production as user@x.x.x.x 行)。是否可以直接登录服务器并使用same bundle exec 命令调用rails c
  • @MattBrictson 它来自这个插件(capistrano-rails-console)github.com/ydkn/capistrano-rails-console
  • 似乎您正在应用程序根目录之外执行rails console。需要您的 deploy.rb(+ 部署环境的相关配置)来调查问题。
  • 那么它可能与 capistrano 无关。我会尝试在您的bundle exec 命令前面加上RAILS_ENV=production,看看您是否有更好的运气。

标签: ruby-on-rails capistrano


【解决方案1】:

我认为问题在于您在 Rails 应用程序的部署副本中缺少 bin/rails。这是我要做的:

  1. 确保您的bin 目录的内容已添加、提交并推送到您的git 存储库。这将包括bin/railsbin/rake
  2. 从 Capistrano 的 :linked_dirs 设置中删除 bin deploy.rb
  3. 重新部署。

【讨论】:

  • 非常感谢您! :)
猜你喜欢
  • 2016-02-27
  • 1970-01-01
  • 1970-01-01
  • 2019-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-29
  • 1970-01-01
相关资源
最近更新 更多