Rails 5& Capistrano 3 - Sidekiq退出状态1

时间:2017-12-04 13:39:07

标签: ruby-on-rails ruby capistrano sidekiq

经过大量的研究,我来到这里揭露我正在努力解决的问题:一个状态为1的sidekiq停止。

  • Ruby 2.4.2p198(2017-09-14修订版59899)[x86_64-linux]
  • capistrano 3

我推出了另一个带有sidekiq的应用程序:

root      4422  3.6 10.7 1760440 657788 ?      Sl   13:32   2:03 sidekiq 4.2.10 sergicapi-sync [0 of 5 busy]
root     27996  0.0  0.0  12748  2200 pts/0    R+   14:29   0:00 grep sidekiq

shared_pa​​th / tmp / pids / sidekiq.pid显示一个数字:12783

我很绝望,我从2天开始尝试了一切......你有什么想法吗?

提前交配很多人。

我的错误:

00:00 deploy:create_shared_folders
      01 mkdir /var/www/sergicapi-sync-staging/shared/sockets -p
    ✔ 01 root@192.168.100.18 0.094s
      02 mkdir /var/www/sergicapi-sync-staging/shared/tmp -p
    ✔ 02 root@192.168.100.18 0.096s
      03 mkdir /var/www/sergicapi-sync-staging/shared/tmp/pids -p
    ✔ 03 root@192.168.100.18 0.096s
      04 mkdir /var/www/sergicapi-sync-staging/shared/log -p
    ✔ 04 root@192.168.100.18 0.097s
      05 touch /var/www/sergicapi-sync-staging/shared/sockets/puma.sock
    ✔ 05 root@192.168.100.18 0.107s
      06 touch /var/www/sergicapi-sync-staging/shared/sockets/pumactl.sock
    ✔ 06 root@192.168.100.18 0.092s
      07 touch /var/www/sergicapi-sync-staging/shared/tmp/pids/puma.state
    ✔ 07 root@192.168.100.18 0.098s
      08 touch /var/www/sergicapi-sync-staging/shared/log/sidekiq.log
    ✔ 08 root@192.168.100.18 0.092s
      09 touch /var/www/sergicapi-sync-staging/shared/log/puma_access.log
    ✔ 09 root@192.168.100.18 0.093s
      10 touch /var/www/sergicapi-sync-staging/shared/log/puma_error.log
    ✔ 10 root@192.168.100.18 0.095s
00:00 git:wrapper
      01 mkdir -p /tmp/sergicapi-sync-staging
    ✔ 01 root@192.168.100.18 0.096s
      Uploading /tmp/sergicapi-sync-staging/git-ssh-sergicapi-sync-staging-staging-thibaut.sh 100.0%
      02 chmod 700 /tmp/sergicapi-sync-staging/git-ssh-sergicapi-sync-staging-staging-thibaut.sh
    ✔ 02 root@192.168.100.18 0.100s
00:01 git:check
      01 git ls-remote git@xxxxxxxxxxxxxxxxxxxxxxxxxxxx <- I hided this don't worry HEAD
      01 4e84a2cb534a752ed696caecfab54e9d1ef467cd   HEAD
    ✔ 01 root@192.168.100.18 1.670s
00:02 deploy:check:directories
      01 mkdir -p /var/www/sergicapi-sync-staging/shared /var/www/sergicapi-sync-staging/releases
    ✔ 01 root@192.168.100.18 0.094s
00:03 deploy:check:linked_dirs
      01 mkdir -p /var/www/sergicapi-sync-staging/shared/config /var/www/sergicapi-sync-staging/shared/tmp/pids /var/www/sergicapi-sync-staging/shared/tmp/sockets
    ✔ 01 root@192.168.100.18 0.094s
00:03 deploy:check:make_linked_dirs
      01 mkdir -p /var/www/sergicapi-sync-staging/shared/config
    ✔ 01 root@192.168.100.18 0.096s
00:04 git:clone
      The repository mirror is at /var/www/sergicapi-sync-staging/repo
00:04 git:update
      01 git remote set-url origin git@xxxxxxxxxxxxxxxxxxxxxxxxxxxx <- I hided this don't worry
    ✔ 01 root@192.168.100.18 0.097s
      02 git remote update --prune
      02 Récupération de origin
    ✔ 02 root@192.168.100.18 1.534s
00:05 git:create_release
      01 mkdir -p /var/www/sergicapi-sync-staging/releases/20171130133621
    ✔ 01 root@192.168.100.18 0.092s
      02 git archive feature/capistratio | /usr/bin/env tar -x -f - -C /var/www/sergicapi-sync-staging/releases/20171130133621
    ✔ 02 root@192.168.100.18 0.109s
00:06 deploy:set_current_revision
      01 echo "0f6781e20cd236f21c1a5aad060cd017136777ef" >> REVISION
    ✔ 01 root@192.168.100.18 0.097s
