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

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

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

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

Ruby on Rails

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

Amazon EC2

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

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

2回答

310閲覧

EC2内でRailsを起動できない(master failed to start, check stderr log for details)

shutoshinoda

総合スコア1

Ruby

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

Ruby on Rails

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

Amazon EC2

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

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2021/01/31 23:56

編集2021/02/01 01:59

EC2内でrailsを起動できません。
[ec2-user@ip-172-31-45-189 newneu-hp]$ bundle exec unicorn_rails -c config/unicorn.rb -E production -D
master failed to start, check stderr log for details

EC2でエラーlogを確認しました。
[ec2-user@ip-172-31-45-189 log]$ cat unicorn.stderr.log

DEPRECATION WARNING: Including LoggerSilence is deprecated and will be removed in Rails 6.1. Please use ActiveSupport::LoggerSilence instead (called from <top (required)> at /var/www/newneu-hp/config/application.rb:7)

bundler: failed to load command: unicorn_rails (/home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails)
ArgumentError: Already running on PID:13986 (or pid=/var/www/newneu-hp/tmp/pids/unicorn.pid is stale))

知識が乏しくActiveSupport :: LoggerSilenceの使用の仕方が分かりません。
ご教授頂けますと幸いです。

該当のソースコード

application.rb

1require_relative 'boot' 2 3require 'rails/all' 4 5# Require the gems listed in Gemfile, including any gems 6# you've limited to :test, :development, or :production. 7Bundler.require(*Rails.groups) 8 9module NewneuHp 10 class Application < Rails::Application 11 # Initialize configuration defaults for originally generated Rails version. 12 config.load_defaults 6.0 13 14 # Settings in config/environments/* take precedence over those specified here. 15 # Application configuration can go into files in config/initializers 16 # -- all .rb files in that directory are automatically loaded after loading 17 # the framework and any gems in your application. 18 end 19end
# MySQL. Versions 5.5.8 and up are supported. # # Install the MySQL driver # gem install mysql2 # # Ensure the MySQL gem is defined in your Gemfile # gem 'mysql2' # # And be sure to use new-style password hashing: # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html # default: &default adapter: mysql2 encoding: utf8mb4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: <%= ENV['NEWNEU_HP_DATABASE_PASSWORD'] %> socket: /tmp/mysql.sock development: <<: *default database: newneu_hp_development # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: newneu_hp_test # As with config/credentials.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is # ever seen by anyone, they now have access to your database. # # Instead, provide the password as a unix environment variable when you boot # the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database # for a full rundown on how to provide these environment variables in a # production deployment. # # On Heroku and other platform providers, you may have a full connection URL # available as an environment variable. For example: # # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" # # You can use this database configuration with: # # production: # url: <%= ENV['DATABASE_URL'] %> # production: <<: *default database: newneu_hp_production username: root password: <%= ENV['DATABASE_PASSWORD'] %> socket: /var/lib/mysql/mysql.sock

動作中のプロセスに対してkillコマンドを使って全て停止させましたがエラーは変わりませんでしたがエラー文は変わりませんでした。
[ec2-user@ip-172-31-45-189 newneu-hp]$ kill 19975
[ec2-user@ip-172-31-45-189 newneu-hp]$ ps aux | grep unicorn
ec2-user 20174 0.0 0.0 119436 956 pts/0 S+ 01:07 0:00 grep --color=auto unicorn

###バージョン
unicorn (5.4.1)

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

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

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

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

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

yu_1985

2021/02/01 02:59

/var/www/newneu-hp/tmp/pids/unicorn.pid が存在しているか確かめて、存在しているなら削除してもう一度unicornを起動してみてください。 WARNINGについては質問の範疇外なので一旦無視でいいと思います。
shutoshinoda

2021/02/01 04:45

WARNING無視します! unicorn.pidあったので削除しました。 [ec2-user@ip-172-31-45-189 ~]$ cd /var/www/newneu-hp/tmp/pids/ [ec2-user@ip-172-31-45-189 pids]$ ls unicorn.pid [ec2-user@ip-172-31-45-189 pids]$ rm unicorn.pid [ec2-user@ip-172-31-45-189 pids]$ ls [ec2-user@ip-172-31-45-189 pids]$ cd [ec2-user@ip-172-31-45-189 ~]$ cd /var/www/newneu-hp/ [ec2-user@ip-172-31-45-189 newneu-hp]$ bundle exec unicorn_rails -c config/unicorn.rb -E production -D master failed to start, check stderr log for details 削除をし再度実行しましたがエラー変わらずでした…
yu_1985

2021/02/01 04:48

ログに出力された内容も変わりませんか?
shutoshinoda

2021/02/01 05:48

bundler: failed to load command: unicorn_rails (/home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails) ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage 少し変わりました! bundlerが何か不具合あるようです。 Bundler version 2.1. $ gem install bundler -v 2.1.4 $ bundle install 正常に動きますがエラー変わりません… 他のミスでしょうか…? 宜しくお願いします!
yu_1985

2021/02/01 05:59

> master failed to start, check stderr log for details というのは読んで字のごとくログを見ろというメッセージなので、都度ログを見て内容を確認してください。
shutoshinoda

2021/02/08 06:17

logを見て解決できました! ありがとうございます!
guest

回答2

0

自己解決

本番環境で環境変数を使用するために、/etc/environmentsファイルで設定をしました!

・sshで本番環境にログイン
$ ssh -i ~/.ssh/(pemファイル名) ec2-user@(EC2のElastic IP)


[ec2-user]$ sudo vim /etc/environment

・「config/master.key」の値をコピーして貼り付け
RAILS_MASTER_KEY='master.keyの値'

・ログインし直して環境変数が設定されたことを確認
[ec2-user]$ exit
$ ssh -i ~/.ssh/(pemファイル名) ec2-user@(EC2のElastic IP)
[ec2-user]$ env | grep RAILS_MASTER_KEY
マスターキーの内容が表示されればうまくいっています。

[ec2-user@ip-172-31-23-189 ~]$ cd /var/www/[リポジトリ]
[ec2-user@ip-172-31-23-189 <リポジトリ名>]$ bundle exec unicorn_rails -c config/unicorn.rb -E production -D

起動できました!

投稿2021/02/08 06:14

shutoshinoda

総合スコア1

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

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

0

ArgumentError: Already running on PID:13986 (or pid=/var/www/newneu-hp/tmp/pids/unicorn.pid is stale))

エラーメッセージのとおり、Unicornを二重起動しようとして失敗しているだけではないでしょうか?

投稿2021/02/01 00:10

maisumakun

総合スコア145183

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

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

shutoshinoda

2021/02/01 00:14

すみません、プログラミング勉強したてで当たり前の質問するかもしれませんが、Unicornを起動できている所にまた起動しようとしているという状態という事でしょうか?
shutoshinoda

2021/02/01 01:14

動作中のプロセスに対してkillコマンドを使って全て停止させましたがエラーは変わりませんでした。 [ec2-user@ip-172-31-45-189 newneu-hp]$ kill 19975 [ec2-user@ip-172-31-45-189 newneu-hp]$ ps aux | grep unicorn ec2-user 20174 0.0 0.0 119436 956 pts/0 S+ 01:07 0:00 grep --color=auto unicorn 他のエラーの可能性はありますでしょうか…?
maisumakun

2021/02/01 01:19

ちょっとわからないですね…
shutoshinoda

2021/02/01 01:20

解決に少し進めた気がします! ご回答ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問