2

我认为 ruby​​ 1.9.3 无法在 /tmp 目录中创建临时文件。问题错误信息:

Status: 500 Internal Server Error No such file or directory   /tmp/RackRewindableInput20121031-8340-1qko694.lock  
/lib/ruby/1.9.1/tempfile.rb:346:in rmdir'  
/lib/ruby/1.9.1/tempfile.rb:346:in rmdir'  
/lib/ruby/1.9.1/tempfile.rb:338:in ensure in locking'  
/lib/ruby/1.9.1/tempfile.rb:338:in locking'  
/lib/ruby/1.9.1/tempfile.rb:144:in block in initialize'  
/lib/ruby/1.9.1/tmpdir.rb:133:in create'  
/lib/ruby/1.9.1/tempfile.rb:134:in initialize'  
/lib/ruby/gems/1.9.1/gems/passenger-3.0.12/lib/phusion_passenger/utils/rewindabl‌​e_input.rb:86:in new' 
4

1 回答 1

1

报告相同的错误,当我尝试使用 Prince xml 生成 pdf 文件时发生:

在本地机器上运行良好,开发和生产运行 webrick,但乘客导致崩溃。

这是我的回溯(短版):

  Compiled print/print_core.css  (1ms)  (pid 14275)
  Completed 500 Internal Server Error in 236ms

  Errno::ENOENT (No such file or directory - /*** PATH DELETED ***/tmp/cache/assets/10948d89a043b6251405277a36d3e0e2.cache20130517-14275-1l2wvu7.lock):
    /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tempfile.rb:346:in `rmdir'
    /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tempfile.rb:346:in `rmdir'
    /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tempfile.rb:338:in `ensure in locking'
    /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tempfile.rb:338:in `locking'
    /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tempfile.rb:144:in `block in initialize'
    /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tmpdir.rb:133:in `create'
    /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tempfile.rb:134:in `initialize'
    activesupport (3.2.9) lib/active_support/core_ext/file/atomic.rb:19:in `new'
    activesupport (3.2.9) lib/active_support/core_ext/file/atomic.rb:19:in `atomic_write'
    activesupport (3.2.9) lib/active_support/cache/file_store.rb:91:in `write_entry'
    activesupport (3.2.9) lib/active_support/cache/strategy/local_cache.rb:140:in `write_entry'
    activesupport (3.2.9) lib/active_support/cache.rb:364:in `block in write'
    activesupport (3.2.9) lib/active_support/cache.rb:520:in `instrument'
    activesupport (3.2.9) lib/active_support/cache.rb:362:in `write'
    sprockets (2.2.2) lib/sprockets/caching.rb:90:in `cache_set'
    sprockets (2.2.2) lib/sprockets/caching.rb:53:in `cache_set_hash'
    sprockets (2.2.2) lib/sprockets/caching.rb:24:in `cache_asset'
    sprockets (2.2.2) lib/sprockets/index.rb:92:in `build_asset'
    sprockets (2.2.2) lib/sprockets/base.rb:169:in `find_asset'
    sprockets (2.2.2) lib/sprockets/index.rb:60:in `find_asset'
    sprockets (2.2.2) lib/sprockets/bundled_asset.rb:16:in `initialize'
    sprockets (2.2.2) lib/sprockets/base.rb:252:in `new'
    sprockets (2.2.2) lib/sprockets/base.rb:252:in `build_asset'
    sprockets (2.2.2) lib/sprockets/index.rb:93:in `block in build_asset'
    sprockets (2.2.2) lib/sprockets/caching.rb:19:in `cache_asset'
    sprockets (2.2.2) lib/sprockets/index.rb:92:in `build_asset'
    sprockets (2.2.2) lib/sprockets/base.rb:169:in `find_asset'
    sprockets (2.2.2) lib/sprockets/index.rb:60:in `find_asset'
    /var/www/*** PATH DELETED ***_core/lib/princely/pdf_helper.rb:83:in `asset_file_path'
    /var/www/*** PATH DELETED ***_core/lib/princely/pdf_helper.rb:29:in `block in make_pdf'
    /var/www/*** PATH DELETED ***_core/lib/princely/pdf_helper.rb:29:in `collect'
    /var/www/*** PATH DELETED ***_core/lib/princely/pdf_helper.rb:29:in `make_pdf'
    /var/www/*** PATH DELETED ***_core/lib/custom_pdf_helper.rb:28:in `make_pdf_with_defaults'
    /var/www/*** PATH DELETED ***_core/lib/custom_pdf_helper.rb:59:in `make_tmp_pdf'
    /var/www/*** PATH DELETED ***_concept/app/controllers/pdf_builder_controller.rb:171:in `build_pdf'

问题是由乘客以用户“nobody”运行时的权限问题引起的,这种情况发生在 root 拥有的配置文件时。

在您的 apache/passenger conf 中设置以下内容使其工作

PassengerDefaultUser www-data # should be same as apache user

将 apache/rails 应用程序使用的所有文件/文件夹设置为

chown www-data:www-data

(在我的情况下,它是chown -R tmp/)使它工作。

注意:我认为,实际上当 ruby​​ 尝试实际写入临时文件时会发生错误,但显然此时没有错误发生。在下一步中,ruby 尝试删除一个不存在的临时文件并崩溃。

希望它有所帮助!

于 2013-05-17T15:45:12.953 回答