Run Ghost as a service using Supervisor

If you have been following my previous post on how to Install and run Ghost on a Raspberry Pi, then you should now have successfully done just that!

The next problem we face is getting Ghost to automatically run on boot, so that every time we need to reboot our Raspberry Pi, we don't need to SSH into the Pi and start Ghost manually.

Enter Supervisor

Luckily, it is easy to run Ghost as a service using Supervisor, so that when our Raspberry Pi boots up, Ghost is automatically started as a service.

First, we need to install Supervisor and then create a configuration file:

boo@ghostpi ~ $ sudo apt-get install supervisor
boo@ghostpi ~ $ cd /etc/supervisor/conf.d
boo@ghostpi ~ $ sudo nano ghost.conf

You'll then need to use the following code, assuming you have installed Ghost in the /var/www/ghost directory as outlined in the previous post:

[program:ghost]
command = node /var/www/ghost/index.js
directory = /var/www/ghost
user = pi
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/ghost.log
stderr_logfile = /var/log/supervisor/ghost_err.log
environment = NODE_ENV="production"

And finally exit (CTRL+X) and save (Y). We now need to tell Supervisor to look out for our new configuration file and to use this, which is done simply by:

boo@ghostpi ~ $ sudo supervisorctl reread
boo@ghostpi ~ $ sudo supervisorctl update

You should then see confirmation in the command line that the new Ghost service has been applied and is available.

Now, check that this all works fine by rebooting your Pi (sudo reboot now) and you should be able to access your vanilla Ghost blog by visiting the Pi's IP address followed by the :2368 port at the end of the URL (as setup in the previous post).

Next steps

If all has gone to plan, then you can now reboot your Pi and your Ghost blog will start automatically thanks to Supervisor. But using the port :2368 suffix on our URL is not very pretty, so to fix that we'll be using NGINX in our next post to redirect your visitors quickly and easily.


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!