Sometimes we get software where all (or most of) settings are passed into application server via environment variables. But Passenger is not executed directly. So how do we pass ENV variables into it?
We need to create a little "wrapper" around Ruby, so it will be executed with our environment variables. Here's a little example (ruby_wrapper.sh):
#!/bin/sh export MONGODB_HOST=172.20.20.45 \ export MONGODB_PORT=27017 \ export MONGODB_DBNAME=openaudit \ export REDIS_HOST=172.20.20.45 \ export REDIS_PORT=6379 \ export REDIS_DB=10 \ exec "/usr/local/bin/ruby" "$@"
Script must be executable with chmod +x and should be placed in /usr/local/bin/ dir.
There is one more thing to do: tell Passenger where the wrapper is (vhost example):
<VirtualHost *:3001> ServerName 127.0.0.1 RackEnv production PassengerMaxPoolSize 30 PassengerUseGlobalQueue on PassengerRuby /usr/local/bin/ruby-wrapper DocumentRoot /home/smhtng/app/current/public/ PassengerUser openaudit <Directory /home/smhtng/app/current/public/> AllowOverride all Options -MultiViews </Directory> </VirtualHost>
The "magic" happens here: