Fixing Ghost Upgrade Issues on Raspberry Pi

Updating Ghost to v1.21.1 can break your blog on Raspberry Pi. Read this guide to fix the upgrade problem in a few quick steps!

Fixing Ghost Upgrade Issues on Raspberry Pi

If you've been following Ghost Pi and the guides on installing Ghost v1.x.x on Raspberry Pi, then you'll know how temperamental it can be at times!

Now that it is possible to install Ghost v1.x.x on Raspberry Pi using the new Ghost CLI tool, things are starting to get simpler for us Raspberry Pi users. However, we recently encountered an issue when upgrading my blog from v1.20.3 to the latest (at the time of writing), v1.21.1.

Before you update to v1.21.1, please read this guide in full. You need to make some minor changes to a key file in the Ghost-CLI tool's source code first!


Updating Ghost on Raspberry Pi

Thankfully, due to the new Ghost CLI tool, updating your Raspberry Pi hosted Ghost blog is very easy! You simple do the following:

boo@ghostpi ~ $ cd /var/www/your_ghost_install_folder
boo@ghostpi ~ $ ghost update

This would use the Ghost CLI tool and automatically update your Ghost blog, and up until v1.21.1, this worked perfectly (we actually host 4 Ghost blogs on one Raspberry Pi, including a test blog) on three version updates.

Unfortunately, on v1.21.1 Ghost advise that you should update the CLI tool to the latest version by running:

boo@ghostpi ~ $ sudo npm i -g ghost-cli@latest

We then attempted to update our test blog using the tried-and-tested steps, but we were met with an issue when restarting Ghost:

boo@ghostpi ~ $ 
Starting Ghost
A GhostError occurred.

Message: Ghost did not start.
Suggestion: journalctl -u ghost -n 50

Debug Information:
    OS: Raspbian, v9.1
    Node Version: v6.12.3
    Ghost-CLI Version: 1.5.1
    Environment: production
    Command: 'ghost install'

Additional log info available in: /home/pi/.ghost/logs/ghost-cli-debug-2018-02-08T17_59_44_648Z.log

Try running ghost doctor to check your system for known issues.

Please refer to https://docs.ghost.org/v1/docs/troubleshooting#section-cli-errors for troubleshooting.

When we looked at the various logs and recommendations, nothing was obvious except for the following:

boo@ghostpi ~ $
Original Error Message:
Message: connect ECONNREFUSED 127.0.0.1:2368
Stack: Error: connect ECONNREFUSED 127.0.0.1:2368
    at Object.exports._errnoException (util.js:1020:11)
    at exports._exceptionWithHostPort (util.js:1043:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)

We were well and truly stumped!

Ghost's Slack community

For those of you who are unfamiliar with Slack, it is an increasingly popular communication tool (much better than email when at work) and the guys and gals over at Ghost have their own Slack community which you can join!

We joined and immediately headed for their #help channel and posted the information above.

Along came Vikas Potluri and helpfully suggested that the Raspberry Pi may be too slow and the updated Ghost CLI tool assumes Ghost is unable to start because the number of timeout checks has been exceeded. Bummer.

Never fear, it's a simple fix!

Thanks to Vikas' help, he pointed me towards the Ghost GitHub repository, specifically to the port-polling.js file and recommended altering the timing.

Benchmark your Ghost start time first!

Before diving in and editing the port-polling.js file, it is a good idea to benchmark your own Pi and Ghost install by running the following command:

boo@ghostpi ~ $ cd /var/www/your_ghost_install_folder
boo@ghostpi ~ $ ghost run

You'll get a warning that this is not the recommended method for starting Ghost, and this is used for benchmarking purposes (which we're doing now), but this will start your Ghost blog and give you the time it takes for this to happen. You should see a time on the last line.

Once you've got this time, which should be in seconds (ours was around 18.234s) you need to shutdown your blog by pressing CTRL+C.

Fixing the Ghost update issue for v1.21.1 on Raspberry Pi

Now we know roughly how long our Ghost blog takes to start, we need to tweak the relevant file, the port-polling.js file. This can be found in your NPM global root folder, which for us was /usr/lib/node_modules/ghost-cli/lib/utils/port-polling.js. Run this in your command line:

boo@ghostpi ~ $ sudo nano /usr/lib/node_modules/ghost-cli/lib/utils/port-polling.js

You'll need to change a few settings here, but please remember this is at your own risk as any changes here could potentially break your install if not done correctly!

We changed ours to look like the following (you can find the original over at the Ghost GitHub repository):

module.exports = function portPolling(options) {
    options = Object.assign({
        timeoutInMS: 2000,
        maxTries: 20,
        delayOnConnectInMS: 3 * 2000,
        logSuggestion: 'ghost log',
        socketTimeoutInMS: 1000 * 60
    }, options || {});

The key points here are the timings. We essentially doubled the timeoutInMS on line 8; the delayOnConnectInMS to 2000 and finally the socketTimeoutInMS to 1000 * 60. Finally press CTRL+X and Y to exit and save.

Go ahead and update Ghost!

Now, we can go ahead and update our Ghost blog to v1.21.1 but before you do that, make sure you backup your blog via the Labs section to export a .json file of your blog, then continue by running:

boo@ghostpi ~ $ cd /var/www/your_ghost_install_folder
boo@ghostpi ~ $ ghost update

Because we've added a longer delay in the new checking script, the upgrade process should now complete and you should now have the latest version of Ghost running on your Raspberry Pi!


If you found this guide, as well as any other guides on Ghost Pi helpful, then if you wanted to buy Ghost Pi a coffee to show your support, then that would be greatly appreciated! As this site does not use any form of adverts, all the costs for running and maintaining the blog are done voluntarily so any extra would be fantastic!

Buy Me A Coffee