2
votes

UPDATE

From @BoraMa's comment - I realized my puma.rb (which was all boilerplate) didn't have the socket location setup properly. However, I'm unsure how to make these match... Does it matter where my sock location is? Can I put it anywhere?

My path from my sites-available file is -

"unix:///home/deploy/apps/mll/shared/tmp/sockets/mll-puma.sock:/"

however, I logged out the app_dir seen below, and I get:

/home/deploy/apps/mll/releases/20160415184544

So I'm unsure how I can get these to match/what I should use, since it looks like it's using my capistrano releases in the puma.rb

My updated puma.rb

# Change to match your CPU core count
workers 1

# Min and Max threads per worker
threads 1, 6

app_dir = File.expand_path("../..", __FILE__)
puts "App dir: #{app_dir}"
# App dir: /home/deploy/apps/mll/releases/20160415184544
shared_dir = "#{app_dir}"

# Default to production
rails_env = ENV['RAILS_ENV'] || "production"
environment rails_env

# Set up socket location
# bind "unix://#{shared_dir}/sockets/puma.sock"
bind "unix://#{shared_dir}/tmp/sockets/mll-puma.sock"

# Logging
stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true

# Set master PID and state locations
pidfile "#{shared_dir}/pids/puma.pid"
state_path "#{shared_dir}/pids/puma.state"
activate_control_app

on_worker_boot do
  require "active_record"
  ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
  ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
end

Note - I was originally following: https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma

Original Post

I'm trying to run Puma via Capistrano/Capistrano gem on Nginx for a rails app.

After running cap production deploy:initialand loading my browser, I get An unhandled lowlevel error occurred. The application logs may have details.

I'm not very familiar with Puma/Sockets/Permissions.

My log shows:

[crit] 27411#0: *2 connect() to unix:///home/deploy/apps/mll/shared/tmp/sockets/mll-puma.sock failed (13: Permission denied) while connecting to upstream, 

client: my_ip_address, 
server: mysite.com, 
request: "GET / HTTP/1.1", 
upstream: "http://unix:///home/deploy/apps/mll/shared/tmp/sockets/mll-puma.sock:/", 
host: "centers.m$

/etc/nginx/sites-available/centers -

upstream mll-puma {
  server unix:///home/deploy/apps/mll/shared/tmp/sockets/mll-puma.sock;
}

server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;

  root /home/deploy/apps/mll/current/public;
  access_log /home/deploy/apps/mll/current/log/nginx.access.log;
  error_log /home/deploy/apps/mll/current/log/nginx.error.log info;

  server_name centers.mrs-lodges-library.com;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://mll-puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

puma.rb, pretty much boilerplate, didn't change any settings

# Change to match your CPU core count
workers 1

# Min and Max threads per worker
threads 1, 6

app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"

# Default to production
rails_env = ENV['RAILS_ENV'] || "production"
environment rails_env

# Set up socket location
bind "unix://#{shared_dir}/sockets/puma.sock"

# Logging
stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true

# Set master PID and state locations
pidfile "#{shared_dir}/pids/puma.pid"
state_path "#{shared_dir}/pids/puma.state"
activate_control_app

on_worker_boot do
  require "active_record"
  ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
  ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
end

/etc/nginx/nginx.conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
  worker_connections 768;
  # multi_accept on;
}

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

  server_names_hash_bucket_size 64;


  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";

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;

Permissions:

namei -l /var/www/centers/

drwxr-xr-x root root /
drwxr-xr-x root root var
drwxr-xr-x root root www
drwxrwxr-x root root centers

namei -l /home/deploy/apps/mll/current/public/

drwxr-xr-x root   root   /
drwxr-xr-x root   root   home
drwxr-xr-x deploy deploy deploy
drwxr-xr-x deploy deploy apps
drwxr-xr-x deploy deploy mll
lrwxrwxrwx deploy deploy current -> /home/deploy/apps/mll/releases/20160415164906
drwxr-xr-x root   root     /
drwxr-xr-x root   root     home
drwxr-xr-x deploy deploy   deploy
drwxr-xr-x deploy deploy   apps
drwxr-xr-x deploy deploy   mll
drwxr-xr-x deploy deploy   releases
drwxrwxr-x deploy deploy   20160415164906
drwxrwxr-x deploy deploy public
deploy@banana:/etc/nginx$

Sockets -

$ ls -l

drwxr-xr-x 2 deploy deploy 4096 Apr 14 18:22 pids
drwxr-xr-x 2 deploy deploy 4096 Apr 14 18:22 sockets

$ ls -l

srwxrwxrwx 1 deploy deploy 0 Apr 14 18:22 mll-puma.sock
1

1 Answers

1
votes

I think that in your puma.rb and nginx site configuration files you should point puma / nginx to the same socket. Right now there are different paths.