Puma每隔一秒钟重新启动一次

时间:2019-04-06 14:08:06

标签: ruby-on-rails capistrano digital-ocean puma

Deploying a Rails App on Ubuntu 14.04 with Capistrano, Nginx, and Puma之后,我对Ubuntu 18.0.4进行了一些小的更改,但配置文件相同。

现在,当我重新部署时使用

cap production deploy

第一次结束日志是这样的

01:38 deploy:cleanup
      Keeping 5 of 6 deployed releases on 157.230.160.164
      01 rm -rf /home/deploy/apps/ezlarm-server/releases/20190406115244
    ✔ 01 deploy@157.230.160.164 1.543s
01:48 puma:restart
      01 ~/.rvm/bin/rvm default do bundle exec pumactl -S /home/deploy/apps/ezlarm-server/shared/tmp/pids/puma.state -F /home/deploy/apps/ezla…
      01 Command restart sent success
    ✔ 01 deploy@157.230.160.164 2.206s
01:52 deploy:log_revision
      01 echo "Branch master (at 0a06a0f61268848284c00bbbd47ee038f8daf2bf) deployed as release 20190406123158 by faisal-nfl" >> /home/deploy/a…
    ✔ 01 deploy@157.230.160.164 1.118s
Skipping task `puma:restart'.

当我访问服务器时崩溃

结束日志是这样的

01:21 deploy:cleanup
      Keeping 5 of 6 deployed releases on 157.230.160.164
      01 rm -rf /home/deploy/apps/ezlarm-server/releases/20190406115458
    ✔ 01 deploy@157.230.160.164 1.069s
01:28 puma:make_dirs
      01 mkdir /home/deploy/apps/ezlarm-server/shared/tmp/sockets -p
    ✔ 01 deploy@157.230.160.164 1.192s
      02 mkdir /home/deploy/apps/ezlarm-server/shared/tmp/pids -p
    ✔ 02 deploy@157.230.160.164 1.188s
01:34 puma:start
      using conf file /home/deploy/apps/ezlarm-server/shared/puma.rb
      01 ~/.rvm/bin/rvm default do bundle exec puma -C /home/deploy/apps/ezlarm-server/shared/puma.rb --daemon
      01 Puma starting in single mode...
      01 * Version 3.12.1 (ruby 2.6.0-p0), codename: Llamas in Pajamas
      01 * Min threads: 4, max threads: 16
      01 * Environment: production
      01 * Daemonizing...
    ✔ 01 deploy@157.230.160.164 2.544s
01:40 deploy:log_revision
      01 echo "Branch master (at 0a06a0f61268848284c00bbbd47ee038f8daf2bf) deployed as release 20190406123406 by faisal-nfl" >> /home/deploy/a…
    ✔ 01 deploy@157.230.160.164 1.039s
Skipping task `puma:restart'.

一切开始正常。

每一次部署都会发生这种情况,例如一次失败然后第二次起作用

我的deploy.rb文件是这样的

# Change these
server 'my_ip', port: 22, roles: [:web, :app, :db], primary: true

set :repo_url,        'git@github.com:my_app'
set :application,     'ezlarm-server'
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 :stage,           :production
set :deploy_via,      :remote_cache
set :deploy_to,       "/home/#{fetch(:user)}/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 :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 :linked_files, %w{config/database.yml}
# set :linked_dirs,  %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
set :bundle_binstubs, nil

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/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

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

我不知道为什么每次失败后它都起作用。

0 个答案:

没有答案