4

I have followed the tutorial here on ow to deploy a Rails App using Capistrano and Puma. I had initially used with a Rails 4 and all worked fine, however I'm now trying with Rails 5 App and is not working. I've made some changes due to changes in Capistrano (I've also upgraded Capistrano) and now I'm stuck as the deployment does not seem to create the sock file while deploying and I get the following error:

*412 connect() to unix:///var/www/apps/myapp/shared/tmp/sockets/myapp-puma.sock failed (2: No such file or directory) while connecting to upstream, client: 172.245.92.157, server: api.myapp.com, request: "GET / HTTP/1.0", upstream: "http://unix:///var/www/apps/myapp/shared/tmp/sockets/myapp-puma.sock:/", host: "roboarticle.com"

Here's my Capfile:

# Load DSL and set up stages
require 'capistrano/setup'
require 'capistrano/deploy'
# Include default deployment tasks

# require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/puma'
install_plugin Capistrano::Puma
require 'capistrano/secrets_yml'
require 'capistrano/sidekiq'
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

Here's my deploy.rb:

    # config valid only for current version of Capistrano
lock '3.8.0'

set :application, 'myapp'
# set :repo_url, 'git@example.com:me/my_repo.git'
# Change these
# server '178.62.117.38', roles: [:web, :app, :db], primary: true

set :repo_url,        'git@gitlab.com:WagnerMatos/myapp.git'
set :application,     'myapp'
set :user,            'deployer'
set :puma_threads,    [4, 16]
set :puma_workers,    0

# Don't change these unless you know what you're doing
set :pty,             false
set :use_sudo,        false
set :deploy_to,       "/var/www/apps/#{fetch(:application)}"
set :puma_bind,       "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log,  "#{release_path}/log/puma.access.log"
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, false  # Change to false when not using ActiveRecord
set :linked_dirs,  %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}

namespace :puma do
  desc 'Create Directories for Puma Pids and Socket'
  task :make_dirs do
    on roles(:app) do
      execute "mkdir #{shared_path}/tmp/sockets -p"
      execute "mkdir #{shared_path}/tmp/pids -p"
    end
  end

  before :start, :make_dirs
end

namespace :deploy do

  desc "Make sure local git is in sync with remote."
  task :check_revision do
    on roles(:app) do
      unless `git rev-parse HEAD` == `git rev-parse origin/staging`
        puts "WARNING: HEAD is not the same as origin/staging"
        puts "Run `git push` to sync changes."
        exit
      end
    end
  end

  desc "reload the database with seed data"
  task :seed do
    puts "\n=== Seeding Database ===\n"
     on primary :db do
      within current_path do
        with rails_env: fetch(:stage) do
          execute :rake, 'db:seed'
        end
      end
     end
  end

  desc 'Initial Deploy'
  task :initial do
    on roles(:app) do
      before 'deploy:restart', 'puma:start'
      invoke 'deploy'
    end
  end

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      invoke 'puma:restart'
      # execute :bundle, 'exec cap production setup'
    end
  end

  after 'deploy:starting', 'sidekiq:quiet'
  after 'deploy:reverted', 'sidekiq:restart'
  after 'deploy:published', 'sidekiq:restart'
  # before :starting,     :check_revision
  # after  :finishing,    :compile_assets
  after  :finishing,    :cleanup
  after  :finishing,    :restart
  # after("deploy:compile_assets", "deploy:build_missing_paperclip_styles")
end

# ps aux | grep puma    # Get puma pid
# kill -s SIGUSR2 pid   # Restart puma
# kill -s SIGTERM pid   # Stop puma

And here's my nguni config file:

        upstream puma {
      server unix:///var/www/apps/myapp/shared/tmp/sockets/myapp-puma.sock;
    }

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
        return 301 https://$host$request_uri;
    }

    server {
      listen 443 default_server deferred;
      server_name api.myapp.io;

        ssl on;

        ssl_certificate /etc/nginx/ssl/api.myapp.io/ssl-bundle.crt;
        ssl_certificate_key /etc/nginx/ssl/api.myapp.io/api.myapp.io.key;
        ssl_prefer_server_ciphers on;

      root /var/www/apps/myapp/current/public;
      access_log /var/www/apps/myapp/current/log/nginx.access.log;
      error_log /var/www/apps/myapp/current/log/nginx.error.log info;

      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://puma;
        proxy_read_timeout 300;
      }

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

Any ideas of what I'm missing here?

WagnerMatosUK
  • 4,309
  • 7
  • 56
  • 95

0 Answers0