Tag: rake

Phusion Passenger and environment variables with Ruby (Rake) applications

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):

export  MONGODB_HOST= \
export  MONGODB_PORT=27017 \
export MONGODB_DBNAME=openaudit \
export REDIS_HOST= \
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>
      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            

The "magic" happens here:

 PassengerRuby /usr/local/bin/ruby-wrapper

Global access to Rake DSL methods is deprecated – mały zgrzyt z Rake 0.9.0 i 0.9.1

Przechodząc na rake 0.9.1 możecie napotkać na taki (lub podobny) komunikat podczas odpalania zadań rake'owych na Railsowej aplikacji:

WARNING: Global access to Rake DSL methods is deprecated.  Please Include
    ...  Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method Susanoo::Application
#task called at /sciezka/rails/application.rb:215:in `initialize_tasks'

Rozwiązania są dwa. Pierwszym z nich jest powrót do 0.8.7:

sudo gem install rake -v 0.8.7
gem 'rake', '0.8.7'

Drugim jest dołączenie Rake::DSL do naszej aplikacji:

require 'rake'

module MyApp
  class Application &amp;lt; Rails::Application
    include Rake::DSL
    # dalsza część

Copyright © 2023 Closer to Code

Theme by Anders NorenUp ↑