Tunnelling into your Chef Kitchen Vagrant instance

So you’ve just done this:

And now something has gone wrong on the box and you need to tunnel through to check something on your instance (say mysql database). Whatever the port may be, you need to change your current directory to where the vagrant file is. This can be achieved by running the following command relative to where your kitchen file is:

List the directory and you will be able to see a Vagrantfile in it. Once you are there, run:

Here I’m using mysql port 3306, you can replace it with whatever port you want to tunnel through.

If you want to tunnel multiple ports, run:

Repeating -L <BIND_ADDRESS> multiple times.

Fixing ubuntu desktop’s wifi disconnect issue on wake

For about more than half the time, when I wake my ubuntu laptop from sleep, I will lose wifi. When I say lose, I mean I lose the wlan0 interface completely.

Now this is a problem because I quite like having wifi and normally there seems to be no way to turn it back on from that little wifi menu from the top right corner.

After doing some googling, I found a crude yet simple solution. Restart the network-manager service by running the following:

Right before writing this article, I had to run that command and now it all works buttery smooth. Maybe there is a more permanent fix, I will keep an eye out for it and when I can find some time, will dig in to some logs somewhere to actually find the issue but for now, this is satisfactory (meh) to my current needs.

Download and store a website’s public cert into a Java keystore

The other day I had to download a public cert from a web service’s host and store it in my java keystore so that it can be trusted. Here’s what I did:

The first line downloads the public cert from www.manthanhd.com and stores it in /tmp/www-manthanhd-com.cert.

Next, we’re using keytool to import that certificate into the Java cacert keystore. I am only using sudo here because Java is installed as root. If in your case its not, you can just use the keytool command without the sudo prefix.

Also, on my test box, the java keystore has the default java keystore password which is changeit. Make sure this matches whatever your keystore password is.

Last but not least, the alias that the cert is imported against is important because this is what you will have to use to later find it. In this case I’m just using the hostname without any punctuations. This way, I can easily find any cert I want for any host if I need it.

Thanks to Jamie Tanna (jvt.me) and Jack Gough (testingsyndicate.com) for their help on this.

Minimal Express server setup for API development

Initialise npm with defaults.

Create your main index.js entrypoint.

Install express, body-parser, morgan and winston packages.

Make your index.js look like this.

This is probably one of the most light weight node.js configuration that I have ever written for building simple REST web services.

In my opinion, this is a good starting point as it makes minimal assumptions about what you might need, letting you add whatever you need minimally on top.

Appending to crontab using a single shell command

Usually to edit crontab for a user, you login as that user and then run:

This usually opens up a text editor which then lets you edit the crontab. Once you are done, you save and quit, and this magically updates your crontab.

Today I was writing a script that needed to update crontab without any user interaction. After doing some digging, I found this neat way of updating my crontab;

The above example is straight out of my shell script which renews my letsencrypt certificate and then restarts the nginx server.

%d bloggers like this: