Capistrano + puma + nginx:Capistrano puma 未创建 puma-sockets 和 puma ids

问题描述 投票:0回答:1

使用 Capistrano 部署后不会创建 Puma 套接字和 pid。我有 ruby 2.4.0 的 Rails 5.1.2 应用程序。出现以下错误:

unix:///home/deploy/affiliate-staging/shared/tmp/sockets/affiliate-staging-puma.sock failed (2: No such file or directory) while connecting to upstream, client: client_id

cap staging deploy:initial
成功完成。已经用谷歌搜索并关注了许多链接和答案,但没有任何效果。如下是deploy.rb和其他文件。

config/deploy.rb

# config valid for current version and patch releases of Capistrano
lock "~> 3.11.0"

# Change these
server 'my_iP-address', roles: [:web, :app, :db], primary: true

set :repo_url,        '[email protected]'
set :user,            'deploy'
set :puma_threads,    [4, 16]
set :puma_workers,    0

# Don't change these unless you know what you're doing
set :pty,             true
set :use_sudo,        false
set :deploy_via,      :remote_cache
set :deploy_to,       "/home/deploy/#{fetch(:application)}"
set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"
set :puma_bind,       "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log,  "#{release_path}/log/puma.access.log"
set :ssh_options,     { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true  # Change to false when not using ActiveRecord

## Defaults:
# set :scm,           :git
# set :branch,        :master
# set :format,        :pretty
# set :log_level,     :debug
set :keep_releases, 5

## Linked Files & Directories (Default None):
set :bundle_binstubs, nil
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.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
      if fetch(:stage) == (:staging || 'staging')
        if `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
      elsif `git rev-parse HEAD` != `git rev-parse origin/master`
        puts "WARNING: HEAD is not the same as origin/master"
        puts "Run `git push` to sync changes."
        exit
      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')
    end
  end

  before :starting,     :check_revision
  after  :finishing,    :compile_assets
  after  :finishing,    :cleanup
  after  :finishing,    :restart
end

config/deploy/staging.rb 中设置分支、应用程序和阶段

set :application, 'affiliate-staging'
set :deploy_to,    "/home/deploy/#{fetch(:application)}"
set :stage,        :staging
set :rails_env,    :staging
set :branch,       :staging

config/nginx.conf

upstream puma {
#using same puma socket name which I am sertting up in staging.rb
server unix:///home/deploy/affiliate-staging/shared/tmp/sockets/affiliate-staging-puma.sock;
}

server {
  listen 80 default_server deferred;
  # server_name example.com;

  root /home/deploy/affiliate-staging/current/public;
  access_log /home/deploy/affiliate-staging/current/log/nginx.access.log;
  error_log /home/deploy/affiliate-staging/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;
  }

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

如您所见,应该有 pid 和

affiliate-saintlbeau-puma.sock
但它没有创建。我收到此错误:

unix:///home/deploy/affiliate-staging/shared/tmp/sockets/affiliate-staging-puma.sock failed (2: No such file or directory) while connecting to upstream, client: client_id

共享/puma.rb

#!/usr/bin/env puma

directory '/home/deploy/affiliate-staging/current'
rackup "/home/deploy/affiliate-staging/current/config.ru"
environment 'staging'

tag ''

pidfile "/home/deploy/shared/tmp/pids/puma.pid"
state_path "/home/deploy/shared/tmp/pids/puma.state"
stdout_redirect '/home/deploy/current/log/puma.error.log', '/home/deploy/current/log/puma.access.log', true


threads 4,16



bind 'unix:///home/deploy/shared/tmp/sockets/puma.sock'

workers 0

preload_app!


on_restart do
  puts 'Refreshing Gemfile'
  ENV["BUNDLE_GEMFILE"] = ""
end


before_fork do
  ActiveRecord::Base.connection_pool.disconnect!
end

on_worker_boot do
  ActiveSupport.on_load(:active_record) do
    ActiveRecord::Base.establish_connection
  end
end

我无法理解我在这里缺少什么。我希望我没有把问题搞砸。

ruby-on-rails nginx capistrano digital-ocean puma
1个回答
0
投票

我的 capistrano 3 也有同样的问题

© www.soinside.com 2019 - 2024. All rights reserved.