matt-helps

insight on all things techie

dnscurl.pl name lookup timed out (Amazon Route53)

Had some problems this morning migrating one of my domains routing over to route53, and google can’t find anyone talking about this issue so (as is my policy) I thought I had better make the information available for other people facing the same issue. I was attempting to use dnscurl.pl to create a hosted zone but would come back with the error:

curl: (6) name lookup timed out
Ouch, curl --progress-bar -I --max-time 5 --url https://route53.amazonaws.com/date --insecure failed with exit status 6

I couldn’t work out whether it mean that some sort of insecurity had made it fail (please use quotes to show where the command ends in future!). So I ran the command above (from curl onwards) on its own to see what would happen:

curl --progress-bar -I --max-time 5 --url https://route53.amazonaws.com/date --insecure

…and sure enough, back came the error:

curl: (6) name lookup timed out

Ok, so its time out or the site isn’t up at all, not a security related issue. I then browsed to https://route53.amazonaws.com/2011-05-05 (correct at the time of publishing) and found that it took more than 5 seconds, but that it did eventually connect. It came back with:

UnknownOperationException/

So the site is working and up, but that it was taking quite a while. In the above curl command we’re just giving it 5 seconds to respond which isn’t too long in the world of requests really, so I altered the above command to set the time-out to be 15 seconds rather than 5 and it worked fine (http code 200):

curl --progress-bar -I --max-time 15 --url https://route53.amazonaws.com/date --insecure

So somewhere in dnscurl.pl there’s a line similar to the above one but it only allows 5 seconds for a response, absolutely not long enough, so we need to change it to something more sensible, perhaps 20 or 30 seconds will do. I’ve never played with perl, but how different can it be right? I openned dnscurl.pl in an editor and found what looked like the right reference to CURL on line 190 (your results may vary), which looks like this:

my $curl_output_lines = run_cmd_read($CURL, "--progress-bar", "-I", "--max-time", "5", "--url", $url, "--insecure");

Simply changing the number 5 to a 30 seemed to solve the problem because the next time I called dnscurl.pl it all worked splendiferously.

monodroid: System.NullReferenceException in aresgen.exe

Just in case anyone else gets this uninformative error on their monodroid packaging, I got mine when I included an ImageView in my layout and this highlighted two problems.

1. I got the useless message because I hadn’t created an AndroidManifest.xml file, new projects don’t have them by default, so right-click on the project, go to properties, then Android Manifest, and create one. Fill in some details, the file needs to exist anyway, but you can get away with not having one until you put an ImageView in there.

2. Then when you rebuild the project you’ll get a sensible message out of aresgen.exe, which for me was an incorrectly spelt resource name. My .png file was in the correct directory (Resources/Drawable) but I’d misspelled it by one letter.

Hope this saves someone else 30 minutes of searching around for answers.

Code Snippet: 301 redirect with args

If you ever need to redirect one domain name to another (using apache) and you need to do it in code you can simply create a .htacess file in the root of the folder that needs to be redirected and pop the standard 301 redirect in there. That doesn’t really help though if you want all the subdirectories of your old domain name to map to the new one, in which case pop the following in:

RewriteEngine On
RewriteRule ^.*$ http://example.com/$0 [R=301,L]

Obviously switch example.com for your domain name and any requests which hit this folder or below will be redirected and keep the subfolders, filename and any arguments that were passed on. You can also do some interesting things with the user agent. For instance, if you want to only forward search engines you can add a rewrite condition such as the following which will only redirect altavista and lycos’ search engine bots. This is called cloaked forwarding and is usually against the terms and conditions of the search engines (ie, they will penalise you if they think you’re forwarding their bots but not users), so don’t do it unless you really hate that user agent!

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} AltaVista [OR]
RewriteCond %{HTTP_USER_AGENT} lycos
RewriteRule ^.*$ http://example.com/$0 [R=301,L]

Using a (free!) Amazon EC2 Micro instance for SVN

Amazon do a free low power/memory/everything server called a Micro Instance. This is perfect for a bunch of websites that don’t get used much or even as an SVN server. Did I mention it was free?

Setting up SVN looks tricky at the outset, but it really isn’t. Assuming you’ve already got an AWS account…:

1. At the AWS management console “Launch Instance”, go to “community AMI’s” and select Alestic’s latest 32-bit Ubuntu build (you can find a list at alestic.com – click on the region you want (ie US-East 1), and then copy the AMI-1234567 and paste it into the search box on the “community AMI” AWS page. There should be a star next to it to indicate that it will be free micro instance. Click select to use that AMI.

2. Make sure the instance type is micro. If you can’t select a micro instance then you need to use a different AMI (or a different region). Then follow the options and set up the server as you would normally. I won’t cover that here (there are plenty of tutorials out there for setting up an instance), though do get yourself an elastic IP and assign it to the new instance.

3. Now your instance is running you need to open up TCP port 3690 for the SVN service to hear from the outside. Find the security group that your instance is using, select it, click on the “inbound” tab, and add a new rule: TCP, 3690, 0.0.0.0/0 and then click “add rule” and then “apply rule changes”.

4. SSH into your instance and run the command “sudo apt-get install subversion” to install svn

5. Create the directory to be used for subversion, for example “mkdir ~/svn”. Your projects will go inside this folder. The newer instances may require you sudo the commands if they don’t work – if you do use sudo you’ll need to change the permissions or ownership on the svn folder and subfolders.

6. Create the project: “sudo svnadmin create ~/svn/myproject”, again you may need to set the permissions here “sudo chmod -R g+rws ~/svn”

7. Under the new project directory (in the conf subfolder), edit svnserve.conf, remove the # before “anon-access” and change it to “none”, then remove the # before “auth-access” and “password-db” lines. Remove the # before the “realm=” and give it a custom name.

8. Edit passwd, add a line entry with the user name(s) and password(s) to be used for access.

9. The SVN server will work locally, but we need it to respond to remote instructions, so set up the service by calling “svnserve -d -r ~/svn” Now in your SVN client of choice commandline (why?), TortoiseSVN (windows) or RabbitSVN (linux) you can access via the SVN protocol: svn:/// using the username and password you set in the passwd file in step 8.

If your instance is rebooted you’ll need to SSH back in and repeat step 9. In order to have it start automagically at boot up follow MichaƂ Wojciechowski’s instructions under “Svnserve Initialization Script” which worked for me!

The wonder of xargs

If you’re ever sat at the linux commandline and had a repetitive task to complete on some files or directories then you’ll find “xargs” together with “find” a very useful combination.

Find will return a list of files and directories, one per line which can be piped into xargs so that the same command can be repeated on each file found, for instance:

find *.png

Will find .png files in the current directory. If you wanted to change the permissions on just these .png files you could then pipe the output into xargs:

find *.png | xargs chmod 775 -v

The other day I wanted to change the permissions for a subfolder called “logs” that was in 10+ folders:

find . -maxdepth 2 -name "logs" | xargs chmod 755 -v

Naturally, one should test the find to see what is returned before piping the result into an xargs, especially if you’re doing something that cannot be easily undone (like rm for instance).

The final thing that is worth knowing about is argument replacement. All the above examples assume that it is ok to put the result of the find command on the end of the xargs command, but if you were doing a rename operation or a copy this wouldn’t be the case. In the case below I’ve used the -I xargs command to define an identifier which will be swapped for the result from find:

find . -maxdepth 2 -name "logs" | xargs -I xxx mv xxx xxx.l

So if one of the lines coming from find is “subfolder/logs” then the mv command executed will be:

mv subfolder/logs subfolder/logs.l

A useful tool.


Follow mattparkins on Twitter