Matt Hughes i like to grow tiny trees and tinker on stuff

Ghost on a Raspberry Pi

I've enjoyed running several different "always on" services on my Raspberry Pi, and this blog is one of them (node.js + Ghost behind nginx).

Some of my other services are an FTP server, a PHP/Apache server for testing freelance projects, and an IRC server (sushichat.no-ip.org/6667). Sometime in the future I plan to install Nagios for some basic network monitoring. I've also installed MysticBBS, but haven't had any luck accessing it via telnet.

By default, Ghost uses sqlite, but it also works with other databases. I wanted to try running it with PostgreSQL, since I've worked with MySQL in the past and wanted to try a different DB platform.

Using postgres as the database only took a few extra steps:

  1. Create a 'ghost' psql user
  2. Create a 'ghostblog' psql database
  3. Replace the existing connection block in the config with something like this:
database: {  
    client: 'postgres',
    connection: {
    host: '127.0.0.1',
              user: 'ghost',
              password: '***********',
              database: 'ghostblog',
              port: '5432'
            },
            debug: false
    }

The only thing that has annoyed me about running Ghost on the raspi was logging in. It wasn't unusual to wait 60+ seconds, only to be greeted by a 504 or other unknown error message. After a few attempts, I'd finally be able to access the admin section. I haven't had any performance problems with creating posts or changing settings.

Before I did much research, I suspected that the issue might be caused by postgres and node overloading the raspi on login. All of the "easy Ghost on raspberry pi" articles use sqlite, so I thought that my configuration might have over-complicated things on this hardware.

My migration plan was pretty low-tech. Since I only had 3 published articles and a couple unpublished, I just pasted the markdown into a text file. I reverted the config.js which got the sqlite database working. Then it was just a matter of re-creating the posts with the markdown that I have saved.

After all of that, I do seem to be logging in less slowly. It's still taking 45 seconds or more, so the improvement wasn't too great.

I did a bit more reading (here and here) and found that the bcrypt-nodejs library is very slow on a raspi. There is a workaround by installing and using bcrypt natively, but that does require changing some code in core/server/models/user.js.

For now, using sqlite as the database has seemed to alleviate the login errors. I'm content waiting 45 seconds or so to log in, as long as I'm not getting an error message. This login success could be completely coincedental, but it's good enough for my light use of this software.

If logging in continues to be a problem in the future, I will do some investigation on using the raspi's native bcrypt library and see if that helps.