AWSでテスト運用していた画像投稿サービスがある日突然、画像の投稿が出来なくなりました。
ただ、それ以外には全く問題なくアクセスできます。あくまで、画像の投稿"だけ"が出来なくなりました。
###エラーの内容
①原因を探るため、運用中のAWSのEC2にSSHした時点で、以下のような文言が表示された
/home/サービス名/.rbenv/libexec/rbenv-init: 行 131: ヒアドキュメント用一時ファイルを作成できません: デバイスに空き領域がありません
②一旦停止したpumaを再起動しようとすると以下のエラーが表示
log writing failed. No space left on device @ io_write - /var/www/rails/サービス名/log/production.log log writing failed. No space left on device @ io_write - /var/www/rails/サービス名/log/production.log log writing failed. No space left on device @ io_write - /var/www/rails/サービス名/log/production.log log writing failed. No space left on device @ io_write - /var/www/rails/サービス名/log/production.log * Listening on tcp://0.0.0.0:3000 * Listening on unix:///var/www/rails/サービス名/tmp/sockets/puma.sock bundler: failed to load command: puma (/home/サービス名/.rbenv/versions/2.3.1/bin/puma) Errno::ENOSPC: No space left on device @ fptr_finalize - /var/www/rails/サービス名/tmp/pids/puma.pid /home/サービス名/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.2/lib/puma/launcher.rb:130:in `close' /home/サービス名/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.2/lib/puma/launcher.rb:130:in `open' /home/サービス名/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.2/lib/puma/launcher.rb:130:in `write_pid' /home/サービス名/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.2/lib/puma/launcher.rb:105:in `write_state' /home/サービス名/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.2/lib/puma/single.rb:90:in `run' /home/サービス名/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.2/lib/puma/launcher.rb:172:in `run' /home/サービス名/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.2/lib/puma/cli.rb:74:in `run' /home/サービス名/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.2/bin/puma:10:in `<top (required)>' /home/サービス名/.rbenv/versions/2.3.1/bin/puma:23:in `load' /home/サービス名/.rbenv/versions/2.3.1/bin/puma:23:in `<top (required)>'
③ df -i の結果は以下の通り。
ファイルシス Iノード I使用 I残り I使用% マウント位置 devtmpfs 124692 428 124264 1% /dev tmpfs 127414 1 127413 1% /dev/shm /dev/xvda1 524288 100115 424173 20% /
④ nginx.error.logには以下が表示
[alert] 2773#0: *607106 write() to "/var/log/nginx/access.log" failed (28: No space left on device) while logging request, client: 172.31.17.201, server: "サービス名ドメイン", request: "GET / HTTP/1.1", host: "172.31.31.81:10001"
###結論(対応内容)
①production.logの中身を全てクリアした
②production.rbに以下のコードを追加した。
その結果、再度問題なく投稿できるようになりました。
ruby
1config.logger = Logger.new("log/production.log", 5, 10 * 1024 * 1024)
production.rbの全コードは以下の通り
ruby
1Rails.application.configure do 2 # Settings specified here will take precedence over those in config/application.rb. 3 4 # Code is not reloaded between requests. 5 config.cache_classes = true 6 7 # Eager load code on boot. This eager loads most of Rails and 8 # your application in memory, allowing both threaded web servers 9 # and those relying on copy on write to perform better. 10 # Rake tasks automatically ignore this option for performance. 11 config.eager_load = true 12 13 # Full error reports are disabled and caching is turned on. 14 config.consider_all_requests_local = false 15 config.action_controller.perform_caching = true 16 17 # Disable serving static files from the `/public` folder by default since 18 # Apache or NGINX already handles this. 19 config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 20 # config.public_file_server.enabled = true 21 22 # Compress JavaScripts and CSS. 23 config.assets.js_compressor = :uglifier 24 # config.assets.css_compressor = :sass 25 26 # Do not fallback to assets pipeline if a precompiled asset is missed. 27 config.assets.compile = false 28 29 # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 30 31 # Enable serving of images, stylesheets, and JavaScripts from an asset server. 32 # config.action_controller.asset_host = 'http://assets.example.com' 33 34 # Specifies the header that your server uses for sending files. 35 # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 36 # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 37 38 # Mount Action Cable outside main process or domain 39 # config.action_cable.mount_path = nil 40 # config.action_cable.url = 'wss://example.com/cable' 41 # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] 42 43 # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 44 # config.force_ssl = true 45 46 # Use the lowest log level to ensure availability of diagnostic information 47 # when problems arise. 48 config.log_level = :debug 49 50 # Prepend all log lines with the following tags. 51 config.log_tags = [ :request_id ] 52 53 # Use a different cache store in production. 54 # config.cache_store = :mem_cache_store 55 56 # Use a real queuing backend for Active Job (and separate queues per environment) 57 # config.active_job.queue_adapter = :resque 58 config.action_mailer.perform_caching = false 59 60 # Ignore bad email addresses and do not raise email delivery errors. 61 # Set this to true and configure the email server for immediate delivery to raise delivery errors. 62 # config.action_mailer.raise_delivery_errors = false 63 64 # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 65 # the I18n.default_locale when a translation cannot be found). 66 config.i18n.fallbacks = true 67 68 # Send deprecation notices to registered listeners. 69 config.active_support.deprecation = :notify 70 71 # Use default logging formatter so that PID and timestamp are not suppressed. 72 config.log_formatter = ::Logger::Formatter.new 73 74 # Use a different logger for distributed setups. 75 # require 'syslog/logger' 76 # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 77 78 if ENV["RAILS_LOG_TO_STDOUT"].present? 79 logger = ActiveSupport::Logger.new(STDOUT) 80 logger.formatter = config.log_formatter 81 config.logger = ActiveSupport::TaggedLogging.new(logger) 82 end 83 84 # Do not dump schema after migrations. 85 config.active_record.dump_schema_after_migration = false 86 87 # Exceptions Handler 88 config.exceptions_app = ->(env) { ErrorsController.action(:show).call(env) } 89 90 config.action_mailer.default_url_options = { host: 'サービスのドメインを設定中' } 91 92 # http://rails.hatenadiary.jp/entry/2013/02/06/201302 93 config.logger = Logger.new("log/production.log", 5, 10 * 1024 * 1024) 94end
###自分なりの解釈
logファイルが大きくなりすぎて容量がなくなったのでは?
→production.logの中身を空にし、一定期間でファイルを自動削除するようにしたので、問題がなくなった。
###知りたいこと
いかんせん、このようなことが全くの初めてで、今回の自分の対応でOKなのかどうか自信がありません。。
①私が対応した内容で問題ないかどうか
②そのエラーならこういう事もやっておいたら再発しないよというものがありましたら、教えて頂きたいです。
何卒宜しくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/15 07:40