NodeBB wont stay up using systemctl
-
So before I begin, I am somewhat new to Ubuntu and this is my first NodeBB install, so I may have missed some basics here.
I have NodeBB installed on Ubuntu 16.04.3 x64. That was relatively easy, works a treat if I use the "./nodebb start" command from the install directory. The part where I am having trouble is I want NodeBB to be fired back up on reboot or failure automatically and I want to use the systemctl commands because it is natively available and because I don't want to further complicate things for myself.
I have a "nodebb.service" file in /etc/systemd/system/ and it is a copy and paste from the NodeBB run up instructions with the user and path/to/nodebb parts set to my environment ...
... When I do "systemctl start nodebb" or "service nodebb start" and I look at "journalctl -u nodebb" I get this...
That is the entire log output for that one "systemctl start nodebb". So you can see it launches nodeBB and immediately fails, repeats this process a few times and eventually times out / hits some kind of flood limit.
There is nothing in /var/nodebb/logs/output and nothing new in /var/log/syslog that isn't already in the journal linked above.
I honestly don't know for certain if it is a NodeBB problem or my Ubuntu knowledge, I'm leaning towards NodeBB. Can anyone help please?
-
Looks like you're instructing systemd to start nodebb by calling
nodebb
with no arguments, which prints the help file.Try changing the exec file to
node loader.js --no-daemon --no-silent
Where
node
is the path to your local node.js executable -
ok so, I spent a lifetime searching the forums and google tonight to try and solve this same problem.
The docs here docs.nodebb are clearly wrong for the systemd config file in Ubuntu LTS, it should look like this ...[Unit] Description=NodeBB forum for Node.js. Documentation=http://nodebb.readthedocs.io/en/latest/ After=system.slice multi-user.target [Service] Type=simple User=nodebb StandardOutput=syslog StandardError=syslog SyslogIdentifier=nodebb Environment=NODE_ENV=production WorkingDirectory=/opt/nodebb ExecStart=/usr/bin/node loader.js --no-daemon --no-silent Restart=always [Install] WantedBy=multi-user.target
This is not my work, it came from here. https://community.nodebb.org/topic/10648/nodebb-service-failing-to-start-after-server-reboot
hope this helps others out. Not sure how to get the docs changed at the above URL.
Duke
-
Would you mind opening an issue on Github for that?
-
@julian yes sorry, I did have that originally. I forgot that I started messing with my system start script. It didn't work with what was on the install documents, copied and pasted with my local system variables changed (path to NodeBB etc).
I have just tried @Duke 's script and it works perfectly @teh_g , I just updated the "WorkingDirectory" line to point to my NodeBB install. In my case, it was being run by the user "nodebb" so I didn't have to change that.
Thank you everyone for the replies.
-
I've posted something about this on here a while ago:
Empty Log
Yep that works, I updated my version here: https://gist.github.com/bdharrington7/2599927d41d30f11900f2099b8d8fc64
NodeBB Community (community.nodebb.org)
-
one important step which I have not seen here is:
systemctl enable nodebb
So for those wondering why it is not starting up after a reboot... this is the cause.
*side-note: Wait a few minutes for it to start up (if mongod/redis is on the same server)
-
@adam-poniatowski If you have to wait a few minutes for MongoDB to start up, then I bet there's some sort of systemd command to wait until the MongoDB process is up...
-
@julian yeah, its in the [unit] field in After= ... just add mongod.service and that should help, but it is not really needed.
It will keep restarting until it is working... if the service has been enabled
I tested it out a few weeks ago. One server has it, the other doesn't have it and both took the same amount of time, unfortunately. The reason is, mongod will report as started/alive/online... but the other dependencies did not start yet (one way to test, is to stop the mongod service, start it up again and immediately try to access the DB... mongod will report an error for a minute or 2, despite reporting that the service has started)
-
@adam-poniatowski I was thinking about your post and it was bugging me as I was sure i'd seen this command in the docs. Flipping through them, I found the command you describe but its in the wrong spot (install as opposed to auto run). Also realised we never actually tell the user to start Mongod service when describing how to make nodeBB autorun.
Described all this in a new ticket to get the docs updated.
https://github.com/NodeBB/NodeBB/issues/5924 -
@duke The "After=" should be in the [unit] field, as you are specifying it to start after specified services. By default (sort of) it is network.service, so that the service will start, only after the network service has started (however, it does not check if there is network connectivity, just if the service has started).
I hope that clarifies things. Maybe one should add that to the docs, as some people will think that the After=network.service, anyotherservice.service will actually checks network connectivity or that the service is working.