Restarting NodeBB after a crash and at login

I ran in to a minor issue the other day with my NobeBB install, and woke up to find it had crashed. Not really a big deal, as it is super easy to restart. But restarting it manually after a crash, or system reboot is not ideal - there must be a better way. And of course there is, and its super easy using systemd. There’s official docs on how to set this up. But, it took me a little trial and error to get my setup working, so i’ll post my solution.

Setting up the systemd service

first of all we ssh into our sever, and once connected we create the systemd service file and place it in the correct location. I like to use nano - so this is the command to open/create a new file with nano in the right folder (at least on my Centos server):

nano /etc/systemd/system/nodebb.service

Then its just a matter of copy & pasting in the following to tell configure systemd to keep NodeBB running:

After=system.slice postgresql.service

User=[[your user name]]


WorkingDirectory=[[path to NodeBB]]
PIDFile=[[path to NodeBB]]/pidfile
ExecStart=/usr/bin/node [[path to your NodeBB instal]]/loader.js
Environment=NODE_ENV=production PORT=[[NodeBB port number]]


You need to replace:

  • [[your user name]] with your username
  • [[path to NodeBB]] to the location of you NodeBB install
  • [[NodeBB port number]] with the port number your NodeBB install runs on

Save the systemd service

Now we save the file, in nano its like this:

  • hold the ^ control and x keys to save
  • hit y then enter

Start the systemd service

To start the service, we do this:
systemctl start nodebb

And to enable the starting at login:
systemctl enable nodebb

Some useful commands

Heres some extra commands that will come in useful:
When making changes to the /etc/systemd/system/nodebb.service file, you will need to reload it in systemctl like so:
systemctl daemon-reload

To stop the service, we do this:
systemctl stop nodebb

And to disable the starting at login:
systemctl disable nodebb