【问题标题】:cap v3 rails 4 passenger deploy Web application could not be started because Gemfile not foundcap v3 rails 4 乘客部署 Web 应用程序无法启动,因为找不到 Gemfile
【发布时间】:2014-11-19 15:34:07
【问题描述】:

当我们部署到我们的服务器时,一切都部署得很好,但是之后我们立即收到错误“找不到 Gemfile”。起初我以为这是 nginx 没有启动,但如果我重新启动机器,错误就会消失并且应用程序可以正常运行。我们正在尝试确定为什么会发生这种情况以及如何解决它。截至目前,我不确定从哪里开始,而且我似乎没有在“谷歌”上研究过任何答案。

服务器设置和部署的细分:

  • 导轨 4
  • rbenv
  • 红宝石 2.1.0
  • capistrano v3
  • 乘客
  • 使用 Chef 构建服务器

Capfile:

require 'pry'
# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'

# 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 }

deploy.rb:

set :application, 'api'

set :scm, :git
set :repo_url, 'git@github.com:PlacewiseMedia/API.git'
set :branch, 'develop'
set :deploy_to, '/home/apps/api'

set :deploy_via, :remote_cache
set :keep_releases, 10
set :user, 'deploy'
set :use_sudo, false

set :rbenv_type, :system
set :rbenv_ruby, '2.1.0'
set :rbenv_path, '/opt/rbenv'

namespace :deploy do

  desc 'Restart application'
  task :restart_application do
    on roles(:app), in: :sequence, wait: 5 do
      spacer("Setting up restart file")
      execute "mkdir -p #{release_path}/tmp ; touch #{release_path}/tmp/restart.txt"
      spacer("Restarting the nginx service")
      execute "sudo service nginx restart"
      spacer()
    end
  end

  desc 'Run Migrations'
  task :update_database do
    on roles(:app), in: :sequence, wait: 5 do
      within(release_path) do
        with rails_env: fetch(:rails_env) do
          spacer("Updating the database")
          execute :rake, "db:migrate", "--trace"
          spacer()
        end
      end
    end
  end

  desc 'Create application symlinks'
  task :shared_links do
    on roles(:app), in: :sequence, wait: 5 do
      spacer("Creating application symlinks")
      execute "rm #{release_path}/config/database.yml"
      execute "ln -s #{shared_path}/config/database.yml #{release_path}/config/database.yml"
      execute "ln -s #{shared_path}/config/secrets.yml #{release_path}/config/secrets.yml"
      execute "ln -s #{shared_path}/bin/passenger #{release_path}/bin/passenger"
      spacer()
    end
  end

  after 'deploy:updated', 'deploy:shared_links'
  after :finishing, 'deploy:update_database'
  after :finishing, 'deploy:restart_application'
  after :finishing, 'deploy:cleanup'
end

namespace :setup do
  desc 'Copy the secrets.yml and database.yml files'
  task config: ['config/secrets.yml', 'config/database.yml'] do |t|
    on roles(:all) do
      execute "mkdir -p #{shared_path}/config"
      t.prerequisites.each do |file|
        upload! file, "#{shared_path}/config"
      end
    end
  end
end

def spacer(desc = nil)
  puts "-----------------------------------------------------------------------------"
  if desc
    puts desc
    puts "-----------------------------------------------------------------------------"
  end
end

错误:

09/25 更新:太平洋标准时间下午 2:10

在使用https://hackhands.com/ 之后,我们发现多个 nginx 实例正在运行,如图所示:

我可以终止服务并重新启动它,但似乎某些内容可能无法通过厨师或我们的上限部署在服务器上正确配置。如果我重新启动盒子,事情会按规定工作,但我们也尝试终止 nginx 服务。我们发现这也有效。我们的开发运营团队正在努力解决这个问题,但我们仍然对这是如何发生的或如何修复它感到困惑。

09/26 更新:太平洋标准时间上午 11:06

我在乘客启动时找到了配置的来源,如果你 查看/etc/service/,您将看到应用程序的文件夹 在服务器上。查看您感兴趣的文件夹中的run 文件 进去,你会看到乘客配置。这会触发ruby .bin/passenger start 进程,然后触发/tmp nginx 在应用程序重新启动时挂起的进程。我试过重新启动 不同的组合,似乎有效的组合是杀死 nginx 进程,然后运行sudo killall ruby 以重新生成新应用程序... 不理想

【问题讨论】:

  • 您的 Gemfile 是否可能通过 .gitignore 被忽略?
  • 听起来 bundler 被安装到不同的 PATH/gemset 然后是 rbenv ruby​​。您正在使用 rbenv 将 ruby​​ 安装到 /opt/ruby。我将首先确保“capistrano/bundler”将捆绑器安装到 /opt/ruby 中的 rbenv ruby​​ 安装知道的路径。例如which bundle, which ruby 或者添加 rbenv 知道的路径或者安装不同的 bundler,这样你就可以保证 rbenv 知道它。
  • @Anlek 是的,gem 文件是正确的。
  • @mmay 当我运行哪个 ruby​​ 我得到“/opt/rbenv/shims/ruby”和哪个捆绑器我得到 /opt/rbenv/shims/bundler 和哪个捆绑 /opt/rbenv/shims/捆。想法?
  • 嗯...这证实了我的预感是错误的!前几天我遇到了类似的问题,在我的情况下修复 PATH 解决了它。没有使用 Capistrano,所以不确定它在这里做了什么样的魔法。也许确认符号链接设置正确?它在该路径下寻找的 Gemfile 是否真的存在?抱歉,帮不上忙!

标签: ruby-on-rails nginx capistrano rbenv


【解决方案1】:

因此,我们的 DevOps 团队为解决此问题所做的更新围绕乘客生成 nginx 的方式展开。它使用的配置是以前版本中较旧的spawn-lv2,我将其更改为当前版本4的spawn。这似乎是为了停止在/tmp中创建新目录,这些目录被runit 脚本,但会失败,因为旧版本仍在运行。现在看起来更新是在当前的/tmp 目录中完成的,所以进程是否仍在运行并不重要。

此更新是针对 chef 中的 rackbox 默认属性进行的:default["rackbox"]["default_config"]["passenger_runit"]["spawn_method"] = "smart"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-20
    • 2014-03-13
    • 1970-01-01
    • 2014-02-28
    • 1970-01-01
    • 2014-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多