Changing Aggregate IP to URL

Hi,

I setup my project's Aggregate by entering the public IP. However, as more people are using it, I had to buy a domain name and have taken the IP behind the domain (so that it is easy to remember for enumerators while configuring Collect). But the aggregate does not seem to like it and does not work when the domain is entered in the collect's URL settings (still works fine if the IP is entered). I understand that the Aggregate is locked to the IP, but is there a way to replace the IP with domain in a production aggregate?

Regards,
Saad

The easiest way to switch from an IP to a URL is to rerun the aggregate installer so that the configuration files get properly configured to use the domain URL instead of the IP address.

If you want to manually edit the files are located in ODKAggregate-settings.jar. However if you mess up those files aggregate will not boot.

The answer is actually the same as your previous question as aggregate takes the IP address or the URL you give it in the config file (normally input by answering a question in the aggregate installer) and treats that as the preferred URL when creating it's response string. So you can switch IP address or you can switch between a URL and IP address using a similar method.

1 Like

Thanks a lot!

Two more things: First, if I rerun the installer and upgrade the ROOT.war file in tomcat, would it not disown the previous production database? I need to sustain the data and the DB.

Second, what is the issue in manually editing the JAR file you mentioned? How can I mess up the files if I just edit it with a text editor, make a small change and exit? I very well understand that aggregate will not work for messing up the files, but I am trying to figure out if there is a special way of editing a jar file (like in some specialized program), or standard text editor will do?

If you keep the same database settings when you re-run the installer, it will keep that same data.

jar and war files are basically zip files. So you can't just edit the jar. Assuming you are starting from the war, you'll need to unzip that war. Then unzip WEB-INF/lib/ODKAggregate-settings.jar, then edit security.properties (text file) to update the hostname. Then you'll need to re-zip the jar and re-zip the war and make sure they are in the same place. It's not hard, but you do have to be precise.

You can also see this done in the ODK Aggregate VM installer:
https://github.com/nafundi/odk-aggregate-box/blob/master/provisioning/roles/install-aggregate/tasks/main.yml#L23-L68

And if that doesn't make sense, here's part of a Bash script that does this on Ubuntu.

TIMESTAMP=$(date +%Y-%m-%dT%H:%M:%SZ)
ZIP_PATH=$(which zip)
UNZIP_PATH=$(which unzip)
WAR_PATH="/var/lib/tomcat6/webapps/ROOT.war"
WAR_FOLDER_PATH="/var/lib/tomcat6/webapps/ROOT"
BACKUP_WAR_PATH="/usr/local/etc/aggregate/ROOT.war.$TIMESTAMP" 

echo "Unpacking ROOT.war";
$UNZIP_PATH -q $WAR_PATH -d /tmp/ODKAggregate;

echo "Unpacking ODKAggregate-settings.jar";
$UNZIP_PATH -q /tmp/ODKAggregate/WEB-INF/lib/ODKAggregate-settings.jar -d /tmp/ODKAggregate-settings;

echo "Changing ODKAggregate-settings.jar settings";
eval "sed -i -e 's/^security.server.hostname=.*/security.server.hostname=$HOSTNAME/g' /tmp/ODKAggregate-settings/security.properties;";

echo "Repacking ODKAggregate-settings.jar";
cd /tmp/ODKAggregate-settings;
$ZIP_PATH -q -r ../ODKAggregate/WEB-INF/lib/ODKAggregate-settings.jar .;

echo "Backing up old war and removing exploded folder";
if [ -f $WAR_PATH ]
then
  mv $WAR_PATH "$BACKUP_WAR_PATH";
fi
if [ -d $WAR_FOLDER_PATH ]
then
  rm -rf $WAR_FOLDER_PATH;
fi

echo "Repacking ROOT.war";
cd /tmp/ODKAggregate;
$ZIP_PATH -q -r $WAR_PATH .;

Thanks Yaw. I already did some research on editing JAR files right after Waylon's post, and figured out the things. I did the IP change, however haven't loaded the file back and tested on the server. Will do so and share the results with everyone as I find some free time.

Many thanks for your help!

Just to update: It works perfectly fine.

1 Like