Thursday, March 21, 2013

Store your RHQ Agent Preferences in a File


The RHQ Project stores its agent configuration using Java Preferences, which is a great way to store things in a platform-independent way without having to worry about it.  But, sometimes it's nice to have a little more control over things, especially on Windows where the native implementation uses the registry.  Some RHQ users have requested being able to store the agent configuration in a configurable file, so that they can just wipe an agent directory and not leave any configuration litter somewhere on the machine.

I recently pushed this feature to our master git branch and it should show up in RHQ 4.7.  But you can try it now if you roll your own builds.

All you need to do is start your agent with two system properties set:


java.util.prefs.PreferencesFactory=org.rhq.core.util.preferences.FilePreferencesFactory 
rhq.preferences.file=


This can be done conveniently by setting them in rhq-agent-env.sh|bat:

set RHQ_AGENT_JAVA_OPTS=-Djava.util.prefs.PreferencesFactory=org.rhq.core.util.preferences.FilePreferencesFactory -Drhq.preferences.file=

You can omit the rhq.preferences.file property and it will default to user.home/.fileprefs but you probably don't want to use the default.  A more likely approach would be to set it to something like:

 -Drhq.preferences.file=$RHQ_AGENT_HOME/conf/agent-prefs.properties

By doing that you'll be storing it under the agent's root, and therefore if you delete the entire agent you'll also get rid of the prefs.

Note that this works easily for new agents.  For existing agents that want to switch to this approach, it will be somewhat like starting with the --fullcleanconfig option.  This means you'll need to re-enter the setup questions and also specify the existing security token via -Drhq.agent.security-token=.  If you want to see your existing configuration settings before making a switch you  can use the '> config list' agent prompt command (either interactively or via the RHQ Agent's operation).