I am trying to setup a spring cloud netflix eureka server. I'm trying to create multiple profiles to be able to run multiple instances of the application at a time locally without much hastle.
Tried using the VM Option spring.profiles.active the spring boot app doesn't seem to honoring this option
I Tried to override the properties in application.properties using environment variables but this did not work either. For example the server.port value defaults to 8080. This can be overridden in application.properties. However, if I try to override this using environment variables it is not respected.
application.properties
server.port=8082
application-local-1.properties
server.port=8083
application-local-2.properties
server.port=8084
I've tried running the application using the VM Option `-Dspring.profiles.active" something like
I've tried setting this on the environment variable
I'm trying to basically have the application read from the correct profile.
==================
My IDE setup
On Intellij I've setup a gradle run configuration with the following configuration parameters
Gradle Project: my-test-project
Tasks: bootRun
VM Options: -Dspring-boot.run.profiles=local
Environment variables: spring-boot.run.profiles=local
I'm not specifying VM options and env at the same time, just one or the other
Related
I have my configuration for my Scala Play application in my application.conf file.
For now, everytime I want to change the configuration I have to make a deployment.
Can anybody help me finding out, how to expose the Configuration as a MBean?
I would like to change the configuration without deployment.
Didn't find any documentation on this.
Redeploy just for a configuration change is really boring and I understand you want to avoid that.
Changing configuration while the application is running is a risky operation and I would not recommend going in that direction.
But there are a few techniques that the framework provides that would only require a restart of the application.
Play allows you to point to an external file with your configuration
$ your-app -Dconfig.file=/full/path/to/conf/application-prod.conf
Besides that in your conf file you can use environment variables, so you can configure different servers differently using the same application.conf
my.key = defaultvalue
my.key = ${?MY_KEY_ENV}
And run your app using
$ your-app -DMY_KEY_ENV=bar
Reference:
https://www.playframework.com/documentation/2.4.x/Production
https://www.playframework.com/documentation/2.4.x/ProductionConfiguration
I've been setting up my rails application to run under jruby/warbler inside a java container (JBoss/wildfly). I'm used to running my rails apps on linux machines, more or less with init.d scripts and the like, and I've been using DATABASE_URL to set the connection without putting my credentials in the source.
Warbler itself is created a pre-packaged WAR, I can deploy that to wildfly(jboss) fine.. but there is no examples of how to set environment variables in the context of that application.
I've googled links, but they are cryptic as hell, there's even a stack overflow question here, but the accepted answer seems to be make your own service between to do this?.
Is there an easy way to pass config to wars in jboss?, or do all java enterprisey applications just store the credentials/urls in the war themselves O.O
You could setup a datasource on the application server
https://docs.jboss.org/author/display/WFLY8/DataSource+configuration
And in your application you will need to use ActiveRecord-JDBC-Adapter
https://github.com/jruby/activerecord-jdbc-adapter
Or you can also set environment variables in the application servers's startup script (bin/standalone.sh or bin/domain.sh)
if you're using Warbler (JRuby-Rack) the environment can be isolated using a context-parameter setting in the deployment descriptor e.g. :
<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
</param-value>
</context-param>
it's pretty easy to set with Warbler's configuration file (generate one at config/warbler.rb using warble config)
https://github.com/jruby/jruby-rack/wiki/ENV-Isolation#warbler
In particular, for test-cases, I want to keep the test database separate so that the test cases don't interfere with development or production databases.
What are some good practices for separating development, test and production environments?
EDIT1: Some context
In Ruby On Rails, there are different configuration files by convention for different environments. So does Play! 2 also support that ?
Or, do I have to cook the configuration files, and then write some glue code that selects the appropriate configuration files ?
At the moment if I run sbt test it uses development database ( configured as "default" in conf/application.conf ). However I would like Play!2 to use a different test database.
EDIT2: On commands that play provides
For Play! 2 framework, I observed this.
$ help play
Welcome to Play 2.2.2!
These commands are available:
-----------------------------
...OUTPUT SKIPPED...
run <port> Run the current application in DEV mode.
test Run Junit tests and/or Specs from the command line
start <port> Start the current application in another JVM in PROD mode.
...OUTPUT SKIPPED...
There are three well defined commands for "test", "development" and "production" instances which are:
test: This runs the test cases. So it should automatically select test configuration.
run <port>: this runs the development instance on the specified port. So this command should automatically select development configuration.
start <port>: this runs the production instance on the specified port. So this should automatically select production configuration.
However, all these commands select the values that are provided in conf/application.conf. I feel there is some gap to be filled here.
Please do correct me if I am wrong.
EDIT3: Best approach is using Global.scala
Described here: How to manage application.conf in several environments with play 2.0?
Good practice is keeping separate instances of the application in separate folders and synching them i.e. via git repo.
When you want to keep single instance you can use alternative configuration file for each environment.
In your application.conf file there is an entry (or entries) for your database, e.g. db.default.url=jdbc:mysql://127.0.0.1:3306/devdb
The conf file can read environment variables using ${?ENV_VAR_NAME} syntax, so change that to something like db.default.url=${?DB_URL} and use environment variables.
A simpler way to get this done and manage your configuration easier is via GlobalSettings. There is a method you can override and that its name is "onLoadConfig". Try check its api at API_LINK
Basically on your conf/ project folder, you'll setup similar to below:
conf/application.conf --> configurations common for all environment
conf/dev/application.conf --> configurations for development environment
conf/test/application.conf --> configurations for testing environment
conf/prod/application.conf --> configurations for production environment
So with this, your application knows which configuration to run for your specific environment mode. For a code snippet of my implementation on onLoadConfig try check my article at my blog post
I hope this is helpful.
I am wondering if there is a way to pass a value for RAILS_ENV directly into the Torquebox server without going through a deployment descriptor; similar to how I can pass properties into Java with the -D option.
I have been wrestling with various deployment issues with Torquebox over the past couple weeks. I think a large part of the problem has to do with packaging the gems into the Knob file, which is the most practical way for managing them on a Window environment. I have tried archive deployment and expanded deployment; with and without external deployment descriptor.
With an external deployment descriptor, I found the packaged Gem dependencies were not properly deployed and I received errors about missing dependencies.
When expanded, I had to fudge around a lot with the dependencies and what got included in the Knob, but eventually I got it to deploy. However, certain files in the expanded Knob were marked as failed (possible duplicate dependencies?), but they did not affect the overall deployment. The problem was when the server restarted, deployment would fail the second time mentioning it could not redeploy one of the previously failed files.
The only one I have found to work consistently for me is archive without external deployment descriptor. However, I still need a way to tell the application in which environment it is running. I have different Torquebox instances for each environment and they only run the one application, so it would be fairly reasonable to configure this at the server level.
Any assistance in this matter would be greatly appreciated. Thank you very much!
The solution I finally came to was to pass in RAILS_ENV as a Java property to the Torquebox server and then to set ENV['RAILS_ENV'] to this value in the Rails boot.rb initializer.
Step 1: Set Java Property
First, you will need to set a Rails Environment java property for your Torquebox server. To keep with standard Java conventions, I called this rails.env.
Dependent on your platform and configuration, this change will need to be made in one of the following scripts:
Using JBoss Windows Service Wrapper: service.bat
Standalone environment: standalone.conf.bat (Windows) or standalone.conf (Unix)
Domain environment:: domain.conf.bat (Windows) or domain.conf (Unix)
Add the following line to the appropriate file above to set this Java property:
set JAVA_OPTS=%JAVA_OPTS% -Drails.env=staging
The -D option is used for setting Java system properties.
Step 2: Set ENV['RAILS_ENV'] based on Java Property
We want to set the RAILS_ENV as early as possible, since it is used by a lot of Rails initialization logic. Our first opportunity to inject application logic into the Rails Initialization Process is boot.rb.
See: http://guides.rubyonrails.org/initialization.html#config-boot-rb
The following line should be added to the top of boot.rb:
# boot.rb (top of the file)
ENV['RAILS_ENV'] = ENV_JAVA['rails.env'] if defined?(ENV_JAVA) && ENV_JAVA['rails.env']
This needs to be the first thing in the file, so Bundler can make intelligent decisions about the environment.
As you can see above, a seldom mentioned feature of JRuby is that it conveniently exposes all Java system properties via the ENV_JAVA global map (mirroring the ENV ruby map), so we can use it to access our Java system property.
We check that ENV_JAVA is defined (i.e. JRuby is being used), since we support multiple deployment environments.
I force the rails.env property to be used when present, as it appears that *RAILS_ENV* already has a default value at this point.
I need to set grails.server.host and grails.server.port differently on different dev machines, or in different configurations. I can set them in BuildConfig.groovy but that is source-controlled so I don't want to check in machine-specific info there. How can I pass these from the Run Configuration?
I have tried every combination of -Dserver.host and -Dgrails.server.host, with the values in quotes or not, in the Arguments tab Program Arguments and VM Arguments fields, and just server.host or grails.server.host in the Environment tab; I even tried changing the Grails tab's Grails Command field to "-Dserver.host=192.168.2.110 run-app" but grails keeps coming up "localhost:8080"
My fallback is to try and set them with an external property file, but then I have to get fancy about setting them differently for different environments and such, and I don't have easy UI visibility like I do with the Run As ... menu. So, can someone tell me how they are configuring Eclipse/STS to pass a grails parameter?
(Using Eclipse (STS 2.7.1) with grails 2.0.0M1)
-Dserver.host=192.168.2.110 -Dserver.port=8888 Should work if set in the VM arguments...
Have you tried grails -Dserver.host=192.168.2.110 -Dserver.port=8888 run-app from terminal or the command prompt?