質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

Q&A

解決済

1回答

1679閲覧

capistrano3のデプロイでunicornがうまく起動しない

garta

総合スコア15

unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

0グッド

0クリップ

投稿2019/12/17 00:44

現在、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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

pids/unicorn.pid が存在しないのにそこの値を引数に kill したので 引数がない状態となってエラー終了してしまったですね。
ない pid でkillしても同じくです。

「pids/unicorn.pid を参照して unicornを killする。
成功しようが失敗しようが 正常終了で終わる」
というshellを作ってそれを呼ぶようにしてはどうでしょうか

投稿2019/12/17 00:55

winterboum

総合スコア23329

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

garta

2019/12/21 16:11

なかなか作業の時間が取れず、返信遅くなってしまい申し訳ありません。 かねてからunicornをpumaに変更しようと考えていたため、あまりよくないやり方だと思いますが unicornからpumaに移行し設定もpumaに全て書き換えたところ正常に動作するようになりました。 年末で忙しい中、いつもありがとうございます。 しかしpumaに変更したところhttpsがうまく繋がらないため、新たに質問を投稿します。 よろしければ目を通していただけたらと思います。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問