現在、rails6のアプリをcapistranoを使用してEC2(amazon linux2)に自動デプロイしたいと思っています。
ですが、unicornの起動がうまく行きません。
具体的には、
bundle exec cap production deployを実行すると、
01:52 unicorn:restart 01 kill -s USR2 $(< /var/www/rails/myapp/current/tmp/pids/unicorn.pid) 01 kill: 01 9555 へのシグナル送信に失敗しました 01 : 01 No such process #<Thread:0x00007fb4aa1eedb0@/Users/name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true): Traceback (most recent call last): 1: from /Users/name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' /Users/name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as tadayoshi@54.92.45.5: kill exit status: 1 (SSHKit::Runner::ExecuteError) kill stdout: Nothing written kill stderr: kill: 9555 へのシグナル送信に失敗しました: No such process (Backtrace restricted to imported tasks) cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as name@54.92.100.100: kill exit status: 1 kill stdout: Nothing written kill stderr: kill: 9555 へのシグナル送信に失敗しました: No such process Caused by: SSHKit::Command::Failed: kill exit status: 1 kill stdout: Nothing written kill stderr: kill: 9555 へのシグナル送信に失敗しました: No such process /Users/tadayoshi/rails/app/lib/capistrano/tasks/unicorn.rake:18:in `reload_unicorn' /Users/tadayoshi/rails/app/lib/capistrano/tasks/unicorn.rake:43:in `block (3 levels) in <top (required)>' Tasks: TOP => unicorn:restart (See full trace by running task with --trace) The deploy has failed with an error: Exception while executing as name@54.92.100.100: kill exit status: 1 kill stdout: Nothing written kill stderr: kill: 9555 へのシグナル送信に失敗しました: No such process
とのエラーが発生します。
EC2内のunicornは停止済みですが、
var/www/rails/myapp/current/tmp/pids/unicorn.pid
には9555というpidがあり、こちらをvimで削除して再度デプロイを実行すると、
kill stdout: Nothing written kill stderr: kill: 十分な引数がありません (Backtrace restricted to imported tasks) cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as name@54.92.100.100: kill exit status: 1 kill stdout: Nothing written kill stderr: kill: 十分な引数がありません
と表示されます。
色々調べてみたのですが、なかなか解決できず、質問させていただきます。
以下にcapとunicorn関連のファイルを添付します。
どうかアドバイスよろしくお願いいたします。
lib/capistrano/tasks/unicorn.rake
namespace :unicorn do task :environment do set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid" set :unicorn_config, "#{current_path}/config/unicorn/production.rb" end def start_unicorn within current_path do execute :bundle, :exec, :unicorn, "-c #{fetch(:unicorn_config)} -E #{fetch(:rails_env)} -D" end end def stop_unicorn execute :kill, "-s QUIT $(< #{fetch(:unicorn_pid)})" end def reload_unicorn execute :kill, "-s USR2 $(< #{fetch(:unicorn_pid)})" end def force_stop_unicorn execute :kill, "$(< #{fetch(:unicorn_pid)})" end desc "Start unicorn server" task start: :environment do on roles(:app) do start_unicorn end end desc "Stop unicorn server gracefully" task stop: :environment do on roles(:app) do stop_unicorn end end desc "Restart unicorn server gracefully" task restart: :environment do on roles(:app) do if test("[ -f #{fetch(:unicorn_pid)} ]") reload_unicorn else start_unicorn end end end desc "Stop unicorn server immediately" task force_stop: :environment do on roles(:app) do force_stop_unicorn end end end
config/unicorn/production.rb
# set lets $worker = 2 $timeout = 30 $app_dir = "/var/www/rails/myapp/current" $listen = "/var/run/unicorn.sock", $app_dir $pid = '/var/www/rails/myapp/current/tmp/pids/unicorn.pid', $app_dir $std_log = File.expand_path 'log/unicorn.log', $app_dir # set config worker_processes $worker working_directory $app_dir stderr_path $std_log stdout_path $std_log timeout $timeout listen $listen pid $pid # loading booster preload_app true # before starting processes before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! old_pid = "#{server.config[:pid]}.oldbin" if old_pid != server.pid begin Process.kill "QUIT", File.read(old_pid).to_i rescue Errno::ENOENT, Errno::ESRCH end end end # after finishing processes after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end
deploy.rb
# config valid for current version and patch releases of Capistrano lock "~> 3.11.2" set :application, "myapp" set :repo_url, "git@github.com:myname/myapp.git" set :rbenv_ruby, '2.5.1' #Default branch is :master # ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp # Default deploy_to directory is /var/www/my_app_name set :deploy_to, "/var/www/rails/myapp" set :log_level, :debug set :linked_files, %w{config/database.yml config/master.key} set :linked_dirs, %w{log tmp/backup tmp/pids tmp/cache tmp/sockets public/system vendor/bundle} namespace :deploy do desc 'Restart application' task :restart do invoke 'unicorn:restart' end desc 'Upload database.yml' task :upload do on roles(:app) do |host| if test "[ ! -d #{shared_path}/config ]" execute "mkdir -p #{shared_path}/config" end upload!('config/database.yml', "#{shared_path}/config/database.yml") end end desc 'Create database' task :db_create do on roles(:db) do |host| with rails_env: fetch(:rails_env) do within current_path do execute :bundle, :exec, :rake, 'db:create' end end end end after :publishing, :restart after :restart, :clear_cache do on roles(:web), in: :groups, limit: 3, wait: 10 do end end end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/12/21 16:11