VPS ที่ใช้ Unicorn+Nginx+Sinatra พร้อมด้วยผู้ปฏิบัติงานหลักล้มเหลว

ฉันกำลังพยายามปรับใช้แอปพลิเคชัน Sinatra กับเซิร์ฟเวอร์ของฉันด้วย Unicorn อย่างไรก็ตาม เมื่อฉันพยายามเรียกใช้ unicorn -c path/to/unicorn.rb -E development -D ฉันได้รับข้อผิดพลาด master failed to start, check stderr log for details นี่คือไฟล์บันทึก stderr:

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,log,tmp/pid,tmp/sockets ภายในโฟลเดอร์แอปพลิเคชันของฉัน และสร้างยูนิคอร์น.conf และยูนิคอร์น.rb ดังต่อไปนี้:

ยูนิคอร์น.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"

ฉันคิดว่าปัญหาอาจขึ้นอยู่กับ 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 อย่างไรก็ตามเมื่อฉันค้นหาปัญหาเกี่ยวกับ "ไม่ทราบวิธีผูก" ก็ไม่มีวิธีแก้ไขที่ฉันสามารถพบได้ ต้องการคำแนะนำ ขอบคุณที่ช่วยเหลือ.


person Tugkan    schedule 09.07.2014    source แหล่งที่มา


คำตอบ (2)


ตามโค้ดของ socket_helper.rb (ดูที่นี่) อาจเป็นปัญหากับรูปแบบเส้นทางซ็อกเก็ตในไฟล์ 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

ดังนั้นฉันเดาว่าคุณ ต้อง ใช้เส้นทางที่แน่นอนสำหรับซ็อกเก็ตของคุณ แทนที่จะเป็นเส้นทางสัมพัทธ์

person Pierre-Adrien    schedule 10.07.2014

@ป้า. Buisson ถูกต้อง และนำฉันไปสู่วิธีแก้ปัญหา เพื่อความสมบูรณ์ คุณสามารถเปลี่ยนยูนิคอร์น.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")
person TomDunning    schedule 23.11.2015