编程语言
首页 > 编程语言> > ruby-on-rails-4 – 没有这样的文件或目录 – connect(2)for“/ tmp / puma-status-1439451994589-14316”

ruby-on-rails-4 – 没有这样的文件或目录 – connect(2)for“/ tmp / puma-status-1439451994589-14316”

作者:互联网

我想通过Capistrano与Puma和Nginx部署我的rails.我已经为puma配置了deploy.rb,并在gem文件中添加了必需的gem.

我可以将初始部署命令作为“cap production deploy:initial”运行,并且能够访问我的rails应用程序,如下所述.

但是,当我想部署一些新的更改或重新启动puma时,它会失败并发出此错误.

的Gemfile:

gem 'capistrano', '~> 3.4.0'
gem 'capistrano-rvm',     require: false
gem 'capistrano-rails',   require: false
gem 'capistrano-bundler', require: false
gem 'capistrano3-puma',   require: false
# gem 'capistrano-passenger',   require: false
gem 'capistrano-ext',     require: false
gem 'capistrano-faster-assets', '~> 1.0.2'

Capfile:

# Load DSL and set up stages
require 'capistrano/setup'

# Include default deployment tasks
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/faster_assets'

require 'capistrano/rvm'
require 'capistrano/puma'
require 'capistrano/puma/workers'
require 'capistrano/puma/nginx'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

deploy.rb

# Puma Server Configuration
set :puma_threads,    [4, 16]
set :puma_workers,    1

# Don't change these unless you know what you're doing
set :pty,             true
set :use_sudo,        false
set :puma_bind,       "unix://#{shared_path}/tmp/sockets/puma.sock"
# set :puma_conf,       "#{shared_path}/puma.rb"
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, true

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/capistrano`
        puts "WARNING: HEAD is not the same as origin/capistrano"
        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

我还使用下面的命令为Puma和Nginx生成模板,如下所示.

rails g capistrano:nginx_puma:config

我运行以下命令将我的rails部署到EC2实例(使用Ubuntu)

cap production deploy:check
cap production puma:config
cap production puma:nginx_config
cap production deploy:initial

现在,我想用下面的代码部署一些更改.

cap production deploy

但我得到的错误如下.

(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ubuntu@54.175.134.149: bundle exit status: 1
bundle stdout: No such file or directory - connect(2) for "/tmp/puma-status-1439451994589-14316"
bundle stderr: Nothing written

SSHKit::Command::Failed: bundle exit status: 1
bundle stdout: No such file or directory - connect(2) for "/tmp/puma-status-1439451994589-14316"
bundle stderr: Nothing written

Tasks: TOP => deploy:restart
(See full trace by running task with --trace)

请帮忙!
谢谢

解决方法:

我找到了解决此问题的一种解决方法.
只需将下面的代码段添加到deploy.rb文件即可.
它会覆盖puma重启任务.

Rake::Task["puma:restart"].clear_actions

namespace :puma do
  task :restart do
    on roles(:all) do
      execute "RACK_ENV=#{fetch(:rails_env)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do pumactl -S #{shared_path}/tmp/pids/puma.state restart"
    end
  end
end

标签:nginx,ruby-on-rails-4,deployment,puma,capistrano3
来源: https://codeday.me/bug/20190711/1433940.html