Phusion passenger is overriding my database config - ruby

I am using nginx with Phusion Passenger to bootload a ruby on rails application, if I run the application like
rails s -e production
It does connect correctly to the database, but when bootloaded from nginx with passenger it tries to use root to the database, like ignoring the config files.
I already tried giving permissions, but doesnt look like there is the problem, I already opened the 3 possible host names for root, which could be "localhost", "%" and "127.0.0.1", but in any case it should be openning a connection with root
I would say something is weird on how passenger behaves or that somewhere (not in the app) is ignoring the database.yml or overriding the credentials

in my opinion, I think you should try Passenger Standalone that is what I use and it works fine.

Related

Unicorn not reading ENV variables

I'm having some issues with SECRET_KEY_BASE setting on our production Ubuntu server with Unicorn and nginx. I added the variable to .bashrc and its reading fine when I try echo $SECRET_KEY_BASE, but for some reason I'm getting the following error:
app error: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml` (RuntimeError)
Also, when I try to access the variable with ENV["SECRET_KEY_BASE"] from within the console in production environment, I can read it fine.
I tried restarting Unicorn and server and it doesn't help. Any idea why this is happening?
You may need to add the variables to the unicorn.conf file, since it seems you are launching Unicorn with a different user or without sourcing your .bashrc.
In any case, I suggest you use dotenv gem to store your env variables in a .env file within your project. That is the cleanest way I know. If you need to have capistrano integration and handle all the different environments with ease, you can also use dotenv-deployment gem.

Passenger Max Requests on Heroku

It it possible to setup Passenger to use a PassengerMaxRequests on Heroku? From what I can tell, Heroku requires the passenger configuration to happen within a Procfile like so:
web: bundle exec passenger start -p $PORT --max-pool-size 4
I tried --max-requests but get an invalid option exception. It also doesn't appear under heroku start --help. Any way to get this parameter (or any of the other parameters from the docs) working with a Procfile?
It looks like you should follow the Passenger Standalone Advanced Configuration guide, and create an nginx config file (not apache), since it seems the standalone passenger actually just comes with nginx.
passenger start --nginx-config-template nginx.conf.erb
And then you should be able to set passenger_max_requests

Heroku database migrations failing with "unable to connect"

I'm having a heck of a time getting a Postgres database on a heroku instance to allow me to run database migrations.
I'm also incredibly new to Heroku, so apologies in advance if this is a silly question :)
So my app is on Heroku and can successfully connect to its database - it just can't do anything because the tables aren't set up. My connect block in the code looks like this:
if ENV['DATABASE_URL']
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
else
ActiveRecord::Base.establish_connection(dbconfig['development'])
end
The environment variable is set by Heroku at deploy time - this also works. If I jump in after everything is initialized with Pry or something, connection works great. The dbconfig hash is populated from my db/config.yml which works fine locally.
I can rake db:migrate on my local system just fine. However, trying this via heroku run rake db:migrate gives me an error dump beginning with:
rake aborted!
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
The only other odd thing I can think of here is that I'm using a gem called standalone migrations (declared in Gemfile) which should allow me to do this without pulling in the rest of Rails.
So, my question, why aren't my migrations running?

Rails app only pointing to default rails index page

So I am new to deploying to an Ubuntu Server (12.04). I have nginx and unicorn installed. Everything seems to be working except for the fact that I don't know how to point it to my app. Currently I am pointing to 'home/administrator/apps/my_site/current/public' however all my files are in 'home/administrator/apps/my_site/app/views/'. I am currently only pointing to the static files like the error htmls and the default rails index.html. How do I get nginx to point to my views/app?
Thanks.
If you're using Nginx + Unicorn then you don't point Nginx at any path, you run up unicorn on the server and then have Nginx proxy all it's requests to the unicorn instance. I would recommend looking at using foreman and then it's foreman export upstart which exports ubuntu upstart scripts for controlling unicorn.
This link gives you details on how to config your nginx site.

Ruby app only works when Passenger is "disabled"

I have deployed a Sinatra application on an Ubuntu server using Apache and Passenger. Through some trial and error, I realize the app only works when the passenger module is disabled.
$ a2dismod passenger
After an Apache restart, the app runs as expected.
If I re-enable the module...
$ a2enmod passenger
...I see this warning upon Apache restart:
[warn] module passenger_module is already loaded, skipping
and the app stops working. Apache responds, serving the contents of the vhost's document root, but is not recognized by Passenger.
I'm glad my app works, but I'm not sure how to explain the reversed effect of enabling/disabling the passenger module.
I ran into the same problem: if you follow passenger installing instruction with this version of Apache you may actually tell Apache to load passenger twice.
Before adding the 3 famous lines to your Apache configuration file:
LoadModule passenger_module /usr/…/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.11
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.2-p290/ruby
Check the configuration file apache2.conf for lines like these:
# Include module configuration:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
If these lines do exists it means that on start your Apache server will include every *.conf and *.load file from /mods-available to /mods-enabled and than load them.
So if you run in the concerning warning message it means you are loading passenger module twice!
You can take advantage of this Apache feature going to /mods-available, looking for passenger.conf and passenger.load files and edit them instead of apache2.conf.
The ‘LoadModule passenger_module’ line goes into passenger.load, while the other 2 ‘PassengerRoot’ and ‘PassengerRuby’ lines go into passenger.conf.
Then restart your server and you’ll be fine.
More about this issue here: http://www.duccioarmenise.net/ruby-on-rails/warn-module-passenger_module-is-already-loaded/
This most likely means you've specified 'LoadModule passenger_module ...' twice. The first entry is somewhere not in passenger.conf, the second entry is in passenger.conf.

Resources