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

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

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

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

Q&A

解決済

2回答

1101閲覧

rails6 - capistranoデプロイにて、unicorn再起動の部分のエラー

mnishikawa

総合スコア7

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

0グッド

0クリップ

投稿2019/12/18 12:56

実行環境

Ruby 2.6.2
Ruby on Rails 6.0.2
AWS EC2 Amazon Linux
Capistrano 3.11.2
nginx
unicorn 5.5.1

my歴 独学6ヶ月目

###現状

Capistranoでのデプロイを試みています。
bundle exec cap production deployで一度は最後まで行ったのですが、

EC2インスタンスを確認すると、nginxのホーム画面になっていたので、
unicornが起動していないのかと思い、プロセスをkillしたりしているうちに、
以下のように、unicornの再起動でエラーが出てしまいました。

正直質問するメンタルすらないぐらいエラーざんまいで果てそうなのですが、
せっかくここまで来たので、デプロイして笑いたいです。

エラー文

Masahiro:Kotosearch masahiro$ bundle exec cap production deploy 00:00 git:wrapper 01 mkdir -p /tmp ✔ 01 masahiro@18.176.74.100 0.201s Uploading /tmp/git-ssh-Kotosearch-production-masahiro.sh 100.0% 02 chmod 700 /tmp/git-ssh-Kotosearch-production-masahiro.sh ✔ 02 masahiro@18.176.74.100 0.191s 00:00 git:check 01 git ls-remote https://github.com/cutsome/Kotosearch.git HEAD 01 f56b194c37d18405476bc0e0cccb6c5612930fdd HEAD ✔ 01 masahiro@18.176.74.100 2.856s 00:03 deploy:check:directories 01 mkdir -p /var/www/rails/Kotosearch/shared /var/www/rails/Kotosearch/releases ✔ 01 masahiro@18.176.74.100 0.242s 00:03 deploy:check:linked_dirs 01 mkdir -p /var/www/rails/Kotosearch/shared/log /var/www/rails/Kotosearch/shared/tmp/pids /var/www/rails/Koto… ✔ 01 masahiro@18.176.74.100 0.194s 00:04 deploy:check:make_linked_dirs 01 mkdir -p /var/www/rails/Kotosearch/shared/config ✔ 01 masahiro@18.176.74.100 0.204s 00:05 git:clone The repository mirror is at /var/www/rails/Kotosearch/repo 00:05 git:update 01 git remote set-url origin https://github.com/cutsome/Kotosearch.git ✔ 01 masahiro@18.176.74.100 0.226s 02 git remote update --prune 02 Fetching origin ✔ 02 masahiro@18.176.74.100 2.727s 00:08 git:create_release 01 mkdir -p /var/www/rails/Kotosearch/releases/20191218124221 ✔ 01 masahiro@18.176.74.100 0.196s 02 git archive master | /usr/bin/env tar -x -f - -C /var/www/rails/Kotosearch/releases/20191218124221 ✔ 02 masahiro@18.176.74.100 0.194s 00:09 deploy:set_current_revision 01 echo "f56b194c37d18405476bc0e0cccb6c5612930fdd" > REVISION ✔ 01 masahiro@18.176.74.100 0.185s 00:09 deploy:symlink:linked_files 01 mkdir -p /var/www/rails/Kotosearch/releases/20191218124221/config ✔ 01 masahiro@18.176.74.100 0.206s 02 ln -s /var/www/rails/Kotosearch/shared/config/settings.yml /var/www/rails/Kotosearch/releases/2019121812422… ✔ 02 masahiro@18.176.74.100 0.204s 00:10 deploy:symlink:linked_dirs 01 mkdir -p /var/www/rails/Kotosearch/releases/20191218124221 /var/www/rails/Kotosearch/releases/2019121812422… ✔ 01 masahiro@18.176.74.100 0.182s 02 rm -rf /var/www/rails/Kotosearch/releases/20191218124221/log ✔ 02 masahiro@18.176.74.100 0.196s 03 ln -s /var/www/rails/Kotosearch/shared/log /var/www/rails/Kotosearch/releases/20191218124221/log ✔ 03 masahiro@18.176.74.100 0.209s 04 ln -s /var/www/rails/Kotosearch/shared/tmp/pids /var/www/rails/Kotosearch/releases/20191218124221/tmp/pids ✔ 04 masahiro@18.176.74.100 0.212s 05 ln -s /var/www/rails/Kotosearch/shared/tmp/cache /var/www/rails/Kotosearch/releases/20191218124221/tmp/cache ✔ 05 masahiro@18.176.74.100 0.201s 06 ln -s /var/www/rails/Kotosearch/shared/tmp/sockets /var/www/rails/Kotosearch/releases/20191218124221/tmp/so… ✔ 06 masahiro@18.176.74.100 0.226s 07 ln -s /var/www/rails/Kotosearch/shared/vendor/bundle /var/www/rails/Kotosearch/releases/20191218124221/vend… ✔ 07 masahiro@18.176.74.100 0.181s 08 ln -s /var/www/rails/Kotosearch/shared/public/system /var/www/rails/Kotosearch/releases/20191218124221/publ… ✔ 08 masahiro@18.176.74.100 0.249s 00:16 bundler:install 01 $HOME/.rbenv/bin/rbenv exec bundle install --path /var/www/rails/Kotosearch/shared/bundle --jobs 4 --withou… ✔ 01 masahiro@18.176.74.100 0.858s 00:16 deploy:migrate [deploy:migrate] Run `rake db:migrate` 00:17 deploy:migrating 01 $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate ✔ 01 masahiro@18.176.74.100 1.371s 00:18 deploy:symlink:release 01 ln -s /var/www/rails/Kotosearch/releases/20191218124221 /var/www/rails/Kotosearch/releases/current ✔ 01 masahiro@18.176.74.100 0.188s 02 mv /var/www/rails/Kotosearch/releases/current /var/www/rails/Kotosearch ✔ 02 masahiro@18.176.74.100 0.196s 00:19 unicorn:restart 01 kill -s USR2 $(< /var/www/rails/Kotosearch/current/tmp/pids/unicorn.pid) 01 kill: 01 sending signal to 21021 failed 01 : 01 そのようなプロセスはありません #<Thread:0x00007fced0cb7ef0@/Users/masahiro/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.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): 10: from /Users/masahiro/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute' 9: from /Users/masahiro/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in `run' 8: from /Users/masahiro/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec' 7: from /Users/masahiro/Desktop/environment/Kotosearch/lib/capistrano/tasks/unicorn.rake:51:in `block (3 levels) in <top (required)>' 6: from /Users/masahiro/Desktop/environment/Kotosearch/lib/capistrano/tasks/unicorn.rake:22:in `reload_unicorn' 5: from /Users/masahiro/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:80:in `execute' 4: from /Users/masahiro/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute' 3: from /Users/masahiro/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `tap' 2: from /Users/masahiro/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute' 1: from /Users/masahiro/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/netssh.rb:170:in `execute_command' /Users/masahiro/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/command.rb:97:in `exit_status=': kill exit status: 1 (SSHKit::Command::Failed) kill stdout: Nothing written kill stderr: kill: sending signal to 21021 failed: そのようなプロセスはありません 1: from /Users/masahiro/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' /Users/masahiro/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as masahiro@18.176.74.100: kill exit status: 1 (SSHKit::Runner::ExecuteError) kill stdout: Nothing written kill stderr: kill: sending signal to 21021 failed: そのようなプロセスはありません (Backtrace restricted to imported tasks) cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as masahiro@18.176.74.100: kill exit status: 1 kill stdout: Nothing written kill stderr: kill: sending signal to 21021 failed: そのようなプロセスはありません Caused by: SSHKit::Command::Failed: kill exit status: 1 kill stdout: Nothing written kill stderr: kill: sending signal to 21021 failed: そのようなプロセスはありません /Users/masahiro/Desktop/environment/Kotosearch/lib/capistrano/tasks/unicorn.rake:22:in `reload_unicorn' /Users/masahiro/Desktop/environment/Kotosearch/lib/capistrano/tasks/unicorn.rake:51: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 masahiro@18.176.74.100: kill exit status: 1 kill stdout: Nothing written kill stderr: kill: sending signal to 21021 failed: そのようなプロセスはありません ** DEPLOY FAILED ** Refer to log/capistrano.log for details. Here are the last 20 lines: ~省略~ DEBUG [5c9877a7] Running [ -f /var/www/rails/Kotosearch/current/tmp/pids/unicorn.pid ] as masahiro@18.176.74.100 DEBUG [5c9877a7] Command: [ -f /var/www/rails/Kotosearch/current/tmp/pids/unicorn.pid ] DEBUG [5c9877a7] Finished in 0.167 seconds with exit status 0 (successful). INFO [235ce5ce] Running /usr/bin/env kill -s USR2 $(< /var/www/rails/Kotosearch/current/tmp/pids/unicorn.pid) as masahiro@18.176.74.100 DEBUG [235ce5ce] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.6.2" ; /usr/bin/env kill -s USR2 $(< /var/www/rails/Kotosearch/current/tmp/pids/unicorn.pid) ) DEBUG [235ce5ce] kill: DEBUG [235ce5ce] sending signal to 21021 failed DEBUG [235ce5ce] : DEBUG [235ce5ce] そのようなプロセスはありません Masahiro:Kotosearch masahiro$

