就像我在标题中所写的,Unicorn主进程最近(在部署和重新启动之后)正在杀死工作者并且一直在开始新的工作,这就是为什么我的Rails应用程序根本不起作用的原因。除此之外,服务器上的CPU是100%。但是,如果我制作上限独角兽:停止正在关闭正确关闭但是在独角兽上限之后:开始它再次重新开始。
unicorn.rb:
# Should be 'production' by default, otherwise use other env
rails_env = ENV['RAILS_ENV'] || 'production'
app_path = "/home/ruby/app/current"
listen 5000
# Spawn unicorn master worker for user ruby (group: www-data)
user 'ruby', 'ruby'
working_directory app_path
worker_processes 2
timeout 90
#preload_app true
# Log everything to one file
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"
# Set master PID location
pid "#{app_path}/tmp/pids/unicorn.pid"
# To save some memory and improve performance
GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true
# Force the bundler gemfile environment variable to
# reference the Сapistrano "current" symlink
before_exec do |_|
ENV["BUNDLE_GEMFILE"] = File.join(@app, 'Gemfile')
end
before_fork do |server, worker|
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
Rails.logger.info('Disconnected from ActiveRecord')
end
old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
end
end
sleep 1
end
after_fork do |server, worker|
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
Rails.logger.info('Connected to ActiveRecord')
end
端
和我的deploy.rb
require "bundler/capistrano"
require 'rvm/capistrano'
set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"
set :default_shell, :bash
set :rvm_type, :system
set :rvm_ruby_string, '1.9.3-p194'
set(:rvm_path) { "/usr/local/rvm" }
set :application, "investwallet"
# main details
role :web, "example.com"
role :app, "example.com"
role :db, "example.com"
# server details
default_run_options[:pty] = true
set :deploy_to, "/home/ruby/app"
set :deploy_via, :remote_cache
set :user, "ruby"
set :use_sudo, false
set :port, 22
# repo details
set :scm, :git
set :scm_username, "git"
#set :scm_passphrase, "" # The deploy user's password
set :repository, "git@example.com:/opt/git/example.git"
set :branch, "master"
#set :git_enable_submodules, 1
set :keep_releases, 3
set(:releases_path) { File.join(deploy_to, version_dir) }
set(:shared_path) { File.join(deploy_to, shared_dir) }
set(:current_path) { File.join(deploy_to, current_dir) }
set(:release_path) { File.join(releases_path, release_name) }
default_environment["RAILS_ENV"] = 'production'
require 'capistrano-unicorn'
after 'deploy:update_code', 'deploy:symlink_db'
after 'deploy:update_code', 'deploy:symlink_letter_opener'
after "deploy:restart", "deploy:cleanup"
after 'deploy:restart', 'unicorn:reload' # app IS NOT preloaded
after 'deploy:restart', 'unicorn:restart' # app preloaded
namespace :deploy do
desc "Symlinks the database.yml"
task :symlink_db, :roles => :app do
run "ln -nfs #{deploy_to}/shared/config/database.yml # {release_path}/config/database.yml"
end
desc "Symlinks the tmp letter opener"
task :symlink_letter_opener, :roles => :app do
run "ln -nfs #{shared_path}/letter_opener/ #{release_path}/tmp/letter_opener"
end
端
namespace :unicorn do
desc "Restart Unicorn"
task :restart do
unicorn.stop
unicorn.start
end
端
答案 0 :(得分:0)
尝试bundle install
你有机会包括一个宝石,并没有安装它。