00:06 deploy:symlink:linked_files
      01 mkdir -p /var/www/sergicapi-sync-staging/releases/20171130133621/config
    ✔ 01 root@192.168.100.18 0.094s
      02 rm /var/www/sergicapi-sync-staging/releases/20171130133621/config/sidekiq.yml
    ✔ 02 root@192.168.100.18 0.093s
      03 ln -s /var/www/sergicapi-sync-staging/shared/config/sidekiq.yml /var/www/sergicapi-sync-staging/releases/20171130133621/config/sidekiq.yml
    ✔ 03 root@192.168.100.18 0.097s
00:06 deploy:symlink:linked_dirs
      01 mkdir -p /var/www/sergicapi-sync-staging/releases/20171130133621 /var/www/sergicapi-sync-staging/releases/20171130133621/tmp
    ✔ 01 root@192.168.100.18 0.094s
      02 rm -rf /var/www/sergicapi-sync-staging/releases/20171130133621/config
    ✔ 02 root@192.168.100.18 0.097s
      03 ln -s /var/www/sergicapi-sync-staging/shared/config /var/www/sergicapi-sync-staging/releases/20171130133621/config
    ✔ 03 root@192.168.100.18 0.095s
      04 ln -s /var/www/sergicapi-sync-staging/shared/tmp/pids /var/www/sergicapi-sync-staging/releases/20171130133621/tmp/pids
    ✔ 04 root@192.168.100.18 0.093s
      05 ln -s /var/www/sergicapi-sync-staging/shared/tmp/sockets /var/www/sergicapi-sync-staging/releases/20171130133621/tmp/sockets
    ✔ 05 root@192.168.100.18 0.093s
00:08 bundler:install
      01 RBENV_ROOT=$HOME/.rbenv RBENV_VERSION=2.4.2 $HOME/.rbenv/bin/rbenv exec bundle install --gemfile /var/www/sergicapi-sync-staging/releases/20171130133621/Gemfile --path /var/www/sergicapi-sync-staging/sh…
    ✔ 01 root@192.168.100.18 0.578s
00:09 deploy:symlink:release
      01 ln -s /var/www/sergicapi-sync-staging/releases/20171130133621 /var/www/sergicapi-sync-staging/releases/current
    ✔ 01 root@192.168.100.18 0.095s
      02 mv /var/www/sergicapi-sync-staging/releases/current /var/www/sergicapi-sync-staging
    ✔ 02 root@192.168.100.18 0.093s
00:09 sidekiq:start
      01 bundle exec sidekiq --index 0 --pidfile /var/www/sergicapi-sync-staging/shared/tmp/pids/sidekiq-0.pid --environment staging --logfile /var/www/sergicapi-sync-staging/shared/log/sidekiq.log --daemon
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as root@192.168.100.18: sidekiq exit status: 1
sidekiq stdout: Nothing written
sidekiq stderr: Nothing written

SSHKit::Command::Failed: sidekiq exit status: 1
sidekiq stdout: Nothing written
sidekiq stderr: Nothing written

Tasks: TOP => sidekiq:start
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as root@192.168.100.18: sidekiq exit status: 1
sidekiq stdout: Nothing written
sidekiq stderr: Nothing written


** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:


 DEBUG [65918f5d] Running if test ! -d /var/www/sergicapi-sync-staging/releases/20171130131849; then echo "Directory does not exist '/var/www/sergicapi-sync-staging/releases/20171130131849'" 1>&2; false; fi as root@192.168.100.18

 DEBUG [65918f5d] Command: if test ! -d /var/www/sergicapi-sync-staging/releases/20171130131849; then echo "Directory does not exist '/var/www/sergicapi-sync-staging/releases/20171130131849'" 1>&2; false; fi

 DEBUG [65918f5d] Finished in 0.096 seconds with exit status 0 (successful).

 DEBUG [a7768096] Running /usr/bin/env [ -f /var/www/sergicapi-sync-staging/shared/tmp/pids/sidekiq-0.pid ] as root@192.168.100.18

 DEBUG [a7768096] Command: cd /var/www/sergicapi-sync-staging/releases/20171130131849 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.4.2" ; /usr/bin/env [ -f /var/www/sergicapi-sync-staging/shared/tmp/pids/sidekiq-0.pid ] )

 DEBUG [a7768096] Finished in 0.094 seconds with exit status 0 (successful).

 DEBUG [c00c6d6b] Running /usr/bin/env kill -0 $( cat /var/www/sergicapi-sync-staging/shared/tmp/pids/sidekiq-0.pid ) as root@192.168.100.18

 DEBUG [c00c6d6b] Command: cd /var/www/sergicapi-sync-staging/releases/20171130131849 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.4.2" ; /usr/bin/env kill -0 $( cat /var/www/sergicapi-sync-staging/shared/tmp/pids/sidekiq-0.pid ) )

 DEBUG [c00c6d6b] Finished in 0.100 seconds with exit status 1 (failed).

 DEBUG [5917f809] Running if test ! -d /var/www/sergicapi-sync-staging/releases/20171130131849; then echo "Directory does not exist '/var/www/sergicapi-sync-staging/releases/20171130131849'" 1>&2; false; fi as root@192.168.100.18

 DEBUG [5917f809] Command: if test ! -d /var/www/sergicapi-sync-staging/releases/20171130131849; then echo "Directory does not exist '/var/www/sergicapi-sync-staging/releases/20171130131849'" 1>&2; false; fi

 DEBUG [5917f809] Finished in 0.093 seconds with exit status 0 (successful).

 DEBUG [1dd4d912] Running /usr/bin/env [ -f /var/www/sergicapi-sync-staging/shared/tmp/pids/sidekiq-0.pid ] as root@192.168.100.18

 DEBUG [1dd4d912] Command: cd /var/www/sergicapi-sync-staging/releases/20171130131849 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.4.2" ; /usr/bin/env [ -f /var/www/sergicapi-sync-staging/shared/tmp/pids/sidekiq-0.pid ] )

 DEBUG [1dd4d912] Finished in 0.092 seconds with exit status 0 (successful).

 DEBUG [e1ea26a2] Running /usr/bin/env kill -0 $( cat /var/www/sergicapi-sync-staging/shared/tmp/pids/sidekiq-0.pid ) as root@192.168.100.18

 DEBUG [e1ea26a2] Command: cd /var/www/sergicapi-sync-staging/releases/20171130131849 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.4.2" ; /usr/bin/env kill -0 $( cat /var/www/sergicapi-sync-staging/shared/tmp/pids/sidekiq-0.pid ) )

 DEBUG [e1ea26a2] Finished in 0.095 seconds with exit status 1 (failed).

  INFO [f5755810] Running bundle exec sidekiq --index 0 --pidfile /var/www/sergicapi-sync-staging/shared/tmp/pids/sidekiq-0.pid --environment staging --logfile /var/www/sergicapi-sync-staging/shared/log/sidekiq.log --daemon as root@192.168.100.18

 DEBUG [f5755810] Command: cd /var/www/sergicapi-sync-staging/releases/20171130131849 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.4.2" ; bundle exec sidekiq --index 0 --pidfile /var/www/sergicapi-sync-staging/shared/tmp/pids/sidekiq-0.pid --environment staging --logfile /var/www/sergicapi-sync-staging/shared/log/sidekiq.log --daemon )

这些是我的档案:

Gemfile:

source 'https://rubygems.org'
gem 'dotenv-rails', require: 'dotenv/rails-now'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
  "https://github.com/#{repo_name}.git"
end

gem 'active_model_serializers'    , '~> 0.9.3'
gem 'appsignal'                   , '~> 2.4'
gem 'capistrano-dotenv-tasks'     , require: false
gem 'clockwork'                   , '~> 2.0', '>= 2.0.2'
gem 'listen'                      , '>= 3.0.5', '< 3.2'
gem 'puma'                        , '~> 3.11'
gem 'pg'
gem 'pry-byebug'
gem 'pry-rails'
gem 'rails'                       , '~> 5.1.3'
gem 'rails_12factor'              , '~> 0.0.3'
gem 'rest-client'                 , '~> 2.0', '>= 2.0.2'
gem 'sidekiq'                     , '~> 4.2', '>= 4.2.9'
gem 'state_machines-activerecord' , '~> 0.5.0'

group :development do
gem 'annotate'                    , '~> 2.7', '>= 2.7.1'
gem 'capistrano'                  , '~> 3.9'
gem 'capistrano-bundler'          , '~> 1.3'
gem 'capistrano3-puma', github: "seuros/capistrano-puma"
gem 'capistrano-rails'            , '~> 1.3'
gem 'capistrano-rbenv'            , '~> 2.1', '>= 2.1.3'
gem 'capistrano-sidekiq'          , '~> 0.20.0'
gem 'spring'
gem 'spring-watcher-listen'       , '~> 2.0.0'
end

_ shared_pa​​th / config / sidekiq.yml: _

:concurrency: 5
:pidfile: tmp/pids/sidekiq-0.pid
:logfile: /tmp/sidekiq.log
staging:
  :concurrency: 10
production:
  :concurrency: 20
:queues:
  - [default,2]
  - [high,4]
  - [low,1]

:logfile: /tmp/sidekiq.log
staging:
  :concurrency: 10
production:
  :concurrency: 20
:queues:
  - [default,2]
  - [high,4]
  - [low,1]

Capfile:

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/sidekiq'
require 'capistrano/rbenv'
require 'capistrano/puma'
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git

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

