2014-07-09 1 views
0

Sinatra 응용 프로그램을 Unicorn으로 서버에 배포하려고합니다. 그러나 unicorn -c path/to/unicorn.rb -E development -D을 실행하려고하면 master failed to start, check stderr log for details 오류가 발생합니다. 다음은 표준 에러 로그 파일입니다 또한Unicorn + Nginx + Sinatra 기반 VPS (마스터 작업자가 실패 함)

FATAL -- : error adding listener addr=../rails/tmp/sockets/unicorn.sock /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/socket_helper.rb:167:in `bind_listen': Don't know how to bind: ../rails/tmp/sockets/unicorn.sock (Argum$ 
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:255:in `listen' 
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:801:in `block in bind_new_listeners!' 
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:801:in `each' 
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:801:in `bind_new_listeners!' 
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:146:in `start' 
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/bin/unicorn:126:in `<top (required)>' 
    from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/unicorn:23:in `load' 
    from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/unicorn:23:in `<main>' 
    from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval' 
    from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>' 

, 나는 내 응용 프로그램 폴더 안에 유니콘의 tmp, 로그인, TMP/PID, TMP/소켓 폴더를 생성하고 다음과 같은 unicorn.conf 및 unicorn.rb을 만들어 :

unicorn.rb

# set path to app that will be used to configure unicorn, 
# note the trailing slash in this example 
@dir = "./" 

worker_processes 2 
working_directory @dir 

timeout 30 

# Specify path to socket unicorn listens to, 
# we will use this in our nginx.conf later 
listen "#{@dir}tmp/sockets/unicorn.sock", :backlog => 64 

# Set process id path 
pid "#{@dir}tmp/pids/unicorn.pid" 

# Set log file paths 
stderr_path "#{@dir}log/unicorn.stderr.log" 
stdout_path "#{@dir}log/unicorn.stdout.log" 

listen "127.0.0.1:8080" 
worker_processes 2 
user "rails" 
working_directory "./" 
pid "/home/unicorn/pids/unicorn.pid" 
stderr_path "/home/unicorn/log/unicorn.log" 
stdout_path "/home/unicorn/log/unicorn.log" 
unicorn.conf

문제는 nginx를 기반으로 할 수 있다고 가정합니다. 그래서 나는 다음과 같은 nginx.conf 편집 :

로그에서 볼 수 있듯이
user www-data; 
worker_processes 4; 
pid /var/run/nginx.pid; 

events { worker_connections 1024; } 

http { 
     sendfile on; 
     tcp_nopush on; 
     tcp_nodelay on; 
     keepalive_timeout 65; 
     types_hash_max_size 2048; 
     server_tokens off; 

     # server_names_hash_bucket_size 64; 
     # server_name_in_redirect off; 

     include /etc/nginx/mime.types; 
     default_type application/octet-stream; 

     access_log /var/log/nginx/access.log; 
     error_log /var/log/nginx/error.log; 

     gzip on; 
     gzip_disable "msie6"; 
     gzip_types text/plain text/xml text/css text/comma-separated-values; 
     upstream app_server { server 127.0.0.1:8080 fail_timeout=0; } 

     include /etc/nginx/conf.d/*.conf; 
     include /etc/nginx/sites-enabled/*; 
     upstream unicorn_server { 
       server unix:/home/rails/tmp/sockets/unicorn.sock 
       fail_timeout=0; 
     } 
} 

이 문제는 unicorn.sock 파일을 기반으로합니다. 그러나 내가 "어떻게 바인딩 해야할지 모르겠다"라는 문제를봤을 때 찾을 수있는 해결책이 없습니다. 조언이 필요합니다. 도와 주셔서 감사합니다.

답변

1

코드 socket_helper.rb (here 참조)에 따르면 unicorn.rb 파일의 소켓 경로 형식에 문제가있을 수 있습니다. bind_listen 방법 전에

코멘트 말 :

# creates a new server, socket. address may be a HOST:PORT or 
# an absolute path to a UNIX socket. address can even be a Socket 
# object in which case it is immediately returned 
def bind_listen(address = '0.0.0.0:8080', opt = {}) 
    ... 
end 

그래서 난 당신이 대신 상대 하나, 당신의 소켓에 대한 절대 경로를 사용해야합니다 같아요.

0

@PA. Buisson은 정확하고 해결책을 찾았습니다. 완전성을 위해 unicorn.rb는 다음과 같이 변경 될 수 있습니다 :

# set path to app that will be used to configure unicorn, 
# note the trailing slash in this example 
@dir = File.expand_path(File.dirname(__FILE__)) 

worker_processes 2 
working_directory @dir 

timeout 30 

# Specify path to socket unicorn listens to, 
# we will use this in our nginx.conf later 
listen File.join(@dir, "tmp/sockets/unicorn.sock"), :backlog => 64 

# Set process id path 
pid File.join(@dir, "tmp/pids/unicorn.pid") 

# Set log file paths 
stderr_path File.join(@dir, "log/unicorn.stderr.log") 
stdout_path File.join(@dir, "log/unicorn.stdout.log") 
관련 문제