こんな雑な質問で大変恐縮ですが、頭の中が真っ白で解決策が全くわからないので、
どなたかヒントをいいただけましたら大変幸いです、、

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

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

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

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

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

guest

回答2

0

自己解決

lib/capistrano/tasks/unicorn.rake

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

すみません、返答と同じ文章ですが、
そもそもkillして停止していたunicornに対し、一度停止してスタートする再起動の
命令がreload_unicornのように入っていたので、ここを一度start_unicornに変えて
デプロイ して起動状態にしておき、もう一回reload_unicornに戻してデプロイ したら
うまく行きました!

皆様のお役に立てますように。

投稿2019/12/18 17:18

mnishikawa

総合スコア7

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

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

0

deployに定義している起動プロセスで kill に失敗した時に終了してしまう書き方なのが原因です。
deployにそう堪能ではないので、どこまで書けるかわからない私は、起動のためのshellを書き(その中でkillの失敗は無視)それを起動するようにしています

投稿2019/12/18 13:16

winterboum

総合スコア23329

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

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

mnishikawa

2019/12/18 17:14

``` 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 ``` そもそもkillして停止していたunicornに対し、一度停止してスタートする再起動の 命令がreload_unicornのように入っていたので、ここを一度start_unicornに変えて デプロイ して起動状態にしておき、もう一回reload_unicornに戻してデプロイ したら うまく行きました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問