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

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

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

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

Ruby on Rails 5

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

Ruby

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

Ruby on Rails

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

Capistrano

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

Q&A

解決済

1回答

743閲覧

capistranoのデプロイ中のunicorn:startの際に、SSHKit::Runner::ExecuteErrorが発生してしまう

big2017

総合スコア39

unicorn

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

Ruby on Rails 5

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

Ruby

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

Ruby on Rails

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

Capistrano

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

0グッド

0クリップ

投稿2018/09/21 08:28

capistranoのデプロイをしていますが、途中のunicorn:startの際に表題のエラーが発生します。
お手数おかけしますが、何か助言をいただけますと幸いです。

エラー内容はkillコマンドの使用法を正しくしてくださいとあるのですが、誤っているとは思いません...

unicornのエラーだったので、
サーバーの再起動、unicornプロセスのkillなどは行いましたが、解決に至りませんでした。

$ bundle exec cap production deployの実行中

エラーログ unicorn:start 01 /home/user/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/app/fender/current/config/unicorn/production.rb -E deployment -D ✔ 01 user@123.4.43.5 6.596s unicorn restarting... 02 kill -s USR2 `cat /var/www/app/fender/shared/tmp/pids/unicorn.pid` 02 02 Usage: 02 kill [options] <pid|name> [...] 02 02 オプション: 02 -a, --all do not restrict the name-to-pid conversion to processes 02 with the same uid as the present process 02 -s, --signal <sig> send specified signal 02 -q, --queue <sig> use sigqueue(2) rather than kill(2) 02 -p, --pid print pids without signaling them 02 -l, --list [=<signal>] list signal names, or convert one to a name 02 -L, --table list signal names and numbers 02 02 -h, --help display this help and exit 02 -V, --version output version information and exit 02 02 For more details see kill(1). #<Thread:0x00007f976fd0a878@/Users/username/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.17.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true): Traceback (most recent call last): 1: from /Users/username/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.17.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' /Users/username/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.17.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as user@123.4.43.5: kill exit status: 1 (SSHKit::Runner::ExecuteError) kill stdout: Usage: kill [options] <pid|name> [...] For more details see kill(1). kill stderr: Nothing written (Backtrace restricted to imported tasks) cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as nattu@118.27.9.161: kill exit status: 1 kill stdout: Usage: kill [options] <pid|name> [...]

エラーログをみる限りだと、
実行のコマンドの使用法(↓下に記載)が正常ではないということなのかと思いますが、

kill -s USR2 cat /var/www/app/fender/shared/tmp/pids/unicorn.pid

他の方のunicorn.capを検索しながらunicorn.capのkillコマンドを実行させているメソッド周辺などを確認しましたが、誤ってそうな箇所はありませんでした。
このエラーはkillコマンドの使用方法が誤っているのでしょうか?

関連しそうなファイルを載せます。

/capistrano/tasks/unicorn.cap

namespace :unicorn do task :environment do # shared_path = "/var/www/app/fender/shared" # current_path = "/var/www/app/fender/current" set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid" set :unicorn_config, "#{current_path}/config/unicorn/#{fetch(:rails_env)}.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

# -*- coding: utf-8 -*- worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3) timeout 20 # ホットデプロイをするか? preload_app true # 更新時ダウンタイム無し app_path = '/var/www/app/fender/current' working_directory "#{app_path}" app_shared_path = "#{app_path}/shared" # nginxと連携するための設定 # リクエストを受け取る ポート番号を指定 listen "#{app_shared_path}/tmp/sockets/unicorn.sock" stdout_path "#{app_shared_path}/log/unicorn.stdout.log" stderr_path "#{app_shared_path}/log/unicorn.stderr.log" # PIDの管理ディレクトリ pid "#{app_shared_path}/tmp/pids/unicorn.pid" # ログの出力パス stderr_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT']) stdout_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT']) # フォーク前に行うことを定義 before_fork do |server, worker| Signal.trap 'TERM' do puts 'Unicorn master intercepting TERM and sending myself QUIT instead' Process.kill 'QUIT', Process.pid end defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! end # フォーク後に行うことを定義 after_fork do |server, worker| Signal.trap 'TERM' do puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT' end defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end

config/deploy.rb

