前提・実現したいこと
現在、作成したオリジナルアプリをhttps://qiita.com/naoki_mochizuki/items/5a1757d222806cbe0cd1こちらの記事に従ってawsにデプロイしようとしています。
そこで、unicornが起動しません。
bundle exec unicorn_rails -c /var/www/rails/viewhome/config/unicorn.conf.rb -D -E production
を実行すると
master failed to start, check stderr log for detailsと表示されます。
logを見ると下記のエラーがでています。
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
私はオリジナルアプリをrailstutorialを参考にしながら作成しました。
active_storageの設定も参考にしています。
$ heroku config:set AWS_ACCESS_KEY=<accessキー> $ heroku config:set AWS_SECRET_KEY=<secretキー> $ heroku config:set AWS_REGION=<リージョン名> $ heroku config:set AWS_BUCKET=<bucket名>
を実行し、
config/storage.yml 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
としています。
herokuでは問題なく動きます。
変更すべき点やしないといけない事等ありますでしょうか。
解決方法わかる方いましたら教えていただきたいです。
該当のソースコード
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 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]
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。