Node red starts but not as a service

Hi,
I can start node red normally, but while installing it as a service it does not start, providing an error

Starting as a service, it does not work:

pi@raspberrypi:~/shared/mqtt-topic-logger/tlogs/tele/tasmota $ sudo systemctl start node-red
pi@raspberrypi:~/shared/mqtt-topic-logger/tlogs/tele/tasmota $ sudo systemctl status node-red
● node-red.service - Node-RED
   Loaded: loaded (/etc/systemd/system/node-red.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2020-01-06 15:56:38 GMT; 2min 3s ago
  Process: 2377 ExecStart=/usr/bin/node-red-pi --max-old-space-size=128 -v (code=exited, status=1/FAILURE)
 Main PID: 2377 (code=exited, status=1/FAILURE)

Jan 06 15:56:38 raspberrypi node-red[2377]:     at Object.<anonymous> (/usr/lib/node_modules/node-red/red.js:98:50)
Jan 06 15:56:38 raspberrypi node-red[2377]:     at Module._compile (internal/modules/cjs/loader.js:778:30)
Jan 06 15:56:38 raspberrypi node-red[2377]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
Jan 06 15:56:38 raspberrypi node-red[2377]:     at Module.load (internal/modules/cjs/loader.js:653:32)
Jan 06 15:56:38 raspberrypi node-red[2377]:     at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
Jan 06 15:56:38 raspberrypi node-red[2377]:     at Function.Module._load (internal/modules/cjs/loader.js:585:3)
Jan 06 15:56:38 raspberrypi node-red[2377]:     at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
Jan 06 15:56:38 raspberrypi node-red[2377]:     at startup (internal/bootstrap/node.js:283:19)
Jan 06 15:56:38 raspberrypi systemd[1]: node-red.service: Main process exited, code=exited, status=1/FAILURE
Jan 06 15:56:38 raspberrypi systemd[1]: node-red.service: Failed with result 'exit-code'.

Starting normally, it works

pi@raspberrypi:~ $ node-red-pi --max-old-space-size=256
6 Jan 15:38:57 - [info]

Welcome to Node-RED
===================

6 Jan 15:38:57 - [info] Node-RED version: v1.0.3
6 Jan 15:38:57 - [info] Node.js  version: v10.18.0
6 Jan 15:38:57 - [info] Linux 4.19.75+ arm LE
6 Jan 15:39:12 - [info] Loading palette nodes
6 Jan 15:39:51 - [info] Settings file  : /home/pi/.node-red/settings.js
6 Jan 15:39:51 - [info] Context store  : 'default' [module=memory]
6 Jan 15:39:51 - [info] User directory : /home/pi/.node-red
6 Jan 15:39:51 - [warn] Projects disabled : editorTheme.projects.enabled=false
6 Jan 15:39:51 - [info] Flows file     : /home/pi/.node-red/flows_raspberrypi.json
6 Jan 15:39:51 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

6 Jan 15:39:51 - [info] Starting flows
6 Jan 15:39:55 - [info] Started flows
6 Jan 15:39:55 - [info] Server now running at http://127.0.0.1:1880/
6 Jan 15:39:55 - [info] [mqtt-broker:localhost] Connected to broker: mqtt://localhost:1883
^C6 Jan 15:50:12 - [info] Stopping flows
6 Jan 15:50:13 - [info] [mqtt-broker:localhost] Disconnected from broker: mqtt://localhost:1883
6 Jan 15:50:13 - [info] Stopped flows

Working on a Raspberry Pi Model B Revision 2.0 - 512MB, with Raspbian Buster Lite.

pi@raspberrypi:~ $ node --version
v10.18.0
pi@raspberrypi:~ $ npm --version
6.13.4

node red was installed using

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

I don't know where node-red.service came from, perhaps it came with the default raspbian install, but the one installed by the recommended script is nodered.service, so try
sudo systemctl start nodered

1 Like

The error log from the system start version is limited to just a few lines and doesn't show what is actually causing the issue I don't think.

You will need to list more of the log. Something like sudo journalctl -u node-red -n 50 should do it I think.

The docs on the Pi page say to use it as a service to do

sudo systemctl enable nodered.service
1 Like

Just to note that that command enables starting on boot, it does not actually start the service.

1 Like

Yes and they also say to use

node-red-start

to manually start it

That is a good way of starting it as it starts the service and then shows the log, it is equivalent to something like

sudo systemctl start nodered
node-red-log

The fundamental problem that @tiagonmas has is probably that he is using the wrong service name, as I noted earlier.

1 Like

Thanks! that was it.
I created the service definition based on a post on stackoverflow.
using the service you mention did the trick. THANKS

Don't forget to remove the one you created or you may get confused again in the future. :slight_smile:

1 Like