Setting Environment Variables in Application.cfc

88 views
Skip to first unread message

to...@3lll.asia

unread,
Aug 31, 2014, 12:03:06 PM8/31/14
to ra...@googlegroups.com
Hi

Can somebody tell me what is wrong with this please...

I'm trying to set a MySQL datasource from an environment variable passed in from the operating system - actually passed in from Kubernetes...

component {

this.Name = "RAILO_WORLD";
//////////////////////////////////////////////
//               DATASOURCES                //
//////////////////////////////////////////////
this.datasources["food13"] = {
 class: 'org.gjt.mm.mysql.Driver'
, connectionString: 'jdbc:mysql://${env.MYSQL_IP}:3306/food13?useUnicode=true&characterEncoding=UTF-8&useLegacyDatetimeCode=true'
, username: 'root'
, password: "encrypted:a06a0672d51aaa0024340f52cf4ca7a288dfaa935464d04d3895002ae41a8f0d"
};

}

I think I'm doing something really silly but can't find what - This was generated from the export Application.cfc and the env.MYSQL_IP put in to replace the IP address...

Thanks


Matt Quackenbush

unread,
Aug 31, 2014, 1:05:45 PM8/31/14
to ra...@googlegroups.com

Are you seeing an exception? I assume the answer is yes. Please post the stack trace.

Thanks!

--
Did you find this reply useful? Help the Railo community and add it to the Railo Server wiki at https://github.com/getrailo/railo/wiki
---
You received this message because you are subscribed to the Google Groups "Railo" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/railo/80700b29-9b29-41a6-8658-92dc3edbd868%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Blackwell

unread,
Aug 31, 2014, 1:35:07 PM8/31/14
to railo

Where did you get this syntax from?

${env.MYSQL_IP}

railo won't expand that so your datasource will not work. cfml uses #varname# for variable expansion in a string, and there is no direct access to environment variables without dipping into java.

you would need to do something like

env = createObject("java", "java.lang.System").getenv()

jdbc_url = "jdbc:mysql://#env.MYSQL_IP#/whatever?..."

also, if you are reading the mysql ip from an environment variable why not also the username and password?  railo "encrypted" passwords are insecure and should never be shared or added to source control.

In our apps we have a datasource defined in a json configuration file.  We then start railo with an extra java property that tells it where to find the configuration file.

java -jar myapp.jar -Dmyapp.config=/path/to/config.json [... other settings]

Tony Legge

unread,
Sep 1, 2014, 3:44:31 AM9/1/14
to ra...@googlegroups.com
This is not my area of expertise..... Thanks for responding!

I'm using Railo 4.2 Express and building that inside a container...

The start script is the normal 'start" for express and this is what is fired up inside the container.

#!/bin/bash

cd $(dirname $0)
java -DSTOP.PORT=8887 -DSTOP.KEY=railo -javaagent:lib/ext/railo-inst.jar -jar start.jar --module=http jetty.port=8888

To make Kubernetes be properly declarative I need to let the system pass the env var for the datasource. The container will just have MYSQL_IP set to the datasource. I have to get this information and pass it to Railo, using the Application.cfc.

I think your reply solves that but I am not sure because there is no file as such - just a variable that will be returned by echo $MYSQL_IP on the non-existant command line!




You received this message because you are subscribed to a topic in the Google Groups "Railo" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/railo/CAB%3DtfTq%2BUbjEBT4M2PO-GPCzUwNZRZR05Hv5ywg%2B%3DFpGc8S37g%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Thanks

Tony Legge
Edible Systems Ltd
Reply all
Reply to author
Forward
0 new messages