> ## Content Index
> Fetch the complete content index at: https://ostreff.info/llms.txt
> Use this file to discover other available public pages before exploring further.

# Ghost CMS advices
- URL: https://ostreff.info/pm2-rcd/
- Published: 2022-10-21T15:26:18.000Z
- Updated: 2022-10-21T15:55:23.000Z
- Author: Jordan Ostreff
- Tags: FreeBSD, #ghost

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](https://ghost.org/?ref=ostreff.info) 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. 

```bash
cd /usr/local/lib/node_modules
```

Save the list of directories you see somewhere in a text editor. 

```bash
ls -1 > ~/node-modules-list-backup.txt
```

Rename node\_modules directory to node\_modules.bak just in case. 

```bash
cd /usr/local/lib/ ; mv node_modules node_modules.bak
```

Reinstall [www/npm](https://www.npmjs.com/?ref=ostreff.info) again.

```bash
portmaster www/npm
```

Reinstall [ghost-cli](https://ghost.org/docs/ghost-cli/?ref=ostreff.info) again.

```bash
npm install -g ghost-cli@latest
```

Install [pm2](https://pm2.keymetrics.io/?ref=ostreff.info) for easy management of node.js applications. Previously I used [forever](https://www.npmjs.com/package/forever?ref=ostreff.info) and the method already described in my blog [here](https://ostreff.info/automate-ghost-update/), but that's how I ended up with the incompatible combination of node-modules.

```bash
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:

```bash
sudo -u ghost -s
NODE_ENV=production pm2 start current/index.js --name GhostCMS 
```

I recommend also adding [pm2-logrotate](https://github.com/keymetrics/pm2-logrotate?ref=ostreff.info) to keep your logs from overflowing.

```bash
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

```bash
pm2 save
```

You can monitor the behavior of a running node.js application using the following command

```bash
pm2 monit
```

![](https://ostreff.info/content/images/2022/10/image.png)

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

```bash
portmaster security/sudo
```

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.

```bash
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](https://github.com/jostreff/ghost-cli-update/blob/main/ghost-cli-update?ref=ostreff.info)