Keeping Nodebb running after power outage
-
Ocassionally my nodebb stops, maybe powerglitch.
When I restart with ./nodebb start it says
Process "3913" from pidfile not found, deleting pidfile
What is that about?Also what is the best system / command to use to get nodebb to restart on its own after powerglitch?
-
@eeeee NodeBB tracks the running process with the pidfile, so if the process already doesn't exist, it deletes the pidfile.
See the systemd system in the docs
Running NodeBB - NodeBB Documentation
Documentation portal for NodeBB Forum Software
(docs.nodebb.org)
-
@PitaJ Im a bit confused with this systemd file.
Like why does this file need a link to the docs?[Unit] Description=NodeBB Documentation=https://docs.nodebb.org After=system.slice multi-user.target mongod.service [Service] Type=forking User=nodebb WorkingDirectory=/path/to/nodebb PIDFile=/path/to/nodebb/pidfile ExecStart=/usr/bin/env node loader.js --no-silent Restart=always [Install] WantedBy=multi-user.target
Replace the value of User (currently set to nodebb, above) with the system user you wish to run NodeBB, and the path to NodeBB (/path/to/nodebb) as appropriate. You'll most likely want to set the User to a system user with as few privileges as possible.
On my server I just have the account I log in with. should I make another user?
Also is the above method better than using nodemon?
-
@eeeee said in Keeping Nodebb running after power outage:
Like why does this file need a link to the docs?
It doesn't. Feel free to omit that line if you want.
@eeeee said in Keeping Nodebb running after power outage:
On my server I just have the account I log in with. should I make another user?
It's best practice, but it depends on whether that user is used for other things. If you're only using that user for NodeBB, then it's fine. But if you're using it for other stuff, it adds a bit of risk.
@eeeee said in Keeping Nodebb running after power outage:
Also is the above method better than using nodemon?
Nodemon is mostly a tool for development, not for running things in production. And it doesn't handle starting things when your server reboots like the systemd service will.
-
EDIT: Oh, I was late...
To answer in a bit of reverse order:
@eeeee said in Keeping Nodebb running after power outage:Also is the above method better than using nodemon?
It's not really doing the same thing as nodemon - the latter is mainly for watching file changes and restarting the application in that case. However, it's not tied to system init in any way, if the system restarts (eg. due to a power outage) it just dies in the process and you need to start it manually afterwards.
Systemd is a software suite which includes the init system and service management, and it's used by majority of modern Linux distributions. The file here is a service unit definition for systemd, and since the same suite handles the init as well you can trivially configure the system to start your service on boot (this is what thesystemctl enable
command does)Systemd also has facilities for doing a lot of other things like timers, watching file paths, etc. but they're not as commonly used as services, so a common configuration might be to use a systemd service to run something like nodemon or PM2 instead of using the harder to configure built-in tools.
On my server I just have the account I log in with. should I make another user?
Nothing is stopping you from using the same user, there are some security advantages to separating services but it's not unique to running as a systemd service so it won't decrease your security compared to your current setup.
Like why does this file need a link to the docs?
It doesn't - it really is just for the sysadmin (in this instance you) to see a link when they're looking at the service and eg. want to debug something. If you feel you don't need it just leave it out - for units I write for myself I usually wouldn't add it, mostly since there wouldn't really be much relevant documentation - but since someone was already writing a pre-made unit file, why not include something nice that might be very occasionally helpful at a cost of just around 40 bytes of disk space being taken?