Using Linode DNS Manager for Google Apps
Monday, December 8th, 2008I've hosted a few websites for other people and have used Google Apps to handle mail and calendar needs. This way I'm just using my Linode to only host the webpages. After manually creating the Google Apps DNS records a few times, I decided it'd be best to write a script using Linode's API to automate the process.
Since I haven't written a Perl script from scratch in awhile, I thought it would be good to use that. Michael Greb, who works at Linode, published a Perl module on CPAN called "WebService::Linode". Mike also posted some really helpful information regarding the installation of Perl modules under Ubuntu Linux. Instead of downloading, compiling, and installing the module the old fashioned manual way, you can use dh-make-perl. The dh-make-perl program will do all of that for you and create a Debian package file to install. This way if the CPAN module is ever upgraded or becomes part of the distro, it'll be handled automatically. I used the following commands to install the module (I also had to do the same thing for JSON because my installed version was too old).
$ dh-make-perl --cpan JSON --build $ dh-make-perl --cpan WebService::Linode --build $ sudo dpkg -i libjson-perl_2.12-1_all.deb libwebservice-linode-perl_0.02-1_all.deb
Once the prerequisites are installed, you can download the googleapps-dns.pl script from my Git repository.
On the first run it will prompt for the Linode API key and store it in ~/.linode-api. Subsequent runs will simply read the key from that file. Below is an example of how it's usage.
$ googleapps-dns.pl -h
Usage:
googleapps-dns.pl [ -d domainname ] [ -m ] [ -c ] [ -f ] [ -v ] [ -h ]
Options:
-d domainname
Specify the domain name for adding the records. This field is
required.
-c Add Google Chat's Jabber and XMPP records to route external
chat program to Google's services.
-g Add CNAMES that point calendar.domainname, docs.domainname,
mail.domainname, sites.domainname, and start.domainname to
ghs.google.com.
-m Add MX and SPF records for routing mail to Google Apps.
-f Force deletion of any conflicting records.
-v Enable verbose debugging messages.
-h Display help and options.
$ googleapps-dns.pl -d example.com -g -m -c
Would you like to delete any conflicting dns records? [Y/n] y
Please enter your Linode API Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$
I hope this is helpful for other people managing sites hosted on Google Apps.
