-
Notifications
You must be signed in to change notification settings - Fork 137
ENV Isolation
Karol Bucek edited this page Jun 17, 2014
·
2 revisions
You can isolate your Ruby application's environment by clearing out the ENV variable by setting the jruby.runtime.env
context parameter to false
sample web.xml deployment descriptor :
<web-app>
<context-param>
<param-name>jruby.runtime.env</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>jruby.min.runtimes</param-name>
<param-value>1</param-value>
</context-param>
<context-param>
<param-name>jruby.max.runtimes</param-name>
<param-value>1</param-value>
</context-param>
<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
</listener>
</web-app>
It accepts comma new line separated values as well, to allow for fine grained customizations :
<context-param>
<param-name>jruby.runtime.env</param-name>
<param-value>
DATABASE_URL=mysql://192.168.1.11/mydb
PATH=/usr/local/bin,HOME=/home/tomcat,NAMES=Jozko, Ferko,Janko,GEM_HOME=""
</param-value>
</context-param>
will end up setting DATABASE_URL
, PATH
, HOME
, NAMES
and GEM_HOME
keys within Ruby runtimes ENV
hash.
Context parameters such as jruby.runtime.env
are easy to set in using config/warble.rb :
Warbler::Config.new do |config|
# Features: additional options controlling how the jar is built.
# Currently the following features are supported:
# - gemjar: package the gem repository in a jar file in WEB-INF/lib
# - executable: embed a web server and make the war executable
# - compiled: compile .rb files to .class files
# config.features = %w(gemjar)
# Additional files/directories to include, above those in config.dirs
config.includes = FileList["db"]
# Additional files/directories to exclude
# config.excludes = FileList["lib/tasks/*"]
# ...
config.webxml.jruby.compat.version = "2.0"
config.webxml.jruby.runtime.env = "DATABASE_URL=mysql://192.168.1.11/mydb\n" <<
'PATH=/usr/local/bin,HOME=/home/tomcat,NAMES=Jozko, Ferko,Janko,GEM_HOME=""'
# Control the pool of Rails runtimes. Leaving unspecified means
# the pool will grow as needed to service requests. It is recommended
# that you fix these values when running a production server!
# If you're using threadsafe! mode, you probably don't want to set these values,
# since 1 runtime(default for threadsafe mode) will be enough.
# config.webxml.jruby.min.runtimes = 2
# config.webxml.jruby.max.runtimes = 4
end