Home>

Currently, I am trying to deploy the created original app to aws according to this article https://qiita.com/naoki_mochizuki/items/5a1757d222806cbe0cd1.
So unicorn doesn't start.
bundle exec unicorn_rails -c /var/www/rails/viewhome/config/unicorn.conf.rb -D -E production
When you run
The message master failed to start, check stderr log for details is displayed.
Looking at the log, I get the following error.

INFO-: Refreshing Gem list
bundler: failed to load command: unicorn_rails (/home/kei/.rbenv/versions/2.7.1/bin/unicorn_rails)
NoMethodError: Cannot load `Rails.config.active_storage.service`:
undefined method `match'for nil: NilClass


I created the original app with reference to the rails tutorial.
I also refer to the setting of active_storage.

$heroku config: set AWS_ACCESS_KEY = $heroku config: set AWS_SECRET_KEY =<secret key>$heroku config: set AWS_REGION =<region name>$heroku config: set AWS_BUCKET =<bucket name>


And run

config/storage.yml
test: test:
  service: Disk
  root:<% = Rails.root.join ("tmp/storage")%>local:
  service: Disk
  root:<% = Rails.root.join ("storage")%>amazon:
  service: S3
  access_key_id:<% = ENV ['AWS_ACCESS_KEY']%>secret_access_key:<% = ENV ['AWS_SECRET_KEY']%>region:<% = ENV ['AWS_REGION']%>bucket:<% = ENV ['AWS_BUCKET']%>
config/environments/production.rb
  config.active_storage.service =: amazon


It is said.
It works fine on heroku.
Is there anything I need to change or have to change?
If i know the solution, please let me know.

Corresponding source code
config/unicorn.conf.rb
#setlets
$worker = 2
$timeout = 30
$app_dir = "/ var/www/rails/viewhome"
$listen = File.expand_path'tmp/sockets/.unicorn.sock', $app_dir
$pid = File.expand_path'tmp/pids/unicorn.pid', $app_dir$std_log = File.expand_path'log/unicorn.log', $app_dir
#set config
worker_processes $worker
working_directory $app_dir
stderr_path $std_log
stdout_path $std_log
timeout $timeout
listen $listen
pid $pid
# loading booster
preload_app true
# before starting processes
before_fork do | server, worker |
  defined? (ActiveRecord :: Base) and ActiveRecord :: Base.connection.disconnect!
  old_pid = "# {server.config [: pid]} .oldbin"
  if old_pid! = server.pid
    begin begin
      Process.kill "QUIT", File.read (old_pid) .to_i
    rescue Errno :: ENOENT, Errno :: ESRCH
    end
  end
end
# after finishing processes
after_fork do | server, worker |
  defined? (ActiveRecord :: Base) and ActiveRecord :: Base.establish_connection
end
Gemfile
# Bundle edge Rails instead: gem'rails', github:'rails/rails'
gem'rails','~>6.0.3','>= 6.0.3.2'
gem'mini_magick'
gem'active_storage_validations'
gem'faker'
gem'will_paginate'
gem'bootstrap-will_paginate'
gem'bootstrap-sass'
gem'jquery-rails'
gem'rails-i18n'
gem'mail-iso-2022-jp'
gem'aws-sdk-s3', '1.46.0', require: false
gem'kaminari'
#Use Puma as the app server
gem'puma','~>4.1'
#Use SCSS for stylesheets
gem'sass-rails','>= 6'
#Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem'webpacker','~>4.0'
#Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem'turbolinks','~>5'#Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem'jbuilder','~>2.7'
#Use Redis adapter to run Action Cable in production
# gem'redis','~>4.0'
# Use Active Model has_secure_password
 gem'bcrypt','~>3.1.7'
# Use Active Storage variant
 gem'image_processing','~>1.2'
#Reduces boot times through caching;required in config/boot.rb
 gem'bootsnap','>= 1.4.2', require: false
roup: development,: test do
  #Call'byebug' anywhere in the code to stop execution and get a debugger console
  gem'byebug', platforms: [: mri,: mingw,: x64_mingw]
  ## Use sqlite3 as the database for Active Record
  gem'mysql2'
  gem'rspec-rails'
  gem'factory_bot_rails'
  gem'faker'
end
group: development do
  #Access an interactive console on exception pages or by calling'console' anywhere in the code.
  gem'web-console','>= 3.3.0'
  gem'listen','~>3.2'
  #Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem'spring'
  gem'spring-watcher-listen','~>2.0.0'
  gem'spring-commands-rspec'
end
group: test do
  #Adds support for Capybara system testing and selenium driver
  gem'rails-controller-testing'
  gem'capybara','>= 2.15'
  gem'selenium-webdriver'
  #Easy installation and use of web drivers to run system tests with browsers
  #gem'webdrivers'
  #gem'chromedriver-helper'
  gem'shoulda-matchers'
  gem'database_cleaner'
end
group: production do
  gem'mysql2'
end
group: production,: staging do
  gem'unicorn', '5.4.1'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem'tzinfo-data', platforms: [: mingw,: mswin,: x64_mingw,: jruby]
  • Answer # 1

    https://qiita.com/NaokiIshimura/items/2a179f2ab910992c4d39
    I was able to solve it by changing the environment variables, referring to this article.