I've been beating my head against a wall trying to figure this out and I'm completely stuck. I'm trying to deploy an app that handles domain redirects. It runs along side our main web app and has a table that redirects users from one domain to another. Its a convoluted system but I'm not the original developer so it kinda got dropped in my lap. It is running on our current production server but we are moving to another. I'm using Capistrano to move the whole app from our development server to our new production server. The main web side of our app has been moved manually and seems to be functioning correctly but they didn't copy this web app when they moved everything else so now I need to use Capistrano to deploy this app.
When I do a Cap deploy production I am getting this error:
2016-02-26 15:40:07 executing `deploy:restart'
triggering after callbacks for `deploy:restart'
* 2016-02-26 15:40:07 executing `unicorn:reload'
* executing "sleep 3; kill -s USR2 `cat /u/apps/app/shared/pids/unicorn.pid`"
servers: ["127.0.0.1"]
[127.0.0.1] executing command
** [out :: 127.0.0.1] kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
** [out :: 127.0.0.1]
command finished in 3294ms
failed: "rvm_path=$HOME/.rvm $HOME/.rvm/bin/rvm-shell '1.9.3@app' -c 'sleep 3; kill -s USR2 `cat /u/apps/app/shared/pids/unicorn.pid`'" on 127.0.0.1
If I run
unicorn
in the apps /current the unicorn server starts up but I have to go to domain.com:8080 to get it to work and redirect... I really don't know what else to do, I'm certain its something stupid that I'm missing but I can't see it. I think that maybe there is an issue with nginx but I'm not seeing anything.
Deploy.rb
set :stages, %w(staging production)¬
set :default_stage, 'production'¬
require 'capistrano/ext/multistage'¬
¬
set :application, "app"¬
set :repository, "[email protected]:app"¬
set :scm, :git¬
set :branch, 'master'¬
ssh_options[:forward_agent] = true¬
set :deploy_via, :remote_cache¬
set :ssh_options, { :forward_agent => true}¬
default_run_options[:pty] = true¬
¬
# RVM Setup¬
gem 'sass-rails', '= 3.2.6'¬
#$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.¬
require "bundler/capistrano"¬
require "rvm/capistrano"▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ▸ ⋅¬
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"")¬
set :rvm_ruby_string, '1.9.3@app'¬
set :rvm_type, :user¬
before 'deploy', 'rvm:install_rvm' #install rvm on target¬
before 'deploy', 'rvm:install_ruby' #install ruby on target¬
before 'deploy:setup', 'rvm:install_rvm'¬
before 'deploy:setup', 'rvm:install_ruby'¬
¬
⋅⋅⋅⋅¬
# Unicorn tasks from: http://blog.teachstreet.com/building-teachstreet/how-i-learned-to-stop-worrying-and-love-the-unicorn/¬
set :unicorn_pid, "#{shared_path}/pids/unicorn.pid"¬
namespace :unicorn do¬
desc "start unicorn"¬
task :start, :roles => :app, :except => { :no_release => true } do¬
run "cd #{current_path} && bundle exec unicorn -c #{current_path}/config/unicorn-#{rails_env}.rb -E #{rails_env} -D"¬
end¬
desc "stop unicorn"¬
task :stop, :roles => :app, :except => { :no_release => true } do¬
run " kill `cat #{unicorn_pid}`"¬
end¬
desc "graceful stop unicorn"¬
task :graceful_stop, :roles => :app, :except => { :no_release => true } do¬
run " kill -s QUIT `cat #{unicorn_pid}`"¬
end¬
desc "reload unicorn"¬
task :reload, :roles => :app, :except => { :no_release => true } do¬
run " sleep 3; kill -s USR2 `cat #{unicorn_pid}`"¬
end¬
⋅¬
after "deploy:restart", "unicorn:reload"¬
end¬
¬
#namespace :rvm do¬
# task :trust_rvmrc do¬
# run "
rvm rvmrc trust #{release_path}"¬
# end¬
#▸after "deploy", "rvm:trust_rvmrc"¬
#end¬
nginx.conf
upstream unicorn {
server unix:/u/apps/app/shared/unicorn.sock fail_timeout=0;
}
server {
listen 80;
# http://nginx.org/en/docs/http/server_names.html
# A special wildcard in the form “.nginx.org” can be used to match both the exact name “nginx.org” and the wildcard name “*.nginx.org”.
server_name .domain.com;
client_max_body_size 4G;
# ~2 seconds is often enough for most folks to parse HTML/CSS and
# retrieve needed images/icons/frames, connections are cheap in
# nginx so increasing this is generally safe...
keepalive_timeout 5;
# path for static files
root /u/apps/app/current/public;
# Prefer to serve static files directly from nginx to avoid unnecessary
# data copies from the application server.
#
# try_files directive appeared in in nginx 0.7.27 and has stabilized
# over time. Older versions of nginx (e.g. 0.6.x) requires
# "if (!-f $request_filename)" which was less efficient:
# http://bogomips.org/unicorn.git/tree/examples/nginx.conf?id=v3.3.1#n127
try_files $uri/index.html $uri.html $uri @app;
location @app {
# an HTTP header important enough to have its own Wikipedia entry:
# http://en.wikipedia.org/wiki/X-Forwarded-For
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# enable this if and only if you use HTTPS, this helps Rack
# set the proper protocol for doing redirects:
# proxy_set_header X-Forwarded-Proto https;
# pass the Host: header from the client right along so redirects
# can be set properly within the Rack application
proxy_set_header Host $http_host;
# we don't want nginx trying to do something clever with
# redirects, we set the Host: header above already.
proxy_redirect off;
# set "proxy_buffering off" *only* for Rainbows! when doing
# Comet/long-poll/streaming. It's also safe to set if you're using
# only serving fast clients with Unicorn + nginx, but not slow
# clients. You normally want nginx to buffer responses to slow
# clients, even with Rails 3.1 streaming because otherwise a slow
# client can become a bottleneck of Unicorn.
#
# The Rack application may also set "X-Accel-Buffering (yes|no)"
# in the response headers do disable/enable buffering on a
# per-response basis.
# proxy_buffering off;
proxy_pass http://unicorn;
}
# Rails error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
root /u/apps/app/current/public;
}
}
Unicorn.rb
# http://blog.teachstreet.com/building-teachstreet/how-i-learned-to-stop-worrying-and-love-the-unicorn/
worker_processes 6
preload_app true
timeout 180
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
# Use RVM
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! APP_ROOT
rescue LoadError
raise "RVM ruby lib is currently unavailable."
end
end
# Use Bundler
ENV['BUNDLE_GEMFILE'] = File.join(APP_ROOT, 'Gemfile')
puts "BUNDLER_GEMFILE=#{ENV['BUNDLE_GEMFILE']}"
require 'bundler/setup'
# Setup directories
working_directory APP_ROOT
listen "/u/apps/app/shared/unicorn.sock", :backlog => 64
#pid APP_ROOT + "/tmp/pids/unicorn.pid"
pid "/u/apps/app/shared/pids/unicorn.pid"
stderr_path APP_ROOT + "/log/unicorn.stderr.log"
stdout_path APP_ROOT + "/log/unicorn.stdout.log"
after_fork do |server, worker|
ActiveRecord::Base.establish_connection
end
before_fork do |server, worker|
ActiveRecord::Base.connection.disconnect!
#old_pid = RAILS_ROOT + '/tmp/pids/unicorn.pid.oldbin'
old_pid = '/u/apps/app/shared/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