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

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

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

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

Ruby on Rails

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

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

1回答

1941閲覧

capistranoを使用した自動デプロイ時のエラー(hg stderr: /usr/bin/env: hg: No such file or directory)について

hamiru-marku

総合スコア0

Ruby

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

Ruby on Rails

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

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2021/09/23 03:55

前提・実現したいこと

現在、Railsでアプリケーションを作成しまして、本番環境にはAWS EC2を使用し、
capistranoで自動デプロイができる設定にしようとしています。

インターネット上に公開されている手順などを参考に環境設定を行い、
デプロイを実行したところ、以下のようなエラーが発生し自力での解決が困難なためご質問させていただきました。

発生している問題・エラーメッセージ

コンテナ内でデプロイを実行しましたところ以下のようなエラーが出力されます。

<実行コマンド> bundle exec cap production deploy
root@fbe6b39ff462:/develop# bundle exec cap production deploy 00:00 hg:check 01 hg id https://github.com/app/production_app.git 01 /usr/bin/env: 01 hg 01 : No such file or directory 01 #<Thread:0x0000559fef86dca8@/usr/local/bundle/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true): Traceback (most recent call last): 1: from /usr/local/bundle/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' /usr/local/bundle/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ec2-user@54.xx.xx.xx: hg exit status: 127 (SSHKit::Runner::ExecuteError) hg stdout: Nothing written hg stderr: /usr/bin/env: hg: No such file or directory (Backtrace restricted to imported tasks) cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as ec2-user@54.xx.xx.xx: hg exit status: 127 hg stdout: Nothing written hg stderr: /usr/bin/env: hg: No such file or directory Caused by: SSHKit::Command::Failed: hg exit status: 127 hg stdout: Nothing written hg stderr: /usr/bin/env: hg: No such file or directory Tasks: TOP => deploy:check => hg:check (See full trace by running task with --trace) The deploy has failed with an error: Exception while executing as ec2-user@54.xx.xx.xx: hg exit status: 127 hg stdout: Nothing written hg stderr: /usr/bin/env: hg: No such file or directory ** DEPLOY FAILED ** Refer to log/capistrano.log for details. Here are the last 20 lines: DEBUG [10e531c9] Command: [ -d $HOME/.rbenv/versions/2.5.9 ] DEBUG [10e531c9] Finished in 0.210 seconds with exit status 0 (successful). INFO [0f9341e1] Running /usr/bin/env hg id https://github.com/app/production_app.git as ec2-user@54.xx.xx.xx DEBUG [0f9341e1] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.9" ; /usr/bin/env hg id https://github.com/app/production_app.git ) DEBUG [0f9341e1] /usr/bin/env: DEBUG [0f9341e1] hg DEBUG [0f9341e1] : No such file or directory DEBUG [0f9341e1] INFO --------------------------------------------------------------------------- INFO START 2021-09-23 12:22:59 +0900 cap production deploy INFO --------------------------------------------------------------------------- DEBUG [7d9ac82b] Running [ -d $HOME/.rbenv/versions/2.5.9 ] as ec2-user@54.xx.xx.xx DEBUG [7d9ac82b] Command: [ -d $HOME/.rbenv/versions/2.5.9 ] DEBUG [7d9ac82b] Finished in 0.226 seconds with exit status 0 (successful). INFO [cac46985] Running /usr/bin/env hg id https://github.com/app/production_app.git as ec2-user@54.xx.xx.xx DEBUG [cac46985] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.9" ; /usr/bin/env hg id https://github.com/app/production_app.git ) DEBUG [cac46985] /usr/bin/env: DEBUG [cac46985] hg DEBUG [cac46985] : No such file or directory DEBUG [cac46985]
<log/capistrano.log> INFO --------------------------------------------------------------------------- INFO START 2021-09-23 12:48:17 +0900 cap production deploy INFO --------------------------------------------------------------------------- DEBUG [3bd968d4] Running [ -d $HOME/.rbenv/versions/2.5.9 ] as ec2-user@54.xx.xx.xx DEBUG [3bd968d4] Command: [ -d $HOME/.rbenv/versions/2.5.9 ] DEBUG [3bd968d4] Finished in 0.232 seconds with exit status 0 (successful). INFO [ed9c17f2] Running /usr/bin/env hg id https://github.com/app/production_app.git as ec2-user@54.xx.xx.xx DEBUG [ed9c17f2] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.9" ; /usr/bin/env hg id https://github.com/app/production_app.git ) DEBUG [ed9c17f2] /usr/bin/env: DEBUG [ed9c17f2] hg DEBUG [ed9c17f2] : No such file or directory DEBUG [ed9c17f2]

試したこと

元々は以下のようなssh接続ができない旨のエラーが出ていましたので、
ローカルホスト上に配置していた「~/.ssh/xxxxx.pem」をコンテナ内にもコピーし、再度デプロイを実行しました。

cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as ec2-user@54.xx.xx.xx: Authentication failed for user ec2-user@54.xx.xx.xx

その結果が上記のエラーになるのですが、元々発生していたssh接続自体は解消された?と仮定し、
その後、現在画面上に出ているエラーを調査しているような状況です。

なお、エラー文中にある
「/usr/bin/env: hg: No such file or directory」から、存在しないとみなされているファイルが本番環境上に存在するかどうかを確認したところ、
以下の通り存在はしているように見えましたため、他何か原因があるのかと調査しているものの、原因特定に至っていない状況となります。

[ec2-user@ip-172-31-33-117 production_app]$ ls -lht /usr/bin/env -rwxr-xr-x 1 root root 29K Jan 23 2020 /usr/bin/env

こちらのエラーの原因について、どう解消したら良いかなどご助言をいただけますでしょうか。

補足情報(FW/ツールのバージョンなど)

作業中の開発環境、及び本番環境については以下になります。

<開発環境> Rails 5.2.6 Ruby 2.5.9 bundler 1.17.3 Docker 20.10.7 (Debian 10.10) psql 11.12
<本番環境> Amazon Linux release 2 (Karoo) nginx 1.20.0 unicorn 6.0.0 ※ruby, bundler, DBはいずれも開発環境と同様

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

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

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

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

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

guest

回答1

0

自己解決

すみません。自己解決しました。
原因の詳細はわかっていないのですが、exit status: 127は$PATHがおかしい時やコマンドミスの場合に発生するとどこかの記事で見つけたのでその路線で修正しました。
関連ファイルでhgコマンドを実行させる記述がないか見ていき、Capfileの以下記述をコメントアウトし再度デプロイを実行したところ成功しました。

<./Capfile> # require "capistrano/scm/hg" # install_plugin Capistrano::SCM::Hg

記事によっては上記の記述を有効化するなどの掲載がありますが、あまり背景などよく理解せずに進めていた故のエラーでした。
まだ回答はありませんが、もし既にお調べくださった方などいましたら申し訳ございません。
以降は作業履歴などからも解消に繋げられないかを考慮するようにします。

投稿2021/09/23 09:09

hamiru-marku

総合スコア0

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問