# Deploy from command line

**URL:** https://discourse.nodered.org/t/deploy-from-command-line/15531
**Category:** General
**Created:** [14 September 2019 15:42 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531 "2019-09-14T15:42:19Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![RogierQ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogierq/32/3211_2.png) [@RogierQ](https://discourse.nodered.org/u/RogierQ)
#### Post date: [14 September 2019 15:42 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/1 "2019-09-14T15:42:19Z")

</div>

Hi!

After a longer period the inputs from my pi stop reacting.  
Then i move a node and click deploy all and problem solved.  
Now thinking about a cron job to deploy every night to prevent problems.  
Is it possible to send a deploy all command from command line?  
Or is there another way to do this?

Thanks  
Rogier

---

<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: [14 September 2019 17:13 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/2 "2019-09-14T17:13:56Z")

</div>

well a cron job to run `node-red-restart` or `node-red-stop && node-red-start` would do the job

---

<div class="post-metadata">

### Author: ![RogierQ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogierq/32/3211_2.png) [@RogierQ](https://discourse.nodered.org/u/RogierQ)
#### Post date: [14 September 2019 18:10 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/3 "2019-09-14T18:10:42Z")

</div>

sounds perfect, but would love to control it from mqtt if possible.  
i have around 60 pi's to control

---

<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: [14 September 2019 18:24 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/4 "2019-09-14T18:24:42Z")

</div>

> [@RogierQ](#):
>
> Now thinking about a cron job to deploy every night to prevent problems

Not sure how to troubleshoot your problem, but wouldn't it be better to fix the issue instead of giving it first aid?

> [@dceejay](#):
>
> a cron job to run `node-red-restart` or `node-red-stop && node-red-start`....

...could always order a reboot from within node-RED itself.

> [@Restart node-RED via dashboard](https://discourse.nodered.org/t/restart-node-red-via-dashboard/15330):
>
> Just tried running node-red-restart through an exec node, and it works well. It shuts down and restarts gracefully according to NR log. (Raspberry Pi installed via official install script) Useful to use remotely or to restart NR after updating nodes, without resorting to cmd prompt. [restart] [{"id":"8497fd50.d66e1","type":"exec","z":"4487e413.bb781c","command":"sudo ","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"System Command","x":720,"y":370,"wires":[[],[],…

If you wanted to order a reboot via MQTT, just replace the inject node with a MQTT in node, and possibly a Switch node to watch for the keyword for a reboot.

![reboot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/46c870abe88a2bc5913a28f3c3b955e1acfb7ba6.jpeg)

---

<div class="post-metadata">

### Author: ![RogierQ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogierq/32/3211_2.png) [@RogierQ](https://discourse.nodered.org/u/RogierQ)
#### Post date: [14 September 2019 20:22 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/5 "2019-09-14T20:22:38Z")

</div>

totally agree to solve the problem. But cannot find a problem.  
just a simple pi input that stops working

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [14 September 2019 20:34 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/6 "2019-09-14T20:34:27Z")

</div>

what type of input?  
My Node-RED Pi lasted 2 years before I had to reboot it due to a house move

---

<div class="post-metadata">

### Author: ![RogierQ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogierq/32/3211_2.png) [@RogierQ](https://discourse.nodered.org/u/RogierQ)
#### Post date: [14 September 2019 20:35 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/7 "2019-09-14T20:35:50Z")

</div>

a raspberry pi input with a switch button, is first time since 6 months

---

<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: [15 September 2019 06:47 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/8 "2019-09-15T06:47:18Z")

</div>

Do you mean a gpio digital input with a mechanical switch connected to it? If so connect a debug node to the input and next time it fails see if anything is shown in the debug.

---

<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: [15 September 2019 11:47 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/9 "2019-09-15T11:47:55Z")

</div>

> [@RogierQ](#):
>
> sounds perfect, but would love to control it from mqtt if possible.  
> i have around 60 pi's to control

Write the MQTT msg with a retain flag. Then, in your cron job, use a small Python or node.js (depending on your preference) script to listen for the topic, reset it and then restart the device.

In addition, I've shared before my own flow for restarting Node-RED and it is really easy on a Pi or other Linux device where you are using systemd to run Node-RED. The only thing you need to do is to ensure that the user id running Node-RED is able to do SUDO on the systemctrl command without requiring a password prompt (use visudo to make the change).

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/67d3f7910952559e6d65b694488f769f4993bb93.png)

You could also amend that to do a full system reboot as well if needed.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8195cae5a3f99db12a99b23d6a570423883c870b.png)

Of course, as Paul says, much better to fix the issue - but sometimes that isn't possible.

---

<div class="post-metadata">

### Author: ![kakyoism](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kakyoism/32/46283_2.png) [@kakyoism](https://discourse.nodered.org/u/kakyoism)
#### Post date: [28 September 2021 03:01 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/10 "2021-09-28T03:01:04Z")

</div>

I'm curious what these commands are: `node-red-restart / -stop`. I couldn't find them among the node-red commandline, nor could I find relevant custom nodes in the palette.

Could you kindly point me in the right direction, please?  
Thanks in advance!

---

<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 September 2021 06:10 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/11 "2021-09-28T06:10:07Z")

</div>

node-red-restart, oddly enough, stops the node red service and starts it again, node-red-stop stops it, and node-red-start starts it (and shows the startup log in the terminal).

Note that it is node-red-restart and not  
node-red -restart  
Similarly for the other commands. They are commands run in a terminal, not nodes.

---

<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: [28 September 2021 06:16 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/12 "2021-09-28T06:16:45Z")

</div>

Those commands are provided by our Linux install script and are described here: [Running on Raspberry Pi : Node-RED](https://nodered.org/docs/getting-started/raspberrypi)

---

<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 September 2021 06:26 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/13 "2021-09-28T06:26:33Z")

</div>

> [@knolleary](#):
>
> Those commands are provided by our Linux install

I tend to forget that some users run node-red on Windows.

---

<div class="post-metadata">

### Author: ![kakyoism](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kakyoism/32/46283_2.png) [@kakyoism](https://discourse.nodered.org/u/kakyoism)
#### Post date: [28 September 2021 11:01 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/14 "2021-09-28T11:01:35Z")

</div>

Ok, that makes sense. Thanks.  
I was mainly on macOS by the way.

---

<div class="post-metadata">

### Author: ![kakyoism](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kakyoism/32/46283_2.png) [@kakyoism](https://discourse.nodered.org/u/kakyoism)
#### Post date: [28 September 2021 11:02 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/15 "2021-09-28T11:02:18Z")

</div>

Yeah, thanks Colin. I figured that out for sure.

---

<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 September 2021 11:43 UTC](https://discourse.nodered.org/t/deploy-from-command-line/15531/16 "2021-09-28T11:43:05Z")

</div>

Start/Stop and restart depend on how you have got Node-RED set up.

But because Node-RED is a node.js app, you can use the package.json file to create suitable scripts that you can then run as `npm start` and `npm restart`. On my Windows installs, those scripts control PM2 and on my live install on Debian Linux, they use `systemctl` as I use systemd there (as you would on a Pi as well which is a form of Debian). Though I have a Mac, I haven't used Node-RED on it so I don't know how you would normally start/stop but since it isn't as likely to be a permanent server but more like a desktop/laptop, you might consider using PM2 as I do on my Windows desktop.
