Restart Node-RED Windows Service using the Exec Node in Node-RED

I'm hoping someone might be able to help figure this out. I have Node-RED running on a Windows Server and it is setup as a Windows Service using NSSM (Non-Sucking Service Manager). I was hoping to be able to use an Exec node to run the command nssm restart Node-RED which works as expected when run directly from the command line but it seems to only stop the service when it is run using the Exec node in Node-RED... it never starts the Service back up?

Any ideas as to why this might be and how I might get it to work?

I could be wrong here.... But......

Using an Exec Node - it will fire up a child process of the node process (that Node RED is running under)

The moment nssm kills the node process (to restart it), the child process (in this case nssm) is also being killed - stopping it from starting up node after.

nssm has to stay alive for it to start a new node process - but it cant, becuase it got killed (as it was started from the node process, that is being killed)

At least that is what i think is going on.

I cant be sure, but I think the exec node has options in how process's are started? (i don't is use it much)

try powershell -command "Restart-Service name_of_service -Force" or look into the sc command. alternatively, setup the service to auto restart and simply kill it (let it auto restart)

That said...

this looks like a sledgehammer approach to cracking some problematic nut. Why are you wanting to restart the service anyhow?

We have a UI setup to run our industrial LASER marker and occasionally (rarely) the SQLite database that is used in that flow gets 'locked' (can't figure out what or why) but the only way I've found to fix it is to simply restart Node-RED so that it kills the SQLite node and forces it to reconnect to the DB file.

This being the case, I wanted to add a button to the UI to allow the user to force this when the problem occurs.

Have you tried restarting flows? If that fixes it, then you can easily command node-red to restart its flows by a remote button on dashboard.


I haven't been able to get the restart flows to work from within Node-RED either... which is why I was trying to restart the service.

I've looked at the documentation here but perhaps I'm not understanding how to do it (which is quite possible).

Is there a simple example flow for this?

BTW, the suggested powershell -command "Restart-Service name_of_service -Force" method did work.


(You should mark that reply as the solution.)

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