Ruby on rails Unicorn/Nginx/Capistrano部署(服务器未启动)

Ruby on rails Unicorn/Nginx/Capistrano部署(服务器未启动),ruby-on-rails,nginx,capistrano,unicorn,Ruby On Rails,Nginx,Capistrano,Unicorn,我一直在拼命想弄明白这一点,我完全被卡住了。我正在尝试部署一个处理域重定向的应用程序。它沿着我们的主web应用程序运行,并有一个表,用于将用户从一个域重定向到另一个域。这是一个复杂的系统,但我不是最初的开发人员,所以它有点落在我的膝上。它正在我们当前的生产服务器上运行,但我们正在转移到另一个。我正在使用Capistrano将整个应用程序从开发服务器移动到新的生产服务器。我们的应用程序的主web端已手动移动,似乎运行正常,但他们在移动其他所有内容时没有复制此web应用程序,因此现在我需要使用Cap

我一直在拼命想弄明白这一点,我完全被卡住了。我正在尝试部署一个处理域重定向的应用程序。它沿着我们的主web应用程序运行,并有一个表,用于将用户从一个域重定向到另一个域。这是一个复杂的系统,但我不是最初的开发人员,所以它有点落在我的膝上。它正在我们当前的生产服务器上运行,但我们正在转移到另一个。我正在使用Capistrano将整个应用程序从开发服务器移动到新的生产服务器。我们的应用程序的主web端已手动移动,似乎运行正常,但他们在移动其他所有内容时没有复制此web应用程序,因此现在我需要使用Capistrano部署此应用程序

在执行Cap部署生产时,我遇到以下错误:

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
如果我跑

unicorn
在apps/current中,unicorn服务器启动,但我必须访问domain.com:8080才能使其工作并重定向。。。我真的不知道还能做什么,我肯定我错过了一些愚蠢的事情,但我看不见。我想nginx可能有问题,但我什么都没看到

Deploy.rb

set :stages, %w(staging production)¬

set :default_stage, 'production'¬
require 'capistrano/ext/multistage'¬
¬
set :application, "app"¬
set :repository, "git@github.com: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;
  }
}
独角兽

# 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

**kill:用法:kill[-s sigspec |-n signum |-sigspec]pid | jobspec。。。或者杀死-l[sigspec]
**[输出:127.0.0.1]
看起来像是
kill
命令不起作用