Automatically updating your self hosted Ghost install

Ghost version 0.9.0 has just been released, introducing awesome new functionality such as scheduled posting (which I am utilisng to post this :)). This is fantastic news, but I run three different self hosted ghost blogs and I only just updated to 0.8.1.

Whilst updating Ghost isn't exactly that difficult, it still takes time. Time which I sadly do not have. As an engineer it struck me as being somewhat ridiculous that I hadn't already written some sort of script to manage the upgrading of these various blogs. In fact, I am even more bemused that someone else hasn't done it either (seemingly).

The title is not strictly correct in that this is not actually automatic. It still requires you to execute the script, and to update multiple blogs you will need to modify it to take arguments. That said, it is a start. Something to get you thinking.

Pub Reviews has complex build scripts which checkout the latest versions of the source code, build the applications, run the test suites etc. Obviously nothing that complex is needed here, but given my experience with ssh, rsync and shell scripts more generally, I pieced together a simple script to update a Ghost blog on an external server from my Mac Book.

The code is embedded below:

Using it

There are a few considerations to note to correctly utilise this script.

  • It is based on the official Ghost upgrade document. Ghost could fundamentally change in the future (although it is unlikely) meaning that different files need to be updated.

  • To use the script you need to download the version of Ghost that you want to update to, and place it in a directory which you specify as the STAGEDIR variable.

  • This is a bare bones script. It has no saferty checks, and doesn't perform backups of your blog content. Make sure that you enter you enter your host/user details correctly, and be sure to backup your data prior to utilising this script.

  • My blogs are run utilising forever such that they don't go offline when I close my terminal.

  • I remove the node_modules directory completely, clean the npm cache, and do a fresh install of the various dependencies because I was encountering a number of dependency based issues when I did not do so.

  • You need to set up passwordless (key based) authentication for SSH connections to your external server. You don't need to do this - you can modify the code as you see fit, but in the interest of making it as quick and painless as possible it is something to consider. This answer on StackOverflow outlines how one can do this.

Thats it

Hopefully this is of use to you, and saves you a few vital moments every once in a while. If you have any questions, comments, or suggestions, let me know below.

Thomas Clowes

Thomas Clowes

I am a 28 year old software engineer from the United Kingdom. During the day I build multi platform applications. In my spare time I eat food and run marathons. Sometimes I write angry tweets.