Need to migrate your DNS?
Posted by Andrew McGrath in Uncategorized on November 4, 2011
This is a super short post but i just wanted to share it because i’m currently doing a DNS migration and finding that validating all CNAME and A records for our domain isnt super easy. Here is how i ended up doing it (You should re-use this PHP!):
//name servers to compare against
$nameservers = array();
array_push($nameservers,"ns1.origionalnameserver.com");
array_push($nameservers,"ns2.origionalnameserver.com");
array_push($nameservers,"ns1.destinationnameserver.com");
array_push($nameservers,"ns2.destinationnameserver.com");
//hosts to compare
$hosts = array(
"hostname1.com",
"hostname2.com",
"hostname3.com",
"hostname4.com"
);
//do the compare and echo out the results
foreach($hosts as $host)
{
//get the results for each name server given the current host
$results = array();
foreach($nameservers as $ns)
{
$result = getDNS($host,$ns);
array_push($results,strtolower($result));
//echo "LOG: $host $ns - $result\n";
}
//see if all the results match
$allmatch = true;
$compare_result = $results[0];
foreach($results as $result)
{
if($result != $compare_result)
$allmatch = false;
}
//check to see if everything matched or not
if(!$allmatch)
{
echo "WARN: $host does not match on all nameservers\n";
$count = 0;
foreach($results as $result)
{
echo "[".$nameservers[$count]."] $result\n";
++$count;
}
}
else
{
echo "INFO: $host OK\n";
}
}
//getdns function to get host name given a name server
function getDNS($host,$ns)
{
$string = '';
exec("dig @$ns +short $host 2>&1", $output, $retval);
if ($retval != 0)
{
return "ERROR_NO_RESULT";
}
else
{
$x=0;
while ($x < (sizeof($output)))
{
$string.= $output[$x];
$x++;
}
}
if (empty($string))
{
return "ERROR_NO_RESULT";
}
else if($string[strlen($string)-1] == '.')
{
$string = substr($string, 0, -1);
}
return $string;
}
Route53 – the good the bad and the great
Posted by Andrew McGrath in Uncategorized on October 20, 2011
So recently at work we’ve been looking to migrate a few services that are hosted on legacy infrastructure over to a much better set of servers at Amazon AWS. Along the way we hit a few issues, i wanted to share my experience with you so people never have to worry about these issues again…
Issue 1:
When using Amazon AWS Elastic Load balancers you get provided with a host name for the load balancer (not an IP – this is key). This is all good and well but DNS RFC 1034 states that the origin of a domain has to be a A record, but Amazon gave us a host name, so thats a CNAME? Our current DNS provider did not support host names as A records, so this isnt good.
Solution:
Use Route53 at Amazon. Amazon allows you to use their Route53 DNS service and create A records with an “AliasTarget”. These basically setup some crazy round robin DNS setup. There are a few steps to this:
1. Create the HostedZone using the Route53 API. Here is the XML required to create the hostedzone for my domain bitchasscode.com
<CreateHostedZoneRequest xmlns="https://route53.amazonaws.com/doc/2010-10-01/"> <Name>bitchasscode.com.</Name> <CallerReference>dns_migration_amcgrath_20111018</CallerReference> <HostedZoneConfig> <Comment>Migrate an existing domain to Route 53</Comment> </HostedZoneConfig> </CreateHostedZoneRequest>
2. Create the individual A records and Cnames for the domain using the Route53 API:
<?xml version="1.0" encoding="UTF-8"?> <ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2011-05-05/"> <ChangeBatch> <Comment>Create record for bitchasscode.com.</Comment> <Changes> <Change> <Action>CREATE</Action> <ResourceRecordSet> <Name>www.bitchasscode.com.</Name> <Type>CNAME</Type> <TTL>300</TTL> <ResourceRecords> <ResourceRecord> <Value>bitchasscode.com<Value> </ResourceRecord> </ResourceRecords> </ResourceRecordSet> </Change><Change> <Action>CREATE</Action> <ResourceRecordSet> <Name>bitchasscode.com.</Name> <Type>A</Type> <AliasTarget> <HostedZoneId>YOUR LOAD BALANCERS HOSTED ZONE ID</HostedZoneId> <DNSName>DNS NAME OF THE LOAD BALANCER</DNSName> </AliasTarget> </ResourceRecordSet> </Change></Changes>
</ChangeBatch>
</ChangeResourceRecordSetsRequest>
This is a key step, becsause this is what lets you have a “hostname” as a A record. Sexy stuff…
3. Test your setup, it worked fine for me, however honestly its a real pain in the ass to do all of this. This created a new issue for me, i didnt really trust what I just did…so i started thinking about creating a UI for Route53 so i could easily view my edits.
Issue 2:
There is no UI for route53 provided by Amazon.
Solution:
Use Interstate53 as your UI, you just need to provide an AWS API key & secret…then you’re done!
Honestly i dont know a lot about Interstate53, other than its very amazing. I tried a few other services which didnt do the job for me:
- nsRoute (Doesnt do Alias records to ELB’s properly)
- dns30 (Doesnt do Alias records to ELB’s properly)
- easydns (They wanted me to signup, pay or something – too hard, i gave up after i couldnt work out how to get an account.)
Interstate53 were super easy to get going with (just provide an api key and secret), there is no registration or anything and their UI is great. It works perfectly with Alias records going to ELB’s and then you’re cooking!
I rotate weekly…and i like it!
Posted by Andrew McGrath in Things we use on October 15, 2011
Its time we all admitted that rotating our log files is something we should get our act together with and do properly. I was a bit surprised how relevant and simple examples were hard to find online the first time i had to do this, so i figured since i just had to install “logrotate” on my Ubuntu server again today that this is a good day to write about it.
Why is this important? Well if you don’t rotate your logs you will suffer from erosion. A massive problem for servers that don’t get a lot of love and attention…and honestly who wants to love a server? If you servers disk space is filling up with logs, and you are not emptying them faster than they fill up…thats erosion.
The following example tells you how to install logrotate and configure it to rotate your Apache2 log files.
Step 1.
Install logrotate on your server.
sudo apt-get install logrotate
Step 2.
Edit the logrotate config file to tell it where your apache logs are.
sudo vi /etc/logrotate.conf
Add the following to the very bottom of the file:
/var/log/apache2/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
/etc/init.d/apache2 restart > /dev/null
endscript
}
Thats great, but what does it mean?
Line by line, this is the breakdown:
1. /var/log/apache2/*.log
This is the path to the logs you want to rotate. I’ve said *.log here, because i want all logs in this directory to rotate
2. weekly
Tells log rotate to rotate these weekly
3. missingok
Prevents us from getting errors if there are no logs
4. rotate 52
How long should archived files be retained before being deleted
5. compress
duh…
6. delaycompress
Sometimes you dont want to compress the file right away, as the app is writing to the logs and will be for some period of time
7. notifempty
Only rotates logs that are not empy
8. create 640 root adm
This defines the file permissions that the archives will be created with
9. sharedscripts
Ensures any prescript or postscript elements of this log rotation are only run once
10-12. postrotate
This section defines what logrotate should do at the end of the rotation. In this case i’ve told it to restart apache, because we want to make sure new log files get created. Even although log rotate renamed the log file, apache will keep writing to the renamed file until its restarted (this is why we included the option ‘delaycompress’)
13. }
end of the log rotation config

ROTATE YOUR LOGS! SAVE YOUR DISK SPACES! OR I WILL HURT THIS RABBIT!
Fix your shit or i’ll take your customers money for you!?
Posted by Andrew McGrath in Uncategorized on October 7, 2011
Recently I’ve run into so many poorly setup systems, and what makes me sad is that people paid for them to do this. If you wrote any code recently and you’re trying to get people to pay for it, do them (and yourself) a credit by at least doing the following:
- GET A LOAD BALANCER
They are very simple to setup, services like Amazon AWS and Rackspace provide these for around $20 / month; they are not expensive. If you have your reputation on the line they are worth the spend! Even if you only have 1 machine behind the load balancer, if you dont use one from the start in order to introduce one later when things get serious you need to make a DNS change. This is a big issue because you probably want it to happen quickly. Add the load balancer in from the start! You can always add more servers behind it and with sticky sessions as an option, you dont even need to make code changes to your app! - DISABLE SSH ACCESS FROM THE ENTIRE WORLD
At Amazon this is very simple, create a custom security group and whitelist only the IP’s you want to have access via SSH. - DO NOT USE MYSQL WITH ROOT
Always create custom usernames for applications. Its nice to tell the difference between your app, and someone using the root account. - ALWAYS USE PASSWORDS WITH MYSQL
I came across a case yesterday where people were using root with no password - ONLY GIVE MYSQL ACCESS TO PEOPLE WHO NEED IT
Again back to the security groups, dont let anyone get access to your machine on port 3306! Only white-list servers which need access to your database. Sadly the same case i ran into yesterday using root and no password also had their instance open to the entire world. Major no no! - KNOW YOUR HOSTING PROVIDER
Companies like Amazon provide some amazing tools that if used properly can result in some great results. If you’re at Amazon try use things like RDS (Rather than installing MYSQL on an EC2 instance), take advantage of different availability zones (dont put every machine behind your load balancer in the same zone), know how to secure your site using tools like “Security Groups”, and understand how to enable monitoring. - Finally…MONITOR YOUR SERVICE
At Amazon CloudWatch is your friend, use it! Its cheap ($3/month) and very useful…if you want to get an email when the number of unhealthy servers in a load balanced group increases, this service can tell you! Tie that baby in with companies like PagerDuty and hey presto, every time a server goes out of service you get a phone call.
If you use the tools you are provided with properly, your life is easy. If you dont someone like me will jump on your machine, drop your database, sit back and laugh because you’re not monitoring it and you dont have a clue it happened until the customer calls to yell at you.
Fix your shit, or i’ll take your customers money and keep it for myself!
A new day, a new office!
Posted by Andrew McGrath in Funny, Things we use on October 4, 2011
We decided that we’ve been far too well behaved this year. We’ve saved up some decent capital, worked hard, built up a bunch of new customers and now its time to reward ourselves! What better way to do this than by getting a flashy new office (and by flashy i mean, slightly dusty…)
Meet our new 27.5ft boat office.

TechCrunch – Thats a problem I’d like to have…again
Posted by Andrew McGrath in Facebook, Funny, Media coverage, Startups on October 3, 2011
Not so long ago one of my products was featured on TechCrunch. Let me tell you, its freaking cool to have happen. For those of you who are curious about “How does that happen?” and “What happens when it happens?” this blog post is for you!
Read the rest of this entry »
Want to know your Facebook user / customers best friend?
Posted by Andrew McGrath in Facebook, Startups, Things we use on October 1, 2011
Its a question that I think most people who own a business would say yes to. After all, who’s advice are you more likely to take than your best friends? You probably have similar interests, grew up in a similar geographical location, talk regularly, are part of the same age group and possibly even work together.
We have seen that Like, Recommend and Share buttons seem to…suck? A good like button will get something like 1% of your customers click it, maybe 10% if you’re doing something special. I don’t know about you, but I’m yet to see any money from people who have liked my pages. Wouldn’t it be better if you could say something like:
Hi <<Friend>> I think you should really buy a new phone from Samsung, I’m going to!
<<link to product>>
Cheers,
Andrew
We all spend a lot of money trying to target our customers in the right way, why not target their friends in the right way! They are probably pretty similar and very likely to buy the same products as each other.
To help with this we have created is our Beta Friends API. Its free while in Beta and you can use it with just 3 pieces of data that you probably already have! Read the rest of this entry »
Cloudability – mint.com for the cloud
Posted by Andrew McGrath in Startups, Things we use on August 23, 2011
I’m excited to tell you that I’ve been trialing a new service called Cloudability. These guys address a very critical problem that we’ve been facing ever since VMware came to exist, how to monitor cost when servers are far too easy to make.
We’ve all been there. You rat through your Amazon, Rackspace (Who if you need cloud servers I would personally recommend you signup with) or Slicehost account only to find that there are 5-10 servers that are either containing peoples names or the word “test”. Each have been running for days if not weeks and no one claims to be using them any more. Well maybe not everyone hits this problem, but when it happens, its a serious issue. You’re paying for things you’re not using!
So what do we do about monitoring costs in the cloud? For some reason the companies offering cloud services have not bothered to make this easy for us. Amazon have consolidated billing (thats kind of cool…) and Rackspace have a billing section that shows stats about currently running instances but none of these offer any of the following (Which as someone managing these costs, i need to know):
- How much am i going to spend this month?
- What am i trending? Am i spending more each month or less? I need to make a yearly budget…
- What is each department of our company spending in the cloud?
It might come as a surprise to some but the ability to “Group” servers and report on the cost of each group would be an amazing feature! While this sounds real simple, its not possible at any of the providers I’ve mentioned so far which means if our CFO says “how much did X team spend this month?” i need to whip out excel and make some nasty calculations (which will be close but not perfect)
Whats the solution? Well you could write something custom using the API of your provider and do something like:
Cost = (uptime x hourly cost) + data charges + additional services*
*additional services may be additional IP’s or storage space
Again this doesnt sound hard but who has the time to write this? We’re busy enough trying to make our product better. Cloudability comes in and offers you some help here. Not only do they monitor all of your hosting costs, they can add a range of other services to the estimations and provide detailed reporting on them too.
Check out Cloudability, they’re in Beta right now and there is a waiting list but if you’re serious about understanding your cloud costs they look like the best place to start.
Back, better and….better?
Posted by Andrew McGrath in Facebook on August 21, 2011
Some of you might remember our application “Who isnt my friend?”. This was an application which told you when someone was no longer your friend, well sadly Facebook banned our application. So we made some changes! After talking to Facebook and creating changes which made them happy. Our “Who isnt your friend?” application is no longer, and we’ve introduced an application which is more “Analaytics” focused. We call it “Friend-watch”
What does “Friend-watch” do? It…
- Tells you when someone becomes your friend
- Tells you when someone changes their name
- Shows a breakdown of males v’s females (and unknowns) in your friends list
- Tells you when someone is no longer on your friends list
- Shows you where your friends live on a map (coming soon…)
Facebook’s main concern was the way people were engaging with the app. Posts should be happy and create positive engagements, Facebook felt that our app didn’t do this, so we changed it up and made it happier and added some cool functions in the process of it.
So, join the fun. Join Friend-watch
How do you monitor a system?
Posted by Andrew McGrath in Facebook, Things we use on July 20, 2011
Its a really hard question to answer, especially when you’re creating something new.
After making some changes to become more “compliant” with Facebooks TOS I decided that I’d re-launch our “Who isnt my friend?” (now called “Friend-Watch“) application by simply adding it to my wall, and then doing nothing. Anyone who has followed this blog in the past knows that this app took off all by itself in the past, so it shouldnt be any surprise that I’d like to see if that happens again (if i do nothing to help it).
That was about 4 days ago now, so today I decided to measure my performance. In order to do this I created the following graphs:
The Engatement stats are interesting because without me doing anything, they’re all pointed in the right direction…so i guess we can watch this one for a while longer and see what happens!
What interests me the most is the “System performance” graph. I was trying to answer the question “how do i know if i need more hardware?”. Previously when i wrote this app I had a massive issue with scale. I think that issue is pretty much resolved, but now i need to ask myself “how do i know when i need to scale it?” Thats where this graph came from.
I’ve drawn 3 key details on the “System performance” graph:
- Total audits – This shows how many audits the system has done as to date
- Total audits on day – This shows how many audits the system did on this day
- Total audits per user * 100 – This shows how many times each user was audited on average, multiplied by 100 to blow up any issues so they’re more easily seen
At first i just implemented “total audits” and “total audits on day”. I made the assumption that when i hit the servers limit i would see the “total audits on day” flat line. While i dont think this is an invalid assumption, it would take a few days for me to notice this…not cool. Then i had a better idea, i should measure how many times each user has been audited.
In general the way this application works is pretty simple. We check each users account once every 7 hours (ideally…) based on a queuing system. There are two “worker” processes, so I expect that ideally we should see around 10-12 audits per user per day (which is something like whats happening in reality), but whats most important from a “system health” type situation is that whatever the current level of “audits per user * 100″ is doesnt change too much from the previous day.
I’m sure there are a lot more details we can abstract out, but I just thought this was interesting and worthy of writing. Enjoy


