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

**URL:** <https://discourse.nodered.org/t/restart-node-red-windows-service-using-the-exec-node-in-node-red/81239>\
**Category:** General\
**Created:** [12 September 2023 14:17 UTC](https://discourse.nodered.org/t/restart-node-red-windows-service-using-the-exec-node-in-node-red/81239 "2023-09-12T14:17:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dudleyjosh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dudleyjosh/32/105799_2.png) [@dudleyjosh](https://discourse.nodered.org/u/dudleyjosh)\
**Post date:** [12 September 2023 14:17 UTC](https://discourse.nodered.org/t/restart-node-red-windows-service-using-the-exec-node-in-node-red/81239/1 "2023-09-12T14:17:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [12 September 2023 14:27 UTC](https://discourse.nodered.org/t/restart-node-red-windows-service-using-the-exec-node-in-node-red/81239/2 "2023-09-12T14:27:49Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [12 September 2023 14:32 UTC](https://discourse.nodered.org/t/restart-node-red-windows-service-using-the-exec-node-in-node-red/81239/3 "2023-09-12T14:32:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dudleyjosh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dudleyjosh/32/105799_2.png) [@dudleyjosh](https://discourse.nodered.org/u/dudleyjosh)\
**Post date:** [12 September 2023 15:02 UTC](https://discourse.nodered.org/t/restart-node-red-windows-service-using-the-exec-node-in-node-red/81239/4 "2023-09-12T15:02:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [12 September 2023 15:04 UTC](https://discourse.nodered.org/t/restart-node-red-windows-service-using-the-exec-node-in-node-red/81239/5 "2023-09-12T15:04:44Z")

</div>

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.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1b838c12fc762629520376fcb4efaca0b67acbd8.png)

---

<div class="post-metadata">

**Author:** ![dudleyjosh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dudleyjosh/32/105799_2.png) [@dudleyjosh](https://discourse.nodered.org/u/dudleyjosh)\
**Post date:** [12 September 2023 15:20 UTC](https://discourse.nodered.org/t/restart-node-red-windows-service-using-the-exec-node-in-node-red/81239/6 "2023-09-12T15:20:15Z")

</div>

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](https://nodered.org/docs/api/admin/methods/post/flows/) 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.

Thanks.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [12 September 2023 21:02 UTC](https://discourse.nodered.org/t/restart-node-red-windows-service-using-the-exec-node-in-node-red/81239/7 "2023-09-12T21:02:11Z")

</div>

(You should mark that reply as the `solution`.)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 September 2023 21:02 UTC](https://discourse.nodered.org/t/restart-node-red-windows-service-using-the-exec-node-in-node-red/81239/8 "2023-09-26T21:02:15Z")

</div>

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