AWSに更新内容を反映させようと
bundle exec cap production deployコマンドを使い
capistranoでrailsアプリをAWSサーバーに再度デプロイをしたのですが、
このようなエラーが出ました。
Mysql2::Error::ConnectionError: Unknown MySQL server host 'db' (2)
Elasticaアドレスを使いいぜんはひらけていたのですが、
we are sorryと出るようになってしまいました。
[ec2-user@ip**** Books]$ rails db:create RAILS_ENV=production
このコマンドでも同じエラーが出ます
docker-compose up 時にでる debconf: delaying package configuration, since apt-utils is not installed
エラーはなにか関係がありますか?
Amazon Linux 2を利用しているので、MariaDBです。
bundle exec cap production deploy 1:in `block (2 levels) in execute' /Users/user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ec2-user@54.249.219.192: rake exit status: 1 (SSHKit::Runner::ExecuteError) Caused by: SSHKit::Runner::ExecuteError: Exception while executing as ec2-user@54.249.219.192: rake exit status: 1 rake stdout: Nothing written Caused by: SSHKit::Command::Failed: rake exit status: 1 rake stdout: Nothing written rake stderr: DEPRECATION WARNING: Including LoggerSilence is deprecated and will be removed in Rails 6.1. Please use `ActiveSupport::LoggerSilence` instead (called from block (2 levels) in require at /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:74) Tasks: TOP => deploy:migrate (See full trace by running task with --trace) The deploy has failed with an error: Exception while executing as ec2-user@54.249.219.192: Exception while executing as ec2-user@54.249.219.192: rake exit status: 1 rake stdout: Nothing written rake stderr: DEPRECATION WARNING: Including LoggerSilence is deprecated and will be removed in Rails 6.1. Please use `ActiveSupport::LoggerSilence` instead (called from block (2 levels) in require at /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:74) rake aborted! Mysql2::Error::ConnectionError: Unknown MySQL server host 'db' (2)
をしたのですが、
database
1default: &default 2 adapter: mysql2 3 encoding: utf8 4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 5 username: root 6 password: <%= ENV['DATABASE_PASSWORD'] %> 7 # socket: /tmp/mysql.sock 8 9 host: db 10 11development: 12 <<: *default 13 database: Books_development 14 15test: 16 <<: *default 17 database: Books_test 18 19production: 20 <<: *default 21 database: Books_production 22 23 username: root 24 password: <%= ENV['DATABASE_PASSWORD'] %> 25 socket: /var/lib/mysql/mysql.sock 26
dockercompose
1version: '3' 2services: 3 db: 4 image: mysql:5.6 5 environment: 6 MYSQL_ROOT_PASSWORD: example 7 MYSQL_DATABASE: root 8 ports: 9 - "4306:3306" 10 volumes: 11 - mysql-data:/var/lib/mysql 12 web: 13 build: . 14 environment: 15 DATABASE_PASSWORD: example 16 command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" 17 volumes: 18 - .:/Books 19 ports: 20 - 3000:3000 21 depends_on: 22 - db 23 tty: true 24 stdin_open: true 25volumes: 26 mysql-data:
deploy
1 2lock '3.14.1' 3 4set :application, 'Books' 5 6set :repo_url, 'git@github.com:shunichfukui/Books.git' 7 8set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads') 9 10set :rbenv_type, :user 11set :rbenv_ruby, '2.6.5' 12set :ssh_options, auth_methods: ['publickey'], 13 keys: ['~/.ssh/35783578a.pem'] 14 15set :unicorn_pid, -> { "#{shared_path}/tmp/pids/unicorn.pid" } 16 17set :unicorn_config_path, -> { "#{current_path}/config/unicorn.rb" } 18set :keep_releases, 5 19 20after 'deploy:publishing', 'deploy:restart' 21namespace :deploy do 22 task :restart do 23 invoke 'unicorn:restart' 24 end 25end
unicon
1app_path = File.expand_path('../../../', __FILE__) 2 3worker_processes 1 4 5working_directory "#{app_path}/current" 6 7listen "#{app_path}/shared/tmp/sockets/unicorn.sock" 8 9pid "#{app_path}/shared/tmp/pids/unicorn.pid" 10 11stderr_path "#{app_path}/shared/log/unicorn.stderr.log" 12 13stdout_path "#{app_path}/shared/log/unicorn.stdout.log" 14 15timeout 60 16 17 18preload_app true 19GC.respond_to?(:copy_on_write_friendly=) && GC.copy_on_write_friendly = true 20 21check_client_connection false 22 23run_once = true 24 25before_fork do |server, worker| 26 defined?(ActiveRecord::Base) && 27 ActiveRecord::Base.connection.disconnect! 28 29 if run_once 30 run_once = false # prevent from firing again 31 end 32 33 old_pid = "#{server.config[:pid]}.oldbin" 34 if File.exist?(old_pid) && server.pid != old_pid 35 begin 36 sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU 37 Process.kill(sig, File.read(old_pid).to_i) 38 rescue Errno::ENOENT, Errno::ESRCH => e 39 logger.error e 40 end 41 end 42end 43 44after_fork do |_server, _worker| 45 defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection 46end
bundle exec unicorn_rails -c config/unicorn.rb -E production -D bundler: failed to load command: unicorn_rails (/home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails) ArgumentError: config_file=config/unicorn.rb would not be accessible in working_directory=/var/www/current /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:592:in `working_directory' config/unicorn.rb:7:in `reload'
関係あるかわからないが
docker-compose up -d 済み
production.rbの内容はあっていると思います
server 'アドレスと一致', user: 'ec2-user', roles: %w{app db web}
deploy部分の git@github.com:shunichfukui/Books.git
を
git@github.com/shunichfukui/Books.git
にしてもだめでした。。
なにか足りない情報などがありましたら
遠慮なくお願いします
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/09/17 21:53
2020/09/18 06:11
2020/09/18 08:15
2020/09/18 08:28
2020/09/18 08:36
2020/09/18 08:46
2020/09/18 09:18 編集
2020/09/18 13:19 編集
2020/09/18 16:10
2020/09/18 22:27 編集