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>'

Кроме того, я создал папки unicorn tmp,log,tmp/pid,tmp/sockets внутри папки моего приложения и создал 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"

unicorn.conf

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

@ПА. Буиссон прав и привел меня к решению. Для полноты 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")
person TomDunning    schedule 23.11.2015