Scripting DSN and Mapping creation

180 views
Skip to first unread message

Dan Skaggs

unread,
Mar 26, 2015, 1:26:34 PM3/26/15
to lu...@googlegroups.com
Has anyone done any work with programmatically adding DSNs and Mappings to the Lucee server admin from a command line?  I'm in the process of setting up a Vagrant box (forked from Mike Sprague's project and updated to CentOS/Apache) and am to the point that I need to configure the primary DSN and set up 2 or 3 mappings.

I thought I had seen some discussion on doing this with Railo in the past but I can't seem to find that now.

Pointers to any resources would be appreciated.

Thanks
Dan

Igal @ Lucee.org

unread,
Mar 26, 2015, 1:33:00 PM3/26/15
to lu...@googlegroups.com
you can either use the cfadmin tag (see how we do it in the admin implementation), or modify the xml files for lucee-server and/or lucee-web.

if you need it only on the application scope, then a better solution might be to add it via the this.datasources and/or this.mappings of Application.cfc

Igal Sapir
Lucee Core Developer
Lucee.org

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/055d27ad-39b6-4482-b35e-3a7996485674%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dominic Watson

unread,
Mar 26, 2015, 1:38:16 PM3/26/15
to lu...@googlegroups.com
We have done something similar with injecting the datasource into our applications with our own tool. The same approach could be made just using environment variables, however. So something like this in Application.cfc (very rough, but you get the idea):


function onRequestStart() {
     _setupInjectedDatasource()
}

private string function _setupInjectedDatasource() {
     this.datasources[ dsn ] = {
                  type     : 'MySQL'
                , port     : getEnvironmentVariable( "DBPORT" )
                , host     : getEnvironmentVariable( "DBHOST" )
                , database : getEnvironmentVariable( "DBNAME" )
                , username : getEnvironmentVariable( "DBUSERNAME" )
                , password : getEnvironmentVariable( "DBPASSWORD" )
                , custom   : {
                      characterEncoding : "UTF-8"
                    , useUnicode        : true
                  }
            };
}

private string function _getEnvironmentVariable( required string variableName ) output=false {
    var result = CreateObject("java", "java.lang.System").getenv().get( arguments.variableName );

    return IsNull( result ) ? "" : result;
}




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



--
Pixl8 Interactive, 3 Tun Yard, Peardon Street, London
SW8 3HT, United Kingdom

T: +44 [0] 845 260 0726 W: www.pixl8.co.uk E: in...@pixl8.co.uk

Follow us on: Facebook Twitter LinkedIn
CONFIDENTIAL AND PRIVILEGED - This e-mail and any attachment is intended solely for the addressee, is strictly confidential and may also be subject to legal, professional or other privilege or may be protected by work product immunity or other legal rules. If you are not the addressee please do not read, print, re-transmit, store or act in reliance on it or any attachments. Instead, please email it back to the sender and then immediately permanently delete it. Pixl8 Interactive Ltd Registered in England. Registered number: 04336501. Registered office: 8 Spur Road, Cosham, Portsmouth, Hampshire, PO6 3EB

Dan Skaggs

unread,
Mar 26, 2015, 1:59:16 PM3/26/15
to lu...@googlegroups.com
Thanks Igal...

This is the primary DSN that all the apps use to dynamically create their individual DSNs.  As for the mappings, all applications share 3 core mappings so I need to script those into the server admin so they'd be automatically propagated to all web contexts.

I'll check into the cfadmin tag and see what I can come up with. I might be able to put a CFM page in the assets folder of the vagrant repo and hit it with curl or something from within the vagrant script.

Thanks
Dan

Igal @ Lucee.org

unread,
Mar 26, 2015, 2:29:13 PM3/26/15
to lu...@googlegroups.com
I think that your simplest solution can be to put the settings in a file (which you can generate with a script), and then include that file in Application.cfc of the files that need it.   consider the following example (assuming all files in the same folder):

Application.cfc:
component {

    this.name = "TEST150326_01";
    include "appsettings.cfml";
}

appsettings.cfml: (defines mapping for /ram)
<cfscript>
    this.mappings[ "/ram" ] = "ram://";
</cfscript>

test.cfm: (test mapping with cffile and cfinclude)
<cffile action="write" file="ram://time.cfml" output="#dump(var: now(), label: "Time in Memory File")#">
<cfinclude template="/ram/time.cfml">

you should be able to do the same for datasources, though I did not test that.


Igal Sapir
Lucee Core Developer
Lucee.org

Dan Skaggs

unread,
Mar 27, 2015, 8:44:01 AM3/27/15
to lu...@googlegroups.com
Actually what I wound up doing was going through the server admin to add all the mappings and datasources that I need to populate a new VM with and then copying the lucee-server.xml file out of the VM and into my Vagrant project. The next time the a new VM is build with Vagrant, that file gets copied back into the new VM and the settings were automatically there.

There are nearly 100 CF apps that could be running on this development VM (depending on which of those you are working on) so editing the Application.cfc for every one of them is not an option. These settings need to be set up before any code ever runs.

Anyway, it's all baked now...type 'vagrant up' and in just a few minutes we get a CentOS/Apache/Lucee box that's correctly configured and read to use as a dev box.

Thanks
Dan
Reply all
Reply to author
Forward
0 new messages