ruby on rails でオリジナルアプリを制作しており、EC2でデプロイをしようとしても、エラーが出てうまくいきません。
一応EC2、RDS、S3の設定、EC2への必要なアプリはインストールは終わってます。
bundle exec unicorn_rails -c /var/www/rails/アプリ名/config/unicorn.conf.rb -D -E production
をすると、
master failed to start, check stderr log for details
というエラーが出ます。
unicorn.logを見ると、ative_storage.service
のエラーとなってるので、S3設定エラーかと思いましたが、現状わかりません。
どのようにしたらエラーを解消できるか教えてもらえると助かります。
log/unicorn.log
cat/unicorn.log
1I, [2021-07-07T22:00:58.486860 #9852] INFO -- : Refreshing Gem list 2bundler: failed to load command: unicorn_rails (/home/ec2-user/.rbenv/versions/2.7.1/bin/unicorn_rails) 3NoMethodError: Cannot load `Rails.config.active_storage.service`: 4undefined method `match' for nil:NilClass 5 /home/ec2-user/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/aws-partitions-1.472.0/lib/aws-partitions/endpoint_provider.rb:113:in `block in partition_matching_region' 6. 7. 8. 9以下省略
config/unicorn.conf.rb
unicorn.conf.rb
1# set lets 2 $worker = 2 3 $timeout = 30 4 $app_dir = "/var/www/rails/Task_memo" 5 $listen = File.expand_path 'tmp/sockets/.unicorn.sock', $app_dir 6 $pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir 7 $std_log = File.expand_path 'log/unicorn.log', $app_dir 8 # set config 9 worker_processes $worker 10 working_directory $app_dir 11 stderr_path $std_log 12 stdout_path $std_log 13 timeout $timeout 14 listen $listen 15 pid $pid 16 # loading booster 17 preload_app true 18 # before starting processes 19 before_fork do |server, worker| 20 defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! 21 old_pid = "#{server.config[:pid]}.oldbin" 22 if old_pid != server.pid 23 begin 24 Process.kill "QUIT", File.read(old_pid).to_i 25 rescue Errno::ENOENT, Errno::ESRCH 26 end 27 end 28 end 29 # after finishing processes 30 after_fork do |server, worker| 31 defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection 32 end
config/storage.yml
test: service: Disk root: <%= Rails.root.join("tmp/storage") %> local: service: Disk root: <%= Rails.root.join("storage") %> # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) amazon: service: S3 access_key_id: <%= ENV['*******************'] %> secret_access_key: <%= ENV['*****************************/***********'] %> region: <%= ENV['ap-northeast-1'] %> bucket: <%= ENV['my-bucket'] %> . . . 以下省略
database.yml
database.yml
1# PostgreSQL. Versions 9.3 and up are supported. 2# 3# Install the pg driver: 4# gem install pg 5# On macOS with Homebrew: 6# gem install pg -- --with-pg-config=/usr/local/bin/pg_config 7# On macOS with MacPorts: 8# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config 9# On Windows: 10# gem install pg 11# Choose the win32 build. 12# Install PostgreSQL and put its /bin directory on your path. 13# 14# Configure Using Gemfile 15# gem 'pg' 16# 17default: &default 18 adapter: postgresql 19 20 encoding: unicode 21 # For details on connection pooling, see Rails configuration guide 22 # https://guides.rubyonrails.org/configuring.html#database-pooling 23 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 24 25development: 26 <<: *default 27 database: memo_development 28 29 # The specified database role being used to connect to postgres. 30 # To create additional roles in postgres see `$ createuser --help`. 31 # When left blank, postgres will use the default role. This is 32 # the same name as the operating system user that initialized the database. 33 #username: memo 34 35 # The password associated with the postgres role (username). 36 #password: 37 38 # Connect on a TCP socket. Omitted by default since the client uses a 39 # domain socket that doesn't need configuration. Windows does not have 40 # domain sockets, so uncomment these lines. 41 host: localhost 42 43 # The TCP port the server listens on. Defaults to 5432. 44 # If your server runs on a different port number, change accordingly. 45 port: 5432 46 47 # Schema search path. The server defaults to $user,public 48 #schema_search_path: myapp,sharedapp,public 49 50 # Minimum log levels, in increasing order: 51# debug5, debug4, debug3, debug2, debug1, 52 # log, notice, warning, error, fatal, and panic 53 # Defaults to warning. 54 #min_messages: notice 55 56# Warning: The database defined as "test" will be erased and 57# re-generated from your development database when you run "rake". 58# Do not set this db to the same as development or production. 59test: 60 <<: *default 61 database: memo_test 62 63# As with config/credentials.yml, you never want to store sensitive information, 64# like your database password, in your source code. If your source code is 65# ever seen by anyone, they now have access to your database. 66# 67# Instead, provide the password as a unix environment variable when you boot 68# the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database 69# for a full rundown on how to provide these environment variables in a 70# production deployment. 71# 72# On Heroku and other platform providers, you may have a full connection URL 73# available as an environment variable. For example: 74# 75# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" 76# 77# You can use this database configuration with: 78# 79# production: 80# url: <%= ENV['DATABASE_URL'] %> 81# 82production: 83 <<: *default 84 adapter: postgresql 85 encoding: unicode 86 # For details on connection pooling, see Rails configuration guide 87 # https://railsguides.jp/configuring.html#データベース接続をプールする 88 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 89 database: <%= ENV['DB_NAME'] %> 90 username: <%= ENV['DB_USERNAME'] %> 91 password: <%= ENV['DB_PASSWORD'] %> 92 host: <%= ENV['DB_HOST'] %>
あなたの回答
tips
プレビュー