# Node-RED Self Restart

**URL:** <https://discourse.nodered.org/t/node-red-self-restart/432>\
**Category:** FAQs\
**Created:** [27 May 2018 10:46 UTC](https://discourse.nodered.org/t/node-red-self-restart/432 "2018-05-27T10:46:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![GChapo](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@GChapo](https://discourse.nodered.org/u/GChapo)\
**Post date:** [27 May 2018 10:46 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/1 "2018-05-27T10:46:37Z")

</div>

Is there a node red restart command available?

I have put a reboot command in an exec node which works well, but sometimes it maybe that node red requires a restart rather than the computer and I wondered if restart was available or was being considered? Obviously if I issue a node-red-stop through an exec node on the app I am unable to do anything further unless I VNC on to then start node red.

Can anybody advise please?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 May 2018 11:01 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/2 "2018-05-27T11:01:30Z")

</div>

It depends what OS you are running on. On a Debian based linux such as Raspbian then the command  
sudo systemctl restart nodered  
should do it, assuming you have installed node red using the pi recommended method.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [27 May 2018 11:17 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/3 "2018-05-27T11:17:04Z")

</div>

I think exec blocks calls to sudo as it’s a privilege escalation…

Can they be concatenated and called as a single call ?  
`node-red-stop && node-red-start`

PR always welcome

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 May 2018 12:27 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/4 "2018-05-27T12:27:18Z")

</div>

> [@dceejay](#):
>
> I think exec blocks calls to sudo as it’s a privilege escalation…

That is not my experience. On one of my Pis I have a watchdog which runs `sudo reboot` in a watchdog flow.

If the machine is setup to require passwords on the use of sudo then it is necessary to disable the password request for that command using `sudo visudo` to invoke the sudoers editor so in the case of reboot I have

```auto
myusername ALL=(ALL) NOPASSWD: /sbin/reboot

```

---

<div class="post-metadata">

**Author:** ![GChapo](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@GChapo](https://discourse.nodered.org/u/GChapo)\
**Post date:** [27 May 2018 13:05 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/5 "2018-05-27T13:05:14Z")

</div>

Thank you I will try this.

---

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [27 May 2018 19:27 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/6 "2018-05-27T19:27:16Z")

</div>

Ia have on an exec node the same that works for me on command line, directly: sudo service nodered restart

Regards

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [27 May 2018 20:03 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/7 "2018-05-27T20:03:47Z")

</div>

> [@dceejay](#):
>
> Can they be concatenated and called as a single call ?  
> `node-red-stop && node-red-start`

I seem to recall that `node-red-stop` will of course stop node-red, however because node-red is not then running, the second command `node-red-start` is not actioned. (I found this out the hard way whilst 200 miles away from home!!).

Paul

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [27 May 2018 20:07 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/8 "2018-05-27T20:07:12Z")

</div>

looks like `sudo service nodered restart` is the winner then !

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [27 May 2018 20:22 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/9 "2018-05-27T20:22:33Z")

</div>

Just to add - all of this presumes you are running on a Raspberry Pi or similar using the service scripts we provide. That is just one of many different ways that Node-RED can be run - so there will not be a one-size-fits-all restart command for Node-RED - it all depends on how its being run.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 May 2018 20:46 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/10 "2018-05-27T20:46:06Z")

</div>

sudo service nodered restart may still work but it is not the correct way of doing it on recent Debian systems such as Raspbian and Ubuntu. That command was obsoleted when systemd became the standard way of doing it with Jessie (I believe) in 2015. Use instead

```auto
sudo systemctl restart nodered

```

I note that node-red-start also uses the service command, ideally this should be updated since at some point it will stop working, though admittedly it may not be for a long time.

---

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [27 May 2018 20:58 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/11 "2018-05-27T20:58:25Z")

</div>

Consider I just started again working with linux since one year ago… more than 20 years out of the game

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 May 2018 21:20 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/12 "2018-05-27T21:20:41Z")

</div>

This got me wondering how the service command still works on a systemd based OS. Running `cat /usr/sbin/service` it seems that it is a wrapper script converting the service command to the appropriate systemctl one.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [27 May 2018 22:15 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/13 "2018-05-27T22:15:25Z")

</div>

Yes its a wrapper around various ways of doing it (on Linux), so is actually the most transportable way to do it. No need to "fix" it.

> <https://askubuntu.com/questions/903354/difference-between-systemctl-and-service-commands>

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 May 2018 08:09 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/14 "2018-05-28T08:09:08Z")

</div>

