index.md (2375B)
1 --- 2 title: "RubyInline in Shared Rails Environments" 3 date: 2008-05-23T00:00:00+00:00 4 draft: false 5 canonical_url: https://www.viget.com/articles/rubyinline-in-shared-rails-environments/ 6 --- 7 8 As an end-to-end web production company, we have a vested interest in 9 making Rails applications easier to deploy for both development and 10 production purposes. We've developed 11 [Tyrant](http://trac.extendviget.com/tyrant/wiki), a Rails app for 12 running Rails apps, and we're [eagerly 13 watching](https://www.viget.com/extend/passenger-let-it-ride/) as new 14 solutions are created and refined. 15 16 But it's a new market, and current solutions are not without their share 17 of obstacles. In working with both Tyrant and [Phusion 18 Passenger](http://www.modrails.com/), we've encountered difficulties 19 running applications that use 20 [RubyInline](http://www.zenspider.com/ZSS/Products/RubyInline/) to embed 21 C into Ruby code (e.g., 22 [ImageScience](http://seattlerb.rubyforge.org/image_science/classes/ImageScience.html), 23 my image processing library of choice). Try to start up an app that uses 24 RubyInline code in a shared environment, and you might encounter the 25 following error: 26 27 ``` 28 /Library/Ruby/Gems/1.8/gems/RubyInline-3.6.7/lib/inline.rb:325:in `mkdir': Permission denied - /home/users/www-data/.ruby_inline (Errno::EACCES) 29 ``` 30 31 RubyInline uses the home directory of the user who started the server to 32 compile the inline code; problems occur when the current process is 33 owned by a different user. "Simple," you think. "I'll just open that 34 directory up to everybody." Not so fast, hotshot. Try to start the app 35 again, and you get the following: 36 37 ``` 38 /home/users/www-data/.ruby_inline is insecure (40777). It may not be group or world writable. Exiting. 39 ``` 40 41 Curses! Fortunately, VigetExtend is here to help. Drop this into your 42 environment-specific config file: 43 44 ```ruby 45 temp = Tempfile.new('ruby_inline', '/tmp') 46 dir = temp.path 47 temp.delete 48 Dir.mkdir(dir, 0755) 49 ENV['INLINEDIR'] = dir 50 ``` 51 52 We use the [Tempfile](http://ruby-doc.org/core/classes/Tempfile.html) 53 library to generate a guaranteed-unique filename in the `/tmp` 54 directory, prepended with "ruby_inline." After storing the filename, we 55 delete the tempfile and create a directory with the proper permissions 56 in its place. We then store the directory path in the `INLINEDIR` 57 environment variable, so that RubyInline knows to use it to compile.