Editing the datasources in lucee-server.xml

Hi,

Can we stop Tomcat / Lucee, edit the lucee-server.xml file, for example to change the IP address of all datasources, and restart Tomcat / Lucee without any side effects? Does Lucee always load the lucee-server.xml file on startup or does it keep some data in memory?

The idea is to be able to quickly change the IP address of all the datasources rather than changing them one by one in the lucee admin.

What is the best way to do it?

  • Editing the lucee-server.xml
  • Using Custom Variables in lucee-server.xml (I need to figure out how)
  • Another tool…

Thank you

OS: Windows Server 2016 (10.0) 64bit
Java Version: 1.8.0_181 (Oracle Corporation) 64bit
Tomcat Version: Apache Tomcat/8.5.33
Lucee Version: Lucee 5.3.8.206

Yes, that’s fine. You just run the risk of corrupting the XML file if you edit it wrong.

Yes,

When it’s running yes, but when it’s shut down, there’s nothing in memory. You can actually

  • Leave Lucee running and hot-reload the setting by using the “restart” button in the server admin
  • Or configure Lucee to watch the config files for changes so it just picks them up within 60 seconds. (Many people don’t even know Lucee does this since there is nowhere to enable this in the admin UI, but CFConfig can be used to enable it :slight_smile: )

Yes, CFConfig is what you need to be looking into here. It’s a CLI tool in the form of a CommandBox module. CommandBox doesn’t even necessarily need to be running on the server if you have the server home mapped over to a PC that is running CommandBox (Whether a windows shared drive or a Linux mount)
CFConfig can be used on ANY Lucee or Adobe server, regardless of how it was installed and allows you to

  • Export all or some config into a JSON file
  • Import all or some config out of a JSON file
  • View or Set any individual setting
  • Transfer or diff settings between servers/files
  • Use easy env var replacements in the form of ${DB_HOST:default-value}

So, let’s say you’ve configured you Lucee server to watch the XML file for changes:

cfconfig set watchConfigFilesForChangesEnabled=true

And then you have a “template” JSON file with your datasources, having the sensitive or fluid bits swapped out with env vars:

{
  "datasources" : {
    "Your_DSN":{
      "database":"your_DB",
      "dbdriver":"MSSQL",
      "host":"${DB_HOST}",
      "port":"1433",
      "username":"user",
      "password":"pass"
    }
  }

And now you can set an environment variable and import the file at-will:

set DB_HOST=10.10.0.50
cfconfig import from=mySettings.json to=/path/to/lucee-server

Or, if you want to get even fancier with a bunch of env vars, install the commandbox-dotenv module, and use an .env file which is loaded by convention, or even multiple property files for quick automation.

dotenv load prod-settings.properties
cfconfig import from=mySettings.json to=/path/to/lucee-server

# failover
dotenv load failover-settings.properties
cfconfig import from=mySettings.json to=/path/to/lucee-server

And that’s only half the possibilities :slight_smile: Managing a JSON file and env vars is going to be much easier than mucking around with Lucee’s XML files.

1 Like

Use host file or DNS, and no restart needed if using name based lookup.

Note you will want to stop or at least not have ultra db independent items running such as logged in users playing around with nuclear codes or something if you are just abruptly changing databses.

Using your favorite editor as administrator

Winroot/system32/drivers/etc/hosts

10.10.1.11 myhost1
10.10.1.12 myhost2.foo.bar

You can create a simple perl, python or powershell script that edits that and right before injecting the edit stops networking service or blocks the port(s) used for the database, then adds the change(s) as needed then starts backup the networking service and or unblocks the ports.

Is this clean? No. Does it work, Yes.
is it recommended, No.
Why would you do something like that? - Many useful examples such as hot-swapping database servers, providers, so on and so forth.

1 Like

Many thanks for the detailed answer. It’s very appreciated!

Thanks also to you @Terry_Whitney for this idea. In your experience, when changing the IP address in the hosts file, should we do an ipconfig /flushdns to ensure that the old IP for the domain name does not remain in cache?

Depending on if you use Host file based or DNS, the patch level or customization of the windows registry key.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\ServiceProvider has a bunch of values such as LocalHostPriority, the lowest value is first. So you can tweak your settings accordingly.

If you are using DNS, then ipconfig/flushDNS is the way to go.

If you are following Microsoft Best Practice (cough) then you could set your internal DNS servers to all resolve everything, and only have to point the DNS entries on the revolvers. This is okay, but slow in a ADS environment (slow by my standards, see 15 minutes in some cases slow).

The key to the DNS resolver route is Timeout needs to be low, under 300 seconds low. Yes your servers will hammer DNS, but that is the trade off for flexibility.

2 Likes

Wow thank you again for this more than complete answer! I will evaluate all of this and make a decision accordingly.

Have a nice day!