> [@dceejay](#):
>
> Yes its a wrapper around various ways of doing it (on Linux), so is actually the most transportable way to do it. No need to “fix” it.

Good point, though I notice that node-red-start (on pi) does assume that the OS uses systemd. You are right however, there is nothing wrong with using the service command.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [28 May 2018 15:39 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/15 "2018-05-28T15:39:34Z")

</div>

In case you want a flow - this works on a Pi and should work on any modern Linux (that uses systemd which is most of them).

```auto
[{"id":"384924bd.c7b6dc","type":"exec","z":"106a5b82.ef95a4","command":"sudo systemctl restart nrlive","addpay":true,"append":"","useSpawn":"","timer":"","name":"","x":873,"y":617,"wires":[["c8f2f6f1.370d08"],["c8f2f6f1.370d08"],["c8f2f6f1.370d08"]]},{"id":"5c9d8978.a36278","type":"inject","z":"106a5b82.ef95a4","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":674,"y":617,"wires":[["384924bd.c7b6dc"]]},{"id":"c8f2f6f1.370d08","type":"debug","z":"106a5b82.ef95a4","name":"","active":true,"console":"false","complete":"false","x":1143,"y":617,"wires":[]},{"id":"46129a4f.b9ed64","type":"comment","z":"106a5b82.ef95a4","name":" **DANGER!: Restart the Node-Red service**","info":"","x":770,"y":580,"wires":[]},{"id":"85941f67.76613","type":"inject","z":"106a5b82.ef95a4","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":673,"y":708,"wires":[["f5f9bc5a.5ab3f"]]},{"id":"f5f9bc5a.5ab3f","type":"exec","z":"106a5b82.ef95a4","command":"sudo reboot now","addpay":false,"append":"","useSpawn":"","name":"","x":842,"y":708,"wires":[["e5e0f45f.0287f8"],["e5e0f45f.0287f8"],["e5e0f45f.0287f8"]]},{"id":"e5e0f45f.0287f8","type":"debug","z":"106a5b82.ef95a4","name":"","active":false,"console":"false","complete":"false","x":1142,"y":708,"wires":[]},{"id":"5714af73.78418","type":"comment","z":"106a5b82.ef95a4","name":" **DANGER! Reboots the Pi running Node-Red, InfluxDB and MQTT**","info":"","x":847,"y":672,"wires":[]},{"id":"7e632c5f.0a5944","type":"comment","z":"106a5b82.ef95a4","name":"TODO: Remove service name and pull from settings instead","info":"","x":1160,"y":580,"wires":[]}]

```

It has a flow for restarting Node-RED and one for rebooting the Pi. Works fine assuming that sudo is configured **not** to ask for an additional password when running these commands.

---

<div class="post-metadata">

**Author:** ![GChapo](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@GChapo](https://discourse.nodered.org/u/GChapo)\
**Post date:** [28 May 2018 15:51 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/16 "2018-05-28T15:51:48Z")

</div>

Looks good. I’ll give it a go, thanks

---

<div class="post-metadata">

**Author:** ![JayDickson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaydickson/32/90592_2.png) [@JayDickson](https://discourse.nodered.org/u/JayDickson)\
**Post date:** [8 September 2018 19:43 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/17 "2018-09-08T19:43:33Z")

</div>

Sorry if this is seen as a necropost, but I generally daemonize my instances using PM2, which opens up the option of using an exec node and running the command "pm2 restart node-red". PM2 also does a good job of restarting the runtime on its own if it pukes.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [8 September 2018 23:11 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/18 "2018-09-08T23:11:07Z")

</div>

PM2 is fairly resource heavy and not necessary if you are using systemd or similar on a Linux system. PM2 is good for test and development systems. Or possibly on Windows if not using the scheduler.

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [3 October 2019 10:56 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/19 "2019-10-03T10:56:37Z")

</div>

Hi,

Any idea how to do a node-red restart when you have it running in a Docker/Container ?

FYI - Using the exec node and sending "pwd"; it tells me I'm here - "/usr/src/node-red", however commands like "reboot" or "restart" or "sudo" are not found

---

<div class="post-metadata">

**Author:** ![MattL0](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mattl0/32/16056_2.png) [@MattL0](https://discourse.nodered.org/u/MattL0)\
**Post date:** [17 December 2020 20:06 UTC](https://discourse.nodered.org/t/node-red-self-restart/432/20 "2020-12-17T20:06:10Z")

</div>

Her I am using sudo systemctl restart nodered.  
With an exec node on my first flow.

But it would be nice to have an option in the web server easy accessible . Like near the node red log on the left .  
With a phone I think it would be the best place to put it .

[Next page](https://discourse.nodered.org/t/node-red-self-restart/432.md?page=2)
