Unicorn / Nginx / Capistrano部署(服务器不启动)

时间:2016-02-26 23:13:59

标签: ruby-on-rails nginx capistrano unicorn

我一直在撞墙试图解决这个问题而且我完全卡住了。我正在尝试部署处理域重定向的应用程序。它与我们的主要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;
  }
}

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

1 个答案:

答案 0 :(得分:0)

** [out :: 127.0.0.1] kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec] ** [out :: 127.0.0.1] 看起来kill命令无法正常工作。