So, I’ve been doing a lot of work with Vagrant recently. Vagrant has been very handy when working in teams in order to have a common point of reference for development, especially when the application we were collaborating on requires helper services (such as Node servers and ElasticSearch) to be started.

Here are a couple of gotchas that caused me a whole bunch of headaches, hopefully this’ll make things easier for you.

Don’t mount to /home/vagrant

In hindsight, this is a stupidly obvious, but at the time I had tunnel vision with a couple of other things didn’t get this until I had an “oh” moment.

The problem was that after provisioning, vagrant ssh would not connect via public key. However, booting the VM by hand using VirtualBox, this would work.

When I finally picked through my VagrantFile, commenting things out until things worked again, I realised my mistake in a facepalming moment. Obvious when you think about it, when you mount your working directory at /home/vagrant you clobber the ~/.ssh/authorized_keys file that had been inserted by vagrant up.

Man, I felt so dumb.

Careful what box you use

If you start getting some weird problems booting your box, you might want to try switching the base box.

I was using the Official Ubuntu 16.04 build as my base, but I was having no end of problems provisioning. More often than not, randomly through the provisioning process, the file system would become read only. I’d have to reboot and restart with the --provision flag, often several times, before I was able to get a box built.

I switched to an unofficial 16.04 box, and these problems went away.

I’m sure there’s a root cause for this issue, I’ll investigate later, but for now, switching VMs resolved it.

Avoid vagrant-vbguest unless you have to

The plugin vagrant-vbguest will update the VirtualBox guest additions on the guest machine, during provisioning, if they are missing or out of date.

This sounds like a great idea, but in my experience, it seems to cause more harm than good. Often, the older guest additions will work just fine, and installing the new additions over them often breaks something.

My view now is very much “if it ain’t broke, don’t fix it!”.

Be careful calling scripts within your startup scripts

If your provisioning or startup script itself calls another shell script, for example to start up custom services, you’re likely going to run into problems on Windows host machines.

Problems I’ve seen:

default: nohup:
default: failed to run command '/path/to/script.sh'

or:

default: -bash: /path/to/script.sh: /bin/bash^M: bad interpreter: No such file or directory

Both of these stem from the same cause, namely your script has been imported from the Windows host and it still has Windows line endings.

There are a number of solutions you could adopt, and the preference would be to avoid using shell scripts within scripts – vagrant should automatically convert line endings in scripts in your Vagrantfile, so try and only call scripts from there. If you must call scripts within scripts, as I had to do on a couple of occasions, you’ll need to convert line endings.

If this is a new project, you could configure git to make sure shell scripts are always binary. Or, convert line endings of your script before execution, e.g:

sed -i -e 's/\r$//' /path/to/script.sh

Hope all this helps!

Before migrating over to MySQL as the officially “blessed” database engine, Known previously used MongoDB.

The support for this was provided by the PECL extension ‘mongo’, which while supported in PHP5.4, was later deprecated and completely removed in PHP 7. This left early adopters, like myself, no upgrade path to PHP 7.

The end goal I believe, is to build a bullet proof import/export function into Known and get everyone over onto MySql, however in order to give us a little more runway, I took the opportunity to rewrite the mongo database driver to use the newer (and supported) MongoDB driver.

This pull request completely replaces the existing mongo code with a backwards compatible version built on the newer MongoDB driver, handling both database and GridFS.

Of course, while it does pass unit tests, this is a big change, so I encourage existing mongo users to kick it about for a bit, and also be sure to take a full backup of your existing stuff before rolling out this change.

Let me know your thoughts!

Like with other free software / indieweb projects, lot of development discussion regarding Known takes place on the IRC channel #Knownchat.

I lurk there, but I kept missing stuff, and besides it’s useful to have a log of some of the conversations. I think the founders were going to set something up, but since I know they’re very busy, I thought it’d be useful to hack something together until something better comes along.

So, I hacked together a quick bot IRC logging bot.

This bot outputs logs in Markdown, and I’ve set up a quick cronjob that will take those logs once a day and push them to a github repository for everyone to see.

Pending something better, I thought this might be useful. Standard caveat; these logs should in no way be considered “official” or endorsed by the project, I made them for my own use with hopes that they’ll be handy for other folk as well.

» View #Knownchat logs...