Starting node-red at boot with systemctl

I have installed node-red on Bookworm, RPI5. I can start it manually but cannot get it enabled with systemctl to start at boot.

Blockquote

Jun 13 17:46:04 RPI5 systemd[1]: nodered.service: Failed with result 'exit-code'.
Jun 13 17:46:04 RPI5 systemd[1]: nodered.service: Scheduled restart job, restart>
Jun 13 17:46:04 RPI5 systemd[1]: Stopped nodered.service - Node-RED graphical ev>
Jun 13 17:46:04 RPI5 systemd[1]: nodered.service: Start request repeated too qui>
Jun 13 17:46:04 RPI5 systemd[1]: nodered.service: Failed with result 'exit-code'.
Jun 13 17:46:04 RPI5 systemd[1]: Failed to start nodered.service - Node-RED grap>
lines 1-14/14 (END)
Any help would be appreciated. Thanks
BG

For the sake of clarity:

How did you install Node-Red?
What command did you use to auto-start Node-Red?

Do you mean that sudo systemctl start nodered works, or you can start it with the node-red command?

After you reboot and it falls over, what does journalctl -t Node-RED --since today --no-pager output?

I am able to start it manually:

bg@RPI5:~ $ node-red
14 Jun 16:55:11 - [info]

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

14 Jun 16:55:11 - [info] Node-RED version: v3.1.10
14 Jun 16:55:11 - [info] Node.js  version: v18.20.3
14 Jun 16:55:11 - [info] Linux 6.6.31+rpt-rpi-2712 arm64 LE
14 Jun 16:55:11 - [info] Loading palette nodes
14 Jun 16:55:12 - [info] Settings file  : /home/bg/.node-red/settings.js
14 Jun 16:55:12 - [info] Context store  : 'default' [module=memory]
14 Jun 16:55:12 - [info] User directory : /home/bg/.node-red
14 Jun 16:55:12 - [warn] Projects disabled : editorTheme.projects.enabled=false
14 Jun 16:55:12 - [info] Flows file     : /home/bg/.node-red/flows.json
14 Jun 16:55:12 - [info] Creating new flow file
14 Jun 16:55:12 - [warn] Encrypted credentials not found
14 Jun 16:55:12 - [info] Server now running at http://127.0.0.1:1880/
14 Jun 16:55:12 - [info] Starting flows
14 Jun 16:55:12 - [info] Started flows

When I try to set it up to start at boot:

bg@RPI5:~ $ systemctl enable nodered
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-unit-files ====
Authentication is required to manage system service or unit files.
Authenticating as: ,,, (bg)
Password:
==== AUTHENTICATION COMPLETE ====
==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon ====
Authentication is required to reload the systemd state.
Authenticating as: ,,, (bg)
Password:
==== AUTHENTICATION COMPLETE ====
bg@RPI5:~ $ service node-red status
Unit node-red.service could not be found.
bg@RPI5:~ $ service nodered status
Ă— nodered.service - Node-RED graphical event wiring tool
     Loaded: loaded (/lib/systemd/system/nodered.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Fri 2024-06-14 14:31:17 EDT; 2h 16min ago
   Duration: 2ms
       Docs: http://nodered.org/docs/hardware/raspberrypi.html
   Main PID: 931 (code=exited, status=217/USER)
        CPU: 894us

bg@RPI5:~ $ journalctl -t Node-RED --since today --no-pager
-- No entries --

It seems to be installed but I can't enable it at boot. I'm not a programmer so am having trouble
understanding what is going on. I use NR to send MQTT data from sensors to my weather station (N4MRV-1 --- Ashland, Virginia Current Weather Conditions) which is now running on Ubuntu. I'm trying to move to a new server, RPI5 running Bookworm.
Thanks.
BG

How about
journalctl -u nodered --since today --no-pager

Also show us what is in /lib/systemd/system/nodered.service

1 Like

And what does
node-red-start
report ?

I'm not familiar with that inline authentication method. On my Pies I use sudo
sudo systemctl enable nodered or sudo systemctl start nodered

According to the internet, so it must be true :laughing:, error 217 means the service is setup with a username which does not exist.
Please show us your /lib/systemd/system/nodered.service file.

If journalctl -t Node-RED --since today --no-pager shows no entries, please try
sudo systemctl restart nodered and try again.

Ok, that did it. nodered.service had pi as user and I’m bg. Bookworm seems to boot and start NR correctly.
Much appreciated for the help in figuring this out!!
I may be back but this is a great start.
Cheers,
Bob

Can you explain how you installed Node-red, what username you used, and when you created the username bg?

Is your Node-red directory /home/bg/.node-red ?

The Raspberry Pi install script is certainly supposed to set up the service to run as the user who installs it, but there could still be a bug.

Much easer and safe is just install it in docker and write

restart: unless-stopped

in docker compose config, It is not really good idea to install things to host itself.

Although I normally would somewhat agree with this statement - but for node-red it is definitely not always the best option, especially when interfacing with devices on hardware level as node-red will not have access to those, one will need to go through quite some hoops to make that work within docker. Some nodes need to compile binaries, there is no compiler included in the docker container (unless customized).

One might argue not to use docker for node-red at all.

5 Likes

For those experienced in the use of Docker it can be very useful, for those without such experience I advise against using it for node-red. It causes more problems than it solves.

2 Likes

Hi jbudd,
To install, I used:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

When I setup the RPI5, I did it as "bg." Not sure why and I probably should have used the default as "pi." Anyway, My .node-red directory is in /home/bg.
Cheers,
Bob

If you were logged in as bg when you ran the script then it should have put bg as the user in the script. Are you sure you didn't run the script before you changed the user name?

No, it is a good idea to not use the default 'pi'. It slightly reduces the chance of being hacked.

For those who like/know docker (and similar environments) - indeed!

But I have to disagree with this statement, it is (IMO) by far NOT easier!
especially for those getting into automation/Node RED and everything in between.

2 Likes

Colin,
When I first installed the OS Bookworm on the RPI5 it was as “bg.” I never created user “pi” and don’t think it’s a valid user at this point. I hope this won’t cause later problems.
Cheers,
Bob

Well that is very odd, there is definitely code in the install that sets the user and group to the current user. I presume that you just had to change the lines

User=pi
Group=i

Could you post that file please so I can see if there are any clues as to what might have happened? /lib/systemd/system/nodered.service. There haven't been any other reports of that not working though, as far as I know.

No, it shouldn't cause any problems. That is the only place the user is used.

There are 4 lines with "pi" hardcoded in the systemd script as downloaded (/usr/lib/systemd/system/nodered.service)

User=pi
Group=pi
WorkingDirectory=/home/pi
EnvironmentFile=-/home/pi/.node-red/environment

The installer should have changed "pi" to the current username on all 4 lines.

2 Likes

Yes, you are right, I had forgotten the other two.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.