Ruby on rails 未能启动cap v3 rails 4乘客部署Web应用程序,因为找不到文件

Ruby on rails 未能启动cap v3 rails 4乘客部署Web应用程序,因为找不到文件,ruby-on-rails,nginx,capistrano,rbenv,Ruby On Rails,Nginx,Capistrano,Rbenv,当我们部署到我们的服务器时,一切都部署得很好,但是我们马上就会收到错误“gemfilenotfound”。起初我以为这是nginx没有启动,但是如果我重新启动这个盒子,错误就会消失,应用程序也会正常工作。我们正在试图确定为什么会发生这种情况,以及如何解决它。到目前为止,我还不知道从哪里开始,而且我对“谷歌”的研究似乎没有找到任何答案 服务器设置和部署的详细信息: require 'pry' # Load DSL and Setup Up Stages require 'capistrano/se

当我们部署到我们的服务器时,一切都部署得很好,但是我们马上就会收到错误“gemfilenotfound”。起初我以为这是nginx没有启动,但是如果我重新启动这个盒子,错误就会消失,应用程序也会正常工作。我们正在试图确定为什么会发生这种情况,以及如何解决它。到目前为止,我还不知道从哪里开始,而且我对“谷歌”的研究似乎没有找到任何答案

服务器设置和部署的详细信息:

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 }
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
  • 轨道4
  • rbenv
  • ruby 2.1.0
  • 卡皮斯特拉诺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 }
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
deploy.rb:

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 }
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
错误:

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 }
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:02:10

使用后,我们发现多个nginx实例正在运行,如图所示:

我可以终止服务并重新启动它,但似乎通过chef或我们的cap部署在服务器上没有正确配置某些东西。如果我重新启动box,事情会如前所述正常工作,但我们也尝试终止nginx服务。我们发现这同样有效。我们的开发运营团队正在进行这方面的工作,但我们仍然对这是如何发生的或如何修复它感到困惑

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

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


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


此更新是对chef:default[“rackbox”][“default\u config”][“passenger\u runit”][“spawn\u method”]=“smart”

中的rackbox default属性进行的。是否可能通过.gitignore忽略了您的Gemfile?听起来bundler安装到的路径/gemset与rbenv ruby不同。您正在使用rbenv将ruby安装到/opt/ruby。我将首先确保“capistrano/bundler”将bundler安装到rbenv ruby install in/opt/ruby知道的路径。e、 g.
哪个bundle
哪个ruby
,或者添加rbenv知道的路径,或者以不同的方式安装bundler,这样您就可以保证rbenv知道它。@Anlek yes gem文件正确过来了。@mmay当我运行哪个ruby时我得到了“/opt/rbenv/shimmes/ruby”我得到了哪个捆绑机/opt/rbenv/shimmes/bundler,哪个捆绑机/opt/rbenv/shimmes/bundle。想法?嗯…这证实了我的直觉是错的!前几天我遇到了一个类似的问题,在我的案例中,修复路径解决了这个问题。没有使用Capistrano,所以不确定它在这里使用的是什么魔法。是否确认符号链接设置正确?它在那条路径下寻找的文件真的在那里吗?对不起,帮不上忙了!