Skip to content

Instantly share code, notes, and snippets.

@workmaster2n
Last active December 23, 2015 17:39
Show Gist options
  • Select an option

  • Save workmaster2n/6670572 to your computer and use it in GitHub Desktop.

Select an option

Save workmaster2n/6670572 to your computer and use it in GitHub Desktop.
Unicorn With RVM
upstream unicorn {
server unix:/tmp/unicorn.arcsite.sock fail_timeout=0;
}
server {
listen 80 default deferred;
# server_name example.com;
root /home/deployer/apps/arcsite/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
Starting - /home/deployer/.rvm/gems/ruby-1.9.3-p392@arcsite_mysql/gems/unicorn-4.6.2/lib/unicorn/configurator.rb:634:in `parse_rackup_file': rackup file (config.ru) not readable (ArgumentError)
from /home/deployer/.rvm/gems/ruby-1.9.3-p392@arcsite_mysql/gems/unicorn-4.6.2/lib/unicorn/configurator.rb:77:in `reload'
from /home/deployer/.rvm/gems/ruby-1.9.3-p392@arcsite_mysql/gems/unicorn-4.6.2/lib/unicorn/configurator.rb:68:in `initialize'
from /home/deployer/.rvm/gems/ruby-1.9.3-p392@arcsite_mysql/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:108:in `new'
from /home/deployer/.rvm/gems/ruby-1.9.3-p392@arcsite_mysql/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:108:in `initialize'
from /home/deployer/.rvm/gems/ruby-1.9.3-p392@arcsite_mysql/gems/unicorn-4.6.2/bin/unicorn:126:in `new'
from /home/deployer/.rvm/gems/ruby-1.9.3-p392@arcsite_mysql/gems/unicorn-4.6.2/bin/unicorn:126:in `<top (required)>'
from /home/deployer/.rvm//gems/ruby-1.9.3-p392@arcsite_mysql/bin/unicorn:19:in `load'
from /home/deployer/.rvm//gems/ruby-1.9.3-p392@arcsite_mysql/bin/unicorn:19:in `<main>'
from /home/deployer/.rvm//gems/ruby-1.9.3-p392@arcsite_mysql/bin/ruby_noexec_wrapper:14:in `eval'
from /home/deployer/.rvm//gems/ruby-1.9.3-p392@arcsite_mysql/bin/ruby_noexec_wrapper:14:in `<main>'
Failed!
# RAILS_ROOT/config/unicorn.rb
# Search for "# SET ME!" and replace these with your own settings!.
# Set environment to development unless something else is specified
env = ENV["RAILS_ENV"] || "development"
RAILS_ROOT = "/home/deployer/apps/arcsite/current"
ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
require 'bundler/setup'
pid "#{RAILS_ROOT}/tmp/pids/unicorn.pid"
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.
worker_processes 10 # SET ME!
# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
listen "/tmp/unicorn.arcsite.sock", :backlog => 1024 # SET ME!
# Preload our app for more speed
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 60
# Production specific settings
if env == "production"
# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
working_directory RAILS_ROOT
# feel free to point this anywhere accessible on the filesystem
user 'deployer', 'sudo'
shared_path = "/home/deployer/apps/arcsite/current"
stderr_path "#{shared_path}/log/unicorn.stderr.log"
stdout_path "#{shared_path}/log/unicorn.stdout.log"
end
before_fork do |server, worker|
# the following is highly recomended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
# Before forking, kill the master process that belongs to the .oldbin PID.
# This enables 0 downtime deploys.
old_pid = "#{RAILS_ROOT}/tmp/pids/unicorn.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
end
after_fork do |server, worker|
# the following is *required* for Rails + "preload_app true",
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
end
# if preload_app is true, then you may also want to check and
# restart any other shared sockets/descriptors such as Memcached,
# and Redis. TokyoCabinet file handles are safe to reuse
# between any number of forked children (assuming your kernel
# correctly implements pread()/pwrite() system calls)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment