Phusion Passenger Standalone: How to pass a command line flag to ruby? - ruby

As part of a performance analysis, I'd like to run my rails app with several different rubies. All of them have the gem passenger (v5) installed and are able to run passenger start.
The question: How can I pass a flag (like --1.8) to my ruby interpreter? I'm using the version manager rbenv, but when I'm running
ruby --1.8 -S passenger start
using the interpreter jruby-1.7.27, the flag is non-persistant i.e. jruby does not run in the 1.8 compatibility mode.

I found that you can set an environment variable, which also applies to the instantiated passenger server:
env JRUBY_OPTS=--1.8 ruby -S passenger start
works like a charm.
See the JRuby FAQ for further details.

Related

How do I configure IntelliJ to use a specific rbenv version for Rake as an external tool?

My terminal is configured to use Ruby 1.8.7, via ruby env.
If I open the Terminal in IntelliJ and do ruby --version I get 1.8.7, which is correct.
I have an external tool which is essentially just a Rake task. I also want this to run using my rbenv managed Ruby 1.8.7, however, when I run the task, it defaults to using the system Ruby (2.0), and then bails because the gems aren't installed here.
The verbose output points all the way back to usr/bin/rake - is there any way I can configure IntelliJ to use a different version of Rake?
I'm using IntelliJ IDEA Ultimate 2016.3, on a Mac running 10.12
Use an absolute path as the Program parameter in the external tool set up to the Rake shim in rbenv:
/Users/someuser/.rbenv/shims/rake

Why does my Rails app not see installed gems?

Running Ubuntu 10, RVM, Passenger and apache2. Trying to configure and get Redmine running.
First, I set my default Ruby binary to /usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby. That's the output of which ruby. Output of which gem is /usr/local/rvm/rubies/ruby-1.9.2-p180/bin/gem. I think that side of things is set up properly.
I know Passenger is running, because I'm getting an error screen, with this error:
Error message:
Missing the i18n 0.4.2 gem. Please gem install -v=0.4.2 i18n
Update The error that passenger is producing is coming from the boot.rb file. I went and made a gist of the application's boot.rb file.
When I do check to see if that gem is installed, here's the output.
# gem list
# ... list truncated ...
# i18n (0.4.2)
(full gist of installed gems here)
Really? Let's first make sure passenger.conf is going to the right Ruby installation...
passenger.conf
PassengerRuby /usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby
>:| So now, I go onto SSH into the application directory, and what have you, script/server starts normally. I'm a little more than confused. Clearly the Ruby installation that Passenger is configured to has the Gem it says is missing, installed, and additionally, the application doesn't falter on a start up. Which makes me think it's a Passenger problem.
Using RVM with Passenger is a bit complicated, maybe this link about using Ruby and Passenger will help.

Sinatra doesn't load when running a ruby app

I'm trying to run a Ruby application that requires Sinatra within Ubuntu 10.10. I'm new to the 3 of these technologies so I understand if this question looks dumb to you.
Yesterday I installed ruby doing...
sudo apt-get install ruby1.9.1-full
And sinatra by doing...
sudo gem install sinatra
This is the code I'm trying to run:
require 'rubygems'
require 'sinatra'
get '/' do
"Hi Alex!"
end
When I do ruby1.9.1 -rubygems app.rb nothing happens (Ruby is properly installed since I tried running apps that don't require sinatra and they work OK).
$ ls
app.rb
$
$ ruby1.9.1 app.rb
$
$ ruby1.9.1 -rubygems app.rb
$
I know it should open Sinatra and tell me which port it is listening to.
I've been looking for help through the web and read several of the threads created within this forum but nothing I've tried has worked out for me.
What could be happening here?
Thanks
There was a similar problem with sinatra 1.0 on ruby 1.9.2. The answer there was to add enable :run to your code.
Have a look at the docs for the :run configuration - if you're going to be deploying to a server you'll want to do something like enable :run if __FILE__ == $0 so that you only start the built-in server during development when you need it.
Strictly speaking your code is correct and should run okay, and in fact it does with ruby 1.8.7 and 1.9.2. The problem seems to be running it with ruby 1.9.1. In general 1.9.1 seems to be fairly outdated and you should probably look to upgrade to 1.9.2 if you can. If Ubuntu doesn't have any packages for 1.9.2 take a look at rvm. (In fact if you're going to be doing ruby development rvm is worth a look anyway).
Update:
I managed to get ruby 1.9.1 compiled to test this, and your code worked ok. Also a bit of googling suggests that the Ubuntu ruby1.9.1 package provides ruby 1.9.2 anyway. So there seems to be something else going on causing :run not to be set when running the file directly, though I don't know what that could be.
Another update:
Looking at the Ubuntu Sinatra package it looks like it's at version 1.0. It could be that your setup is using the Ubuntu
package and ignoring the more recent version installed via rubygems. This could explain what's happening. If so this isn't a "a similar problem" to ruby 1.9 and sinatra 1.0 like I suggested above, it's the same problem!
Yet another update:
A couple of things have occurred to me. You can check what version of Sinatra you're actually using with something like puts Sinatra::VERSION after require 'sinatra'. Also, it looks like there is a gem1.9.1 command that corresponds to ruby1.9.1. It looks like when you installed sinatra with sudo gem install sinatra the latest version got installed into the ruby 1.8 install, and left ruby 1.9 with the Ubuntu packaged Sinatra 1.0. If you haven't switched over to rvm yet, you could try sudo gem1.9.1 install sinatra.

How to deploy a Test App on Dreamhost Rails 3.0.4?

All this weekend I have been trying to setup a Rails 3.0.4 app in production on a Dreamhost shared server. I have followed this wiki article to have my own set of rubygems setup on the server. Furthermore, I also installed rvm and ruby 1.9.2 using the following command:
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
rvm use 1.9.2 --default
Doing ruby -v returns ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux], so I believe rvm has installed the version of ruby correctly.
I created my app forcing the use of a mysql database, and then generated an articles controller:
rails new test_app -d mysql
cd test_app
rails g scaffold articles title:string body:text
Now when I visit the domain I see the usual "Welcome aboard You’re riding Ruby on Rails!" screen, but if I click the "About your application’s environment" link I get what looks like to be some kind of passenger error:
Ruby (Rack) application could not be started
The application has exited during startup (i.e. during the evaluation of config/environment.rb). The error message may have been written to the web server's log file. Please check the web server's log file (i.e. not the (Rails) application's log file) to find out why the application exited. If that doesn't help, then please use the backtrace below to debug the problem.
Lastly, if I SSH into the server and just do rails s I can see the app functioning correctly on port 3000.
I have never put an app into production before, so I am very confused. Is passenger not using the RVM version of ruby? Is these even possible on a DreamHost shared server? What do I have to do to rectify this problem?
Any help is appreciated, Thanks.
I've been able to successfully get a Rails 3.2.2 app deployed to Dreamhost. Here are some notes I've written for myself.
On the local development machine
First off, Dreamhost Passenger is based on Ruby 1.8.7, not Ruby 1.9.2. Because of this, Dreamhost won't like some of your Ruby code because it has some of the new key value syntax. So look for any code like this:
key: "value"
and change it to Ruby 1.8.7 style (which Ruby 1.9.2 also can understand):
:key => "value"
I found that you can find this code by doing something like this...this can be done more efficiently on a *nix box, but this is how I did it in Windows with some *nix commands installed:
egrep -r -i "^.*\w: .*$" . | grep rb
After fixing the syntax, you'll want to bundle up your gems so Dreamhost doesn't complain about your rack version.
$> bundle package
On the Server (aka Dreamhost)
(Get your files on dreamhost. Personally, I commit and push changes into a git remote repository, then git pull them down to a private folder on dreamhost. After they are there, I copy them into the Passenger folder)
Then I run these commands from the Rails application folder (/home/username/www.myapp.com/):
$> bundle install --path vendor/bundle --local
$> rake db:migrate RAILS_ENV="production"
$> bundle exec rake assets:precompile
$> touch tmp/restart.txt
Voila, this seems to work. If it still isn't working, check the log/production.log.
I've bumped into the same problem. I believe it's because passenger is not loading the ruby interpretor you specify in rvm as it or gems you specify. You'll likely see that the gems being loaded refer to /usr/...
I did bump into this http://blog.ninjahideout.com/posts/the-path-to-better-rvm-and-passenger-integration, but I haven't been able to get around that Dreamhost is using ruby 1.8.7 in it's passenger configuration and you and I would like to use 1.9.2

How run a RoR application using a custom Ruby installation?

On my Mac Os running Snow Leopard 10.6.5 I successfully installed Ruby 1.9.2 performing these steps so that, in the Terminal, I have these results:
$ ruby -v
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.5.0]
$ which ruby
/usr/local/bin/ruby
Now, when I run my RoR application and I get an error (in my case a "SocketError"), I have the following RoR "Framework Trace":
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in `initialize'
...
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:772:in `get'
activeresource (3.0.1) lib/active_resource/connection.rb:112:in `send'
...
that means my RoR application is still running on the previous version of Ruby (v1.8.7)!!!
How can I run my RoR application using my new Ruby installation (v 1.9.2)?
P.S. I: all my RoR applications are located in /usr/< my_mac_account_name >/Sites directory
P.S. II: I am using Phusion Passenger
Not a solution for this particular problem, but you should really really use RVM to manage your Ruby installations. That's the easiest way to be sure you're using X version of Ruby (and thus it's related gems). Then you can switch between versions like this:
rvm use 1.9.2 #begin using Ruby 1.9.2
I suspect that your phusion passenger was built against the system Ruby, not the one you've got in /usr/local. Rebuild phusion Passenger but modify the path in the environment you're building phusion in.
On a linux:
export PATH=/usr/local/bin:$PATH
Not precisely sure of the PATH settings for Mac machines.
Reference:
http://www.modrails.com/documentation/Users%20guide%20Apache.html#_preparation_gem_and_source_tarball_only

Resources