アクティブ レコードを使用してデータベースに対してデータ ファイルをチェックする rake タスクを持つ ruby sinatra アプリがあります。このレーキ タスクをスケジュールに従って実行するために、everyone gem を使用しています。これはしばらくの間正常に動作していましたが、数日後にはエラーが発生し、ログ ファイルに書き込めないように見えます。エラーとスタック トレースをメールで送信してくれるレスキューがあります。
Broken pipe -
/usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/logger.rb:578:in `write'
/usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/logger.rb:578:in `warn'
/usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/logger.rb:578:in `rescue in write'
/usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/logger.rb:562:in `write'
/usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/logger.rb:382:in `add'
/usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/logger.rb:456:in `error'
/home/deployer/public/fulfillment_api/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:428:in `rescue in log'
/home/deployer/public/fulfillment_api/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:425:in `log'
/home/deployer/public/fulfillment_api/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:286:in `execute'
/home/deployer/public/fulfillment_api/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:220:in `execute'
/home/deployer/public/fulfillment_api/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:224:in `exec_query'
/home/deployer/public/fulfillment_api/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:233:in `select'
/home/deployer/public/fulfillment_api/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:24:in `select_all'
/home/deployer/public/fulfillment_api/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
/home/deployer/public/fulfillment_api/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:30:in `select_one'
/home/deployer/public/fulfillment_api/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:36:in `select_value'
/home/deployer/public/fulfillment_api/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/relation/finder_methods.rb:174:in `exists?'
/home/deployer/public/fulfillment_api/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/querying.rb:3:in `exists?'
/home/deployer/public/fulfillment_api/releases/20131010141756/app/models/clients/test/order_file.rb:39:in `block in create_new_orders'
when gem によって作成された crontab は次のようになります。
0 0,12 * * * /bin/bash -l -c 'cd /home/deployer/public/fulfillment_api/releases/20131010141756 && RACK_ENV=production bundle exec rake background_jobs:process_and_email['\''khartnet@gmail.com'\''] --silent'
奇妙なのは、このコマンドをコマンド ラインに貼り付けると、正常に動作することです。ユーザーをルートに切り替えて実行しても、問題なく動作します。crontab を実行したときにのみエラーが発生します。