Automatic restart of node red on failure

My node red is getting stopped by some nodes in between the operation. I want to automatically restart node red whenever it is automatically stopped. Kindly help me to do this?
As for IoT monitoring i need 24/7 operation.

What do you mean by

My node red is getting stopped by some nodes

Is node-red shutting down? What is stopping it?

What version of NR and node.js are you running?

I am using version 16
I am using azure iot hub node, i think that is causing the node to stop


But i need to restart node red automatically in case if it stopped unknowingly.

It really helps if you answer all the questions. I asked what version of NR and node.js and you replied:

I am using version 16

since the latest version of NR is v3.0.2 I guess the '16' you mention is for node.js and what version of Node-RE are you running?

  • what is the exact name (node-red-contrib-??) of the 'azure iot hub node' you are using?

When you want to share an error message, please copy and paste it to a reply, screen shots cn be hard to read and seeing what is in the log before an error can be very helpful.

Sorry for not providing complete information.
my node red version is version3.0.2
the node which caused the flow to stop is,
node-red-contrib-azure-iot-hub

pasting the error logs

21 Nov 10:24:06 - [info] Starting flows
21 Nov 10:24:06 - [info] Started flows
21 Nov 10:24:06 - [info] [azureiothub:Azure IoT Hub] JSON
21 Nov 10:24:06 - [info] [azureiothub:Azure IoT Hub] Connection to IoT Hub not established or configuration changed. Reconnecting.
21 Nov 10:24:06 - [info] [azureiothub:Azure IoT Hub] Connecting to Azure IoT Hub:
Protocol: http
Connection string :HostName=pipihub.azure-devices.net;DeviceId=pipidevice;SharedAccessKey=yj3l1XDjRvedr+3zNQZ+Dv6D5dCWy51yyMZq9noyYYs=
21 Nov 10:24:06 - [info] [azureiothub:Azure IoT Hub] Connected to Azure IoT Hub.
21 Nov 10:24:06 - [info] [azureiothub:Azure IoT Hub] Message is pending. Sending it to Azure IoT Hub.
21 Nov 10:24:06 - [info] [azureiothub:Azure IoT Hub] Sending Message to Azure IoT Hub :
Payload: {"TSE FLOW PRE DAY":1236,"TSE LOADING PRE DAY":243,"WAS FLOW PRE DAY":13,"TOTAL-INFLOW":null}
21 Nov 10:24:08 - [info] [azureiothub:Azure IoT Hub] Message sent.
06:24:09.169Z :client_session_impl :747 [NODE-OPCUA-W21] Pending transactions: ReadRequest ReadRequest ReadRequest ReadRequest ReadRequest ReadRequest ReadRequest ReadRequest ReadRequest ReadRequest ReadRequest
06:24:09.169Z :client_session_impl :748 [NODE-OPCUA-W22] Warning : your opcua client is sending multiple requests simultaneously to the server ReadRequest
... please fix your application code
21 Nov 10:29:39 - [info] Stopping flows
21 Nov 10:29:39 - [info] [azureiothub:Azure IoT Hub] Disconnecting from Azure IoT Hub
21 Nov 10:29:39 - [info] [azureiothub:Azure IoT Hub] close status: Disconnected
21 Nov 10:29:39 - [info] Stopped flows
21 Nov 10:29:39 - [info] Updated flows
21 Nov 10:29:39 - [info] Starting flows
21 Nov 10:29:39 - [info] Started flows
21 Nov 10:29:54 - [info] Stopping flows
21 Nov 10:29:54 - [info] Stopped flows
21 Nov 10:29:54 - [info] Updated flows
21 Nov 10:29:54 - [info] Starting flows
21 Nov 10:29:54 - [info] Started flows
21 Nov 10:29:54 - [info] [azureiothub:Azure IoT Hub] JSON
21 Nov 10:29:54 - [info] [azureiothub:Azure IoT Hub] Connection to IoT Hub not established or configuration changed. Reconnecting.
21 Nov 10:29:54 - [info] [azureiothub:Azure IoT Hub] Connecting to Azure IoT Hub:
Protocol: http
Connection string :HostName=pipihub.azure-devices.net;DeviceId=pipidevice;SharedAccessKey=yj3l1XDjRvedr+3zNQZ+Dv6D5dCWy51yyMZq9noyYYs=
21 Nov 10:29:54 - [info] [azureiothub:Azure IoT Hub] Connected to Azure IoT Hub.
21 Nov 10:29:54 - [info] [azureiothub:Azure IoT Hub] Message is pending. Sending it to Azure IoT Hub.
21 Nov 10:29:54 - [info] [azureiothub:Azure IoT Hub] Sending Message to Azure IoT Hub :
Payload: {"TSE FLOW PRE DAY":1236,"TSE LOADING PRE DAY":243,"WAS FLOW PRE DAY":13,"TOTAL-INFLOW":1323}
21 Nov 10:29:56 - [info] [azureiothub:Azure IoT Hub] Message sent.

You will need to contact the author of that node. The easiest way is to go to the node's GitHub repo and raise an issue there. Generally, node-red nodes should not crash node-red.

As for auto-restart, I don't think you've said where/how you are running node-red? The direct answer to your question depends on that information.

I am running node red on a windows 10 pc. The node red is directly installed on the PC. If you can help me out to set up auto restart in case of node-red failure, that would be great.
As for IoT data monitoring, we need node red operation 24/7.

Look into this video, it shows how to autostart Node-Red on Windows bootup. Instead of that you might schedule to start node-red on an event trigger, event being a custom event - filter it with the error/critical log as per your scenario

You have several options. The shared video is just one. Note that the video sets the startup to run when the user has already logged in, it won't start after a reboot until you've logged in. You can change that but then you either have to give the scheduler your id and password or tell it to use the SYSTEM account which means that you would be running node-red under system and that has different permissions to things.

An alternative that works especially well for development instances is to use PM2. You can use that for live running on Windows as well but it does have some overheads - though it is certainly more convenient for getting at logs, auto-restarting after critical file changes, etc.

The 3rd option is to use something like the nssm tool to create a Windows service from the node-red startup. However, people seem to be having lots of problems with nssm recently.

1 Like

thank you @SameeraAkbar for the video.
@TotallyInformation but those are just restarting node red on windows startup right. But i need the method to restart the node red, in case if it stops running while the os is running.

When you examined the proposed solutions you must have missed the fact that pm2 can restart an app on failure.

No, the Windows scheduler can auto-restart things as well. As can PM2 as Colin say's.

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