Ghost CMS advices
After some period of problems related to the complicated system dependent on many different node.js components, I had to redo the mechanism by which my GhostCMS based blog is launched on FreeBSD 13/stable.
First my experience on what to do when you find yourself in the situation where you can no longer start the Ghost app. In short, my approach is simple - don't bother trying to figure out which module is causing the problem. Just start clean.
Go to /usr/local/lib/node_modules directory on your freebsd machine.
Save the list of directories you see somewhere in a text editor.
ls -1 > ~/node-modules-list-backup.txt
Rename node_modules directory to node_modules.bak just in case.
cd /usr/local/lib/ ; mv node_modules node_modules.bak
Reinstall www/npm again.
Reinstall ghost-cli again.
npm install -g ghost-cli@latest
Install pm2 for easy management of node.js applications. Previously I used forever and the method already described in my blog here, but that's how I ended up with the incompatible combination of node-modules.
npm install -g pm2@latest
Here comes the point, how do you tell "pm2" to start and keep your blog (node.js app) up and running? Because I want the entire site to run on behalf of an unprivileged account, I've created an account called "ghost" for this application. I personally do the initial test launch like this:
sudo -u ghost -s NODE_ENV=production pm2 start current/index.js --name GhostCMS
I recommend also adding pm2-logrotate to keep your logs from overflowing.
pm2 install pm2-logrotate
After you are convinced that your site is working correctly, it is good to save the thus made configuration of pm2 running
You can monitor the behavior of a running node.js application using the following command
To be able to restart pm2 every time the FreeBSD host is restarted, so that it can in turn start and keep the ghost application running, you need to add the necessary rcd script to /usr/local/etc/rc.d/. For your convenience, I am implementing my version relying on already installed security/sudo. If missing install it
The standard built-in pm2 way of creating a startup using command "pm2 startup rcd -u ghost" does not create a convenient and working script, at least for me. My variant is published on github and you can easily download and install it like this.
cd /usr/local/etc/rc.d &&\ fetch https://raw.githubusercontent.com/jostreff/ghost-rc.d-script/main/pm2 -o pm2 &&\ chmod +x pm2
If you need to automate the process of updating your self-hosted ghost cms - take a look at this https://github.com/jostreff/ghost-cli-update/blob/main/ghost-cli-update