deploy.rb:

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

set :application  , "sergicapi-sync-staging"
set :repo_url     , "git@github.com:sergicdev/eseis-middleware-api.git"
# There is a known bug that prevents sidekiq from starting when pty is true on Capistrano 3.
set :pty          , false
set :linked_files , %w{config/sidekiq.yml}
set :linked_dirs  , %w{config tmp/pids tmp/sockets}
set :stage        , :staging
set :deploy_via   , :remote_cache
set :log_level    , :debug



set :rbenv_type     , :user
set :rbenv_ruby     , '2.4.2'
set :rbenv_prefix   , "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins , %w{rake gem bundle ruby rails}
set :rbenv_roles    , :all



set :sidekiq_default_hooks        => true
set :sidekiq_pid                  => File.join(shared_path, 'tmp', 'pids', 'sidekiq.pid')
set :sidekiq_env                  => fetch(:rack_env, fetch(:rails_env, fetch(:stage)))
set :sidekiq_log                  => File.join(shared_path, 'log', 'sidekiq.log')
set :sidekiq_options              => nil
set :sidekiq_require              => nil
set :sidekiq_tag                  => nil
set :sidekiq_config               => -> { File.join(shared_path, 'config', 'sidekiq.yml') }
set :sidekiq_queue                => 'default'
set :sidekiq_timeout              => 10
set :sidekiq_role                 => :app
set :sidekiq_processes            => 1
set :sidekiq_options_per_process  => nil
set :sidekiq_concurrency          => 10
set :sidekiq_monit_default_hooks  => true
set :sidekiq_service_name         => "sidekiq_#{fetch(:application)}_#{fetch(:sidekiq_env)}"
set :sidekiq_user                 => 'root'



set :bundle_roles         , :all
set :bundle_servers       , -> { release_roles(fetch(:bundle_roles)) }
set :bundle_binstubs      , -> { shared_path.join('bin') }
set :bundle_gemfile       , -> { release_path.join('Gemfile') }
set :bundle_path          , -> { shared_path.join('bundle') }
set :bundle_without       , %w{development test}.join(' ')
set :bundle_flags         , '--deployment --quiet'
set :bundle_env_variables , {}
set :bundle_clean_options , ""


set :puma_user                , fetch(:user)
set :puma_rackup              , -> { File.join(current_path, 'config.ru') }
set :puma_state               , "#{shared_path}/tmp/pids/puma.state"
# set :puma_pid                 , "#{shared_path}/tmp/pids/puma.pid"
set :puma_pid                 , "#{shared_path}/tmp/pids/puma.pid"
set :puma_bind                , %w{192.168.100.18}
set :puma_control_app         , false
set :puma_default_control_app , "unix://#{shared_path}/sockets/pumactl.sock"
set :puma_conf                , "#{shared_path}/puma.rb"
set :puma_access_log          , "#{shared_path}/log/puma_access.log"
set :puma_error_log           , "#{shared_path}/log/puma_error.log"
set :puma_role                , :app
set :puma_env                 , fetch(:rack_env, fetch(:rails_env, 'production'))
set :puma_threads             , [4, 16]
set :puma_workers             , 0
set :puma_worker_timeout      , nil
set :puma_init_active_record  , true
set :puma_preload_app         , true
set :puma_daemonize           , false
set :puma_plugins             , []  #accept array of plugins
set :puma_tag                 , fetch(:application)
set :puma_restart_command     , 'bundle exec puma'



namespace :puma do
end

namespace :sidekiq do
end

namespace :deploy do

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

  desc 'Create shared folders'
  task :create_shared_folders do
    on roles(:all) do
      execute "mkdir #{shared_path}/sockets -p"
      execute "mkdir #{shared_path}/tmp -p"
      execute "mkdir #{shared_path}/tmp/pids -p"
      execute "mkdir #{shared_path}/log -p"
      execute "touch #{shared_path}/sockets/puma.sock"
      execute "touch #{shared_path}/sockets/pumactl.sock"
      execute "touch #{shared_path}/tmp/pids/puma.state"
      execute "touch #{shared_path}/log/sidekiq.log"
      execute "touch #{shared_path}/log/puma_access.log"
      execute "touch #{shared_path}/log/puma_error.log"
    end
  end

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      invoke 'puma:restart', 'sidekiq:restart'
    end
  end

  after  :finishing,    :cleanup
  after  :finishing,    :restart
end

staging.rb:

server '192.168.100.18',
  user: 'root',
  roles: %w{app web db},
  ssh_options: {
   forward_agent: true
  }

set :rails_env , 'staging'
set :deploy_to , '/var/www/sergicapi-sync-staging'
set :branch    , 'feature/capistratio'
set :tmp_dir   , '/tmp/sergicapi-sync-staging'
set :stage     , :staging

0 个答案:

没有答案