Node-Red stopped running and didn't restart - first time occurrence - how to restart?

Hi, I have Node-Red running on RPI.

I use sudo systemctl enable nodered.service command to start Node-Red on boot. I then start Chromium in kiosk mode and use the Node-Red dashboard as a HMI.

I have had a first ever occurrence (that I am aware of) of Node-Red process stopping, or crashing. I have checked for Node-Red using pgrep -f node and confirmed there is no PID for the process. Chromium is still running but showing a blank screen

There is no terminal window showing the Node-Red logs. I have checked sysmlog and I can't find anything in reference to Node-Red.

I have run journalctl -u nodered -n 50 and its empty

I have run sudo systemctl status nodered and get the following which seems to imply something killed the Node-Red process

Can anyone provide some hints on

  1. How to figure out what went wrong?
  2. How to make sure Node-Red will restart automatically if it ever shuts down again? Should I be using PM2 according to this to start and manage Node-Red? Starting Node-RED on boot : Node-RED Will this cause any other issues on RPI with Node-Red? Or is there other options?

First thing is to figure out why it crashed. I would open a terminal connection to the Pi and start it by entering node-red

This way you will see the log of what is happening and if it crashes you can look at that log.

Remember to keep that terminal window open.

It stopped 5 days ago, so it is probably too late to find what killed node-red.

Please post the systemd script for node red. That is the file /lib/systemd/system/nodered.service (the systemctl status command you showed tells you that is it) so we can check it is configured to restart.

No, systemd, which is what you are using, is the right way.

The timeout error suggests that it failed to restart because node-red took too long to start up again, but I don't know why that would be.

In future, if possible please copy/paste logs and terminal output rather than screenshot.

node-red-start will start it using systemd, and show the logs, but you don't then need to keep the window open. If node red stops then you can use journalctl to inspect the log.

It was for 100% sure running last night when I went to bed and was not running when I woke up this morning.

Maybe that log from 5 days ago was me killing the process on purpose when I had issues with an infinte loop......

This is the first time I have seen it crash in years of it running, I dont know if running a terminal to try and capture the log would be useful. And journalctl is empty, I checked that.

Understand the screenshot thing, the Node-Red device is not connected to internet and its a hassle to copy things to USB thumb drive. A photo is easier, sorry about that.

systemd script below

# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html

[Service]
Type=simple
# Run as normal pi user - change to the user name you wish to run Node-RED as
User=pi
Group=pi
WorkingDirectory=/home/pi

Environment="NODE_OPTIONS=--max_old_space_size=2048"
# define an optional environment file in Node-RED's user directory to set custom variables externally
EnvironmentFile=-/home/pi/.node-red/EnvironmentFile
# uncomment and edit next line if you need an http proxy
#Environment="HTTP_PROXY=my.httpproxy.server.address"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
# uncomment next line if you need to wait for time sync before starting
#ExecStartPre=/bin/bash -c '/bin/journalctl -b -u systemd-timesyncd | /bin/grep -q "systemd-timesyncd.* Synchronized to time server"'

ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
RestartSec=20
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog

[Install]
WantedBy=multi-user.target

Not using the systemd script it wasn't.
How do you normally start node-red?

What do
journalctl -u nodered -f
and
systemctl status nodered
show now?

OK, in that case we will have to make do with photos.

Edit: In that case how are you getting the screenshot off?

Its a picture of screen with my phone.

Node-Red is normally started automatically on startup using sudo systemctl enable nodered.service. I can't remember, but I might have killed Node-Red when I had infinite loop issue and restarted in command line Node-Red-Start or maybe Node-Red --Safe and I may not have rebooted since then. So I gather this line of questioning is saying the Systemd was not in charge of Node-Red, when it crashed nothing restarted it.

So I guess I should restart with command line and keep the log open, maybe it is crashing more frequently but because Systemd is normally in charge it just restarts it, but I am not aware of the issue.

When I type journalctl -u nodered -f it says a single line -- Logs begin at Mon 2024-03-11 12:09:47
When I type systemctl status nodered it shows the black diaglog box above showing it failed

What happens if you do
node-red-stop
node-red-start

Node-Red-Start the system started Node-Red as normal, left it running all day, no problem
Node-Red-Stop the system stops, but something slightly strange that just occurred to me.

I have a touchscreen connected which is powered via a relay connected to the Pi. The screen turning on is triggered by Node-Red.

When I type Node-Red-Stop it turns the touchscreen off, which makes sense as Node-Red wont hold the relay closed.

But when Node-Red stopped working as per original post, the screen was still on. A bit odd...... Node-Red not running but screen relay held on...... and come to think of it, when I had the code entering an infinite loop by accident last week, when I typed Node-Red-Stop it would also allow the screen to stay on.

This is perplexing me a bit in retrospect, I hope this problem description makes sense.

And really appreciate the help so far, you guys are great. Thanks!

That is wrong. It is node-red-start. If you use capitals that is a different command.

After starting using the correct command does journalctl work?

It was node-red-start and node-red-stop. Yes journalctl has content in it

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