【Rails】log writing failed. No space left on deviceというエラーに関する対処法
- 評価
- クリップ 0
- VIEW 3,326
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に以下のコードを追加した。
その結果、再度問題なく投稿できるようになりました。
config.logger = Logger.new("log/production.log", 5, 10 * 1024 * 1024)
production.rbの全コードは以下の通り
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# config.public_file_server.enabled = true
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
# Exceptions Handler
config.exceptions_app = ->(env) { ErrorsController.action(:show).call(env) }
config.action_mailer.default_url_options = { host: 'サービスのドメインを設定中' }
# http://rails.hatenadiary.jp/entry/2013/02/06/201302
config.logger = Logger.new("log/production.log", 5, 10 * 1024 * 1024)
end
自分なりの解釈
logファイルが大きくなりすぎて容量がなくなったのでは?
→production.logの中身を空にし、一定期間でファイルを自動削除するようにしたので、問題がなくなった。
知りたいこと
いかんせん、このようなことが全くの初めてで、今回の自分の対応でOKなのかどうか自信がありません。。
①私が対応した内容で問題ないかどうか
②そのエラーならこういう事もやっておいたら再発しないよというものがありましたら、教えて頂きたいです。
何卒宜しくお願いいたします。
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 過去に投稿した質問と同じ内容の質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
0
参考情報
- Railsアプリでローテーションの設定 http://skygrid.co.jp/jojakudoctor/rails-log-rotate/
- Rails5 + Pumaを実現する上で気をつけるべき4つの設定 http://qiita.com/selmertsx/items/a0c94f201b0130988910
- Railsプロジェクトでまず最初にやっておきたい設定 http://blog.mmmcorp.co.jp/blog/2016/11/11/rails-initial-settting/
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 88.13%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
2017/01/15 16:40