使用Capistrano部署Puma时不会创建套接字文件

时间:2017-04-19 06:50:10

标签: ruby-on-rails nginx capistrano3 puma

我已按照教程here使用Capistrano和Puma部署Rails应用程序。我最初使用的是Rails 4并且一切正常,但我现在正在尝试使用Rails 5 App并且无法正常工作。由于Capistrano的更改(我还升级了Capistrano),我做了一些更改,现在我陷入困境,因为部署似乎没有在部署时创建sock文件,我收到以下错误:

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

这是我的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 }

这是我的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

这是我的nguni配置文件:

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

我在这里缺少什么想法?

0 个答案:

没有答案