# 共通の設定をconfig/deploy.rbで記述 # config valid for current version and patch releases of Capistrano lock "~> 3.11.0" # 基本設定 set :application, "fender" set :repo_url, "git@github.com:NatsukiSugawara/fender.git" # デプロイ対象のリポジトリ set :deploy_to, '/var/www/app/fender' # デプロイ先 set :branch, 'master' # ブランチを指定できる # set :scm, :git set :deploy_via, :remote_cache set :log_level, :debug # capistranoの出力ログの制御 set :pty, true # sudoを使用するのに必要 # bundleインストール設定 set :bundle_binstubs, nil # Shared に入るものを指定 set :linked_files, %w{config/database.yml config/secrets.yml} # シンボリックリンクを貼るファイル ->デプロイ対象としたくないファイルを記載 set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets bundle public/system public/assets} # sharedにシンボリックリンクを張るディレクトリ指定-> デプロイ対象としたくないディレクトリを記載 # Unicorn set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid" # リリースフォルダをいくつまで保持するか? set :keep_releases, 5 after 'deploy:publishing', 'deploy:restart' namespace :deploy do desc 'Restart application' # アプリ再起動を行うタスク task :restart do on roles(:app), in: :sequence, wait: 5 do execute :mkdir, '-p', release_path.join('tmp') execute :touch, release_path.join('tmp/restart.txt') end end # linked_files で使用するファイルをアップロードするタスク # deployが行われる前に実行する必要がある。 desc 'upload important files' task :upload do # binding.pry on roles(:app) do |host| execute :mkdir, '-p', "#{shared_path}/config" upload!('config/database.yml',"#{shared_path}/config/database.yml") upload!('config/secrets.yml',"#{shared_path}/config/secrets.yml") end end # webサーバー再起動時にキャッシュを削除する after :restart, :clear_cache do on roles(:web), in: :groups, limit: 3, wait: 10 do #Here we can do anything such as: within release_path do execute :rm, '-rf', release_path.join('tmp/cache') end end end # Flow の before, after のタイミングで上記タスクを実行 before :started, 'deploy:upload' after :finishing, 'deploy:cleanup' #unicorn 再起動タスク desc 'Restart application' task :restart do invoke 'unicorn:restart' # lib/capustrano/tasks/unicorn.cap 内処理を実行 end end

リモートサーバー内で
$ /usr/bin/env kill -s USR2 cat /var/www/app/fender/shared/tmp/pids/unicorn.pid
行いましたが、同様のエラーになります

Usage: kill [options] <pid|name> [...] オプション: -a, --all do not restrict the name-to-pid conversion to processes with the same uid as the present process -s, --signal <sig> send specified signal -q, --queue <sig> use sigqueue(2) rather than kill(2) -p, --pid print pids without signaling them -l, --list [=<signal>] list signal names, or convert one to a name -L, --table list signal names and numbers -h, --help display this help and exit -V, --version output version information and exit For more details see kill(1).

$ tail -f unicorn.log # ユニコーンログ

I, [2018-09-21T15:48:07.269858 #8546] INFO -- : Refreshing Gem list I, [2018-09-21T15:48:11.973895 #8546] INFO -- : listening on addr=/var/www/app/fender/current/shared/tmp/sockets/unicorn.sock fd=11 I, [2018-09-21T15:48:12.000559 #8550] INFO -- : worker=0 ready I, [2018-09-21T15:48:12.002483 #8546] INFO -- : master process ready I, [2018-09-21T15:48:12.003035 #8553] INFO -- : worker=1 ready I, [2018-09-21T15:48:12.005866 #8557] INFO -- : worker=2 ready

$ ps aux | grep unicorn #プロセスの確認(killはすでにしましたが、治りませんでした。)

user 3092 0.1 7.3 478076 139216 ? Sl 16:23 0:05 unicorn master -c /var/www/app/fender/current/config/unicorn/production.rb -E deployment -D user 3096 0.0 7.1 479064 133896 ? Sl 16:23 0:00 unicorn worker[0] -c /var/www/app/fender/current/config/unicorn/production.rb -E deployment -D user 3100 0.0 7.1 479080 133872 ? Sl 16:23 0:00 unicorn worker[1] -c /var/www/app/fender/current/config/unicorn/production.rb -E deployment -D user 3104 0.0 7.1 479080 133876 ? Sl 16:23 0:00 unicorn worker[2] -c /var/www/app/fender/current/config/unicorn/production.rb -E deployment -D user 3341 0.0 0.0 112720 980 pts/0 S+ 17:23 0:00 grep --color=auto unicorn

長文で失礼しました。
何助言いただけますと幸いです。
すみませんが、何卒よろしくお願いいたします。

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

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

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

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

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

guest

回答1

0

ベストアンサー

なんらかの原因(そもそもない、権限が不足している など)で

`cat /var/www/app/fender/shared/tmp/pids/unicorn.pid`

でpidが表示されないのではないでしょうか?

投稿2018/09/23 09:37

asm

総合スコア15147

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

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

big2017

2018/09/25 15:23

ご回答ありがとうございました。 ご指摘の通り、ファイルがなかったということでした。. ひとまずデプロイを終えることができました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問