Deploy on Startup

1,401 views
Skip to first unread message

Adam S

unread,
Apr 27, 2016, 1:26:31 PM4/27/16
to Node-RED
I created a setup script that installs and creates all the files I need for my project.  One of these files is /home/pi/.node-red/flows_raspberrypi.json the default flow.  My problem is that while it will load the flow in the admin UI, it is not "deployed" and so nothing works until I modify it and deploy it.  Is there a way to manually deploy via command line, or a 1 time deploy on startup option?

Dave C-J

unread,
Apr 27, 2016, 1:58:07 PM4/27/16
to node...@googlegroups.com

Not sure I quite understand. node-red-start should load the flow file and run it automatically. It should already be running by the time you can load the ui in the browser. The console window should report which flow file is loaded/running.

Adam S

unread,
Apr 27, 2016, 2:16:50 PM4/27/16
to Node-RED
Here are the steps to recreate:

make /home/pi/.node-red/flows_raspberrypi.json with any flow that has an inject node before node-red is installed
install node-red
set to start on boot
reboot

I see that all my nodes are present and can view them, but clicking on the inject node gives me an error "node not deployed" even though the Deploy button is greyed out.  Additionally, the pages for the HTTP nodes simply say "Cannot GET /page"

Console output:
pi@raspberrypi:~ $ node-red -v


Welcome to Node-RED
===================

27 Apr 18:16:09 - [info] Node-RED version: v0.13.4
27 Apr 18:16:09 - [info] Node.js  version: v0.10.29
27 Apr 18:16:09 - [info] Linux 4.1.19-v7+ arm LE
27 Apr 18:16:09 - [info] Loading palette nodes
27 Apr 18:16:18 - [warn] ------------------------------------------
27 Apr 18:16:18 - [warn] [sensehat] Error: Can't find Sense HAT python libraries. Run sudo apt-get install sense-hat
27 Apr 18:16:18 - [warn] ------------------------------------------
27 Apr 18:16:18 - [info] Settings file  : /home/pi/.node-red/settings.js
27 Apr 18:16:18 - [info] User directory : /home/pi/.node-red
27 Apr 18:16:18 - [info] Flows file : /home/pi/.node-red/flows_raspberrypi.json
27 Apr 18:16:18 - [info] Server now running at http://127.0.0.1:1880/
27 Apr 18:16:18 - [info] Starting flows
27 Apr 18:16:18 - [info] Started flows

Toshi Bass

unread,
Apr 27, 2016, 2:43:13 PM4/27/16
to Node-RED
Dont know if this would help,                        https://groups.google.com/d/msg/node-red/-vN5tU7DWKg/pV5UzopgAQAJ

msg.headers = {
    "Node-RED-Deployment-Type":"reload"
};
return msg;


Adam S

unread,
Apr 27, 2016, 3:00:06 PM4/27/16
to Node-RED
Hello again Toshi, log time no talk!  Unfortunately this is on a fresh new install, so there are no flows running anywhere that I could send the data.  I guess I could script something up in bash with curl to see if I can get it running.  That will have to wait for tomorrow since my install script takes about 30 minutes to run.
Message has been deleted

Adam S

unread,
Apr 28, 2016, 12:30:05 PM4/28/16
to Node-RED
I sent a POST to /flows using "curl --data "Node-RED-Deployment-Type=reload" http://localhost:1880/flows" and got the following message back "{"error":"unexpected_error","message":"TypeError: Object #<Object> has no method 'forEach'"}" 

Toshi Bass

unread,
Apr 28, 2016, 1:18:57 PM4/28/16
to Node-RED
I got that exact same message when node-red was v0.12.2 see  https://groups.google.com/d/msg/node-red/-vN5tU7DWKg/_DJxxkmvAQAJ  however since v0.13.3 it is working fine for me, did you not upgrade recently ?  


Nicholas O'Leary

unread,
Apr 28, 2016, 1:22:32 PM4/28/16
to Node-RED

But just to reiterate, this should be entirely unnecessary - if you can see the flows in the editor when it loads, then they should be running already.

Can you paste the startup log?


On Thu, 28 Apr 2016, 18:18 Toshi Bass, <toshib...@gmail.com> wrote:
I got that exact same message when node-red was v0.12.2 see  https://groups.google.com/d/msg/node-red/-vN5tU7DWKg/_DJxxkmvAQAJ  however since v0.13.3 it is working fine for me, did you not upgrade recently ?  


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
For more options, visit https://groups.google.com/d/optout.

Adam S

unread,
Apr 28, 2016, 1:24:04 PM4/28/16
to Node-RED
I'm actually on 13.4, so maybe it is broken again?  Can you try that curl command on your install and let me know if that works?  I might just have some syntax wrong.  I tried all kinds of syntax:


curl --data "Node-RED-Deployment-Type=reload" http://localhost:1880/flows
curl --data '{"Node-RED-Deployment-Type":"reload"}' http://localhost:1880/flows
curl --data '"Node-RED-Deployment-Type":"reload"' http://localhost:1880/flows
curl --data "Node-RED-Deployment-Type:reload" http://localhost:1880/flows

Nicholas O'Leary

unread,
Apr 28, 2016, 1:27:58 PM4/28/16
to Node-RED

You need to set the content-type HTTP header to application/json


--

Adam S

unread,
Apr 28, 2016, 1:29:55 PM4/28/16
to Node-RED
I think I posted the startup log above, unless you want something else?

Adam S

unread,
Apr 28, 2016, 1:38:33 PM4/28/16
to Node-RED
I added the content type header, and while it looks like I'm closer, still can't get it to work.  Can you give an example?  This is what I have tried so far:

pi@raspberrypi:~ $ curl -H "Content-Type: application/json" --data '{"Node-RED-Deployment-Type":"reload"}' http://localhost:1880/flows

{"error":"unexpected_error","message":"TypeError: Object #<Object> has no method 'forEach'"}
pi@raspberrypi:~ $ curl -H "Content-Type: application/json" --data {"Node-RED-Deployment-Type":"reload"} http://localhost:1880/flows
SyntaxError: Unexpected token N<br> &nbsp; &nbsp;at Object.parse (native)<br> &nbsp; &nbsp;at parse (/usr/lib/node_modules/node-red/node_modules/body-parser/lib/types/json.js:88:17)<br> &nbsp; &nbsp;at /usr/lib/node_modules/node-red/node_modules/body-parser/lib/read.js:116:18<br> &nbsp; &nbsp;at invokeCallback (/usr/lib/node_modules/node-red/node_modules/raw-body/index.js:262:16)<br> &nbsp; &nbsp;at done (/usr/lib/node_modules/node-red/node_modules/raw-body/index.js:251:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (/usr/lib/node_modules/node-red/node_modules/raw-body/index.js:308:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (events.js:92:17)<br> &nbsp; &nbsp;at _stream_readable.js:929:16<br> &nbsp; &nbsp;at process._tickCallback (node.js:419:13)
pi@raspberrypi:~ $ curl -H "Content-Type: application/json" --data "Node-RED-Deployment-Type":"reload" http://localhost:1880/flows
SyntaxError: Unexpected token N<br> &nbsp; &nbsp;at parse (/usr/lib/node_modules/node-red/node_modules/body-parser/lib/types/json.js:83:15)<br> &nbsp; &nbsp;at /usr/lib/node_modules/node-red/node_modules/body-parser/lib/read.js:116:18<br> &nbsp; &nbsp;at invokeCallback (/usr/lib/node_modules/node-red/node_modules/raw-body/index.js:262:16)<br> &nbsp; &nbsp;at done (/usr/lib/node_modules/node-red/node_modules/raw-body/index.js:251:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (/usr/lib/node_modules/node-red/node_modules/raw-body/index.js:308:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (events.js:92:17)<br> &nbsp; &nbsp;at _stream_readable.js:929:16<br> &nbsp; &nbsp;at process._tickCallback (node.js:419:13)
pi@raspberrypi:~ $ curl -H "Content-Type: application/json" --data "Node-RED-Deployment-Type:reload" http://localhost:1880/flows
SyntaxError: Unexpected token N<br> &nbsp; &nbsp;at parse (/usr/lib/node_modules/node-red/node_modules/body-parser/lib/types/json.js:83:15)<br> &nbsp; &nbsp;at /usr/lib/node_modules/node-red/node_modules/body-parser/lib/read.js:116:18<br> &nbsp; &nbsp;at invokeCallback (/usr/lib/node_modules/node-red/node_modules/raw-body/index.js:262:16)<br> &nbsp; &nbsp;at done (/usr/lib/node_modules/node-red/node_modules/raw-body/index.js:251:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (/usr/lib/node_modules/node-red/node_modules/raw-body/index.js:308:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (events.js:92:17)<br> &nbsp; &nbsp;at _stream_readable.js:929:16<br> &nbsp; &nbsp;at process._tickCallback (node.js:419:13)
pi@raspberrypi:~ $ curl -H "Content-Type: application/json" --data "Node-RED-Deployment-Type=reload" http://localhost:1880/flows
SyntaxError: Unexpected token N<br> &nbsp; &nbsp;at parse (/usr/lib/node_modules/node-red/node_modules/body-parser/lib/types/json.js:83:15)<br> &nbsp; &nbsp;at /usr/lib/node_modules/node-red/node_modules/body-parser/lib/read.js:116:18<br> &nbsp; &nbsp;at invokeCallback (/usr/lib/node_modules/node-red/node_modules/raw-body/index.js:262:16)<br> &nbsp; &nbsp;at done (/usr/lib/node_modules/node-red/node_modules/raw-body/index.js:251:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (/usr/lib/node_modules/node-red/node_modules/raw-body/index.js:308:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (events.js:92:17)<br> &nbsp; &nbsp;at _stream_readable.js:929:16<br> &nbsp; &nbsp;at process._tickCallback (node.js:419:13)

nzfarmer

unread,
May 2, 2016, 2:05:55 AM5/2/16
to Node-RED
I have a similar use case.

Am using the RED.nodes API to replace the global flow and add a new flow to the default first Flow tab. (flowAdd()  creates a new tab which is not what we want).  

updateFlow('global',[<Flows>]) works nicely, but I have to manually refresh the browser to see the new flow that I've added (even if the server has been stopped/started).

Is there a way to get the client to trigger a reload from the runtime API? (or another way? - i.e. include some code that sits in the client space and can be defined in settings.js?)

thanks 

Adam S

unread,
May 2, 2016, 7:40:25 AM5/2/16
to Node-RED
After a weekend and a second glance at the documentation I found my error.  The deployment type is actually a header, not the data as I thought before.  This command works:

curl -v -H "Content-Type: application/json; charset=UTF-8" -H "Node-RED-Deployment-Type: reload" -X POST http://localhost:1880/flows

I'll re-run my script with that at the end to see if it deploys the nodes so they are usable.

nzfarmer

unread,
May 2, 2016, 8:47:52 AM5/2/16
to Node-RED
Well done!  Unfortunately it doesn't help my use case.

On the server side I can call

            RED.nodes.updateFlow('global',flow)

And this adds the flow to the current config and raises an updated event (3 May 00:44:18 - [info] Updated flow: global [global])

But for some reason the browser isn't instructed to refresh the contents of the editor and I'm not quite sure how to trigger that.

Have tried RED.comms.publish("/")  but no joy.

Nicholas O'Leary

unread,
May 2, 2016, 9:19:09 AM5/2/16
to Node-RED Mailing List
The 'global' flow should only contain global config nodes and subflow templates. If you want to update an existing flow (ie tab) you would call updateFlow with its id instead of global.

If you want to replace the entire set of flows running - as if you'd hit the deploy button, you should use RED.nodes.setFlows().

There is no mechanism in place to cause the editor to refresh its flows from the runtime, but we have an item on the whiteboard to address it - https://trello.com/c/BaeznpAz

Nick

nzfarmer

unread,
May 2, 2016, 9:32:48 AM5/2/16
to Node-RED
Thanks Nick

Awesome response.  At least I know what not to chase! 

So for updateFlow I will just use the id of the tab and that should insert the required flow. It appears to work as an addFlow - cloning the activeConfig rather than replacing it.

Nicholas O'Leary

unread,
May 2, 2016, 9:39:42 AM5/2/16
to Node-RED Mailing List
The expected behaviour is:

addFlow will add the new flow (ie tab) to the active configuration. The call will return (via a promise) the generated id of the new flow.

updateFlow can be used to update an existing flow.

Is that not what you see?

Nick

--

Adam S

unread,
May 2, 2016, 11:11:19 AM5/2/16
to Node-RED
Running "curl -v -H "Content-Type: application/json; charset=UTF-8" -H "Node-RED-Deployment-Type: reload" -X POST http://localhost:1880/flows" is not enough to get everything running.  I tried some of the other deployment types but they all error out.  Moving a node on the admin UI and deploying changes still gets everything going.

pi@raspberrypi:~ $ curl -v -H "Content-Type: application/json; charset=UTF-8" -H "Node-RED-Deployment-Type: reload" -X POST http://localhost:1880/flows
* Hostname was NOT found in DNS cache
*   Trying ::1...
* connect to ::1 port 1880 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 1880 (#0)
> POST /flows HTTP/1.1
> User-Agent: curl/7.38.0
> Host: localhost:1880
> Accept: */*
> Content-Type: application/json; charset=UTF-8
> Node-RED-Deployment-Type: reload
>
< HTTP/1.1 204 No Content
< X-Powered-By: Express
< Date: Mon, 02 May 2016 15:04:02 GMT
< Connection: keep-alive
<
* Connection #0 to host localhost left intact
pi@raspberrypi:~ $ curl -v -H "Content-Type: application/json; charset=UTF-8" -H "Node-RED-Deployment-Type: full" -X POST http://localhost:1880/flows
* Hostname was NOT found in DNS cache
*   Trying ::1...
* connect to ::1 port 1880 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 1880 (#0)
> POST /flows HTTP/1.1
> User-Agent: curl/7.38.0
> Host: localhost:1880
> Accept: */*
> Content-Type: application/json; charset=UTF-8
> Node-RED-Deployment-Type: full
>
< HTTP/1.1 400 Bad Request
< X-Powered-By: Express
< Content-Type: application/json; charset=utf-8
< Content-Length: 92
< ETag: W/"5c-nQx74NB4O7JWcvGEgroEUQ"
< Date: Mon, 02 May 2016 15:05:10 GMT
< Connection: keep-alive
<
* Connection #0 to host localhost left intact

{"error":"unexpected_error","message":"TypeError: Object #<Object> has no method 'forEach'"}pi@raspberrypi:~ $
pi@raspberrypi:~ $ curl -v -H "Content-Type: application/json; charset=UTF-8" -H "Node-RED-Deployment-Type: flows" -X POST http://localhost:1880/flows
* Hostname was NOT found in DNS cache
*   Trying ::1...
* connect to ::1 port 1880 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 1880 (#0)
> POST /flows HTTP/1.1
> User-Agent: curl/7.38.0
> Host: localhost:1880
> Accept: */*
> Content-Type: application/json; charset=UTF-8
> Node-RED-Deployment-Type: flows
>
< HTTP/1.1 400 Bad Request
< X-Powered-By: Express
< Content-Type: application/json; charset=utf-8
< Content-Length: 92
< ETag: W/"5c-nQx74NB4O7JWcvGEgroEUQ"
< Date: Mon, 02 May 2016 15:05:52 GMT
< Connection: keep-alive
<
* Connection #0 to host localhost left intact

{"error":"unexpected_error","message":"TypeError: Object #<Object> has no method 'forEach'"}pi@raspberrypi:~ $
pi@raspberrypi:~ $ curl -v -H "Content-Type: application/json; charset=UTF-8" -H "Node-RED-Deployment-Type: nodes" -X POST http://localhost:1880/flows
* Hostname was NOT found in DNS cache
*   Trying ::1...
* connect to ::1 port 1880 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 1880 (#0)
> POST /flows HTTP/1.1
> User-Agent: curl/7.38.0
> Host: localhost:1880
> Accept: */*
> Content-Type: application/json; charset=UTF-8
> Node-RED-Deployment-Type: nodes
>
< HTTP/1.1 400 Bad Request
< X-Powered-By: Express
< Content-Type: application/json; charset=utf-8
< Content-Length: 92
< ETag: W/"5c-nQx74NB4O7JWcvGEgroEUQ"
< Date: Mon, 02 May 2016 15:06:11 GMT
< Connection: keep-alive
<
* Connection #0 to host localhost left intact

Adam S

unread,
May 2, 2016, 11:23:47 AM5/2/16
to Node-RED
Forgot to add that I did see in the documentation the body must contain a JSON config.  Is this required?  My impression is that this API should be similar to "service node-red restart", but now I think maybe I should not create the config before node-red is installed and run the full command with my config in the body?

Nicholas O'Leary

unread,
May 2, 2016, 11:30:16 AM5/2/16
to Node-RED

Are you creating the config on startup then? Or is it already in the flow file?

The reload action is there so you don't have to provide the full flow config with the request - it tells the runtime to reload the flow config from storage.

All of the other actions on /flows do require you to provide the full config in the request - which is why you hit errors when you try them without a flow config included. I'll take a look at improving the error reporting in those cases.


--

Adam S

unread,
May 2, 2016, 1:16:29 PM5/2/16
to Node-RED
The flow file (flows_raspberrypi.json) is created before node-red is installed via apt-get.  I noticed that after I click Deploy the permissions for flows_raspberrypi.json change from -rw-r--r--  1 pi root to -rw-r--r--  1 pi pi.  Would the group permissions be causing this problem?

nzfarmer

unread,
May 2, 2016, 3:29:37 PM5/2/16
to Node-RED
The expected behaviour is:

addFlow will add the new flow (ie tab) to the active configuration. The call will return (via a promise) the generated id of the new flow.

updateFlow can be used to update an existing flow.

Is that not what you see?



It only shows the API stubs, no examples and few details. So I've been digging into the code to figure out how to use the calls.  Do you have a git somewhere with some working examples or more detailed docs perhaps?

Loving the API! 

Nicholas O'Leary

unread,
May 2, 2016, 3:34:14 PM5/2/16
to Node-RED Mailing List
Well, you've found where the docs _will_ be.... that's as good as it gets right now. Simply too many things to do and not enough time to do it. But I'm always here/on slack to answer questions you have.

I will try to get some basic docs in place soon.

Nick

--

Dave C-J

unread,
May 2, 2016, 4:52:25 PM5/2/16
to node...@googlegroups.com
Adam,

have re-created the base problem here now... (ie deploy flow before install) - and indeed not running is not how it should behave... so will investigate to see what's up.

Nicholas O'Leary

unread,
May 3, 2016, 5:47:56 AM5/3/16
to Node-RED Mailing List
Adam,

in the flow config you are generating, have you included a 'tab' node whose id matches the z property of the nodes that belong on that tab? I suspect not - and that would explain everything you've seen.

The recreate Dave hit was because his flow just had an inject and debug node - no tab node. If I manually added the tab node and restarted, it worked as expected. Hitting deploy in the editor would cause the flow config to get rewritten to include a tab node - hence why that appears to bring it to life. The reload command wouldn't work as it just reloads the existing config that is missing the tab node.

This is a bug in the runtime and something I will fix in 0.14.0. But the workaround for now is to ensure you include a tab node. If you compare your generated flow with the one written after you hit the deploy button in the editor you'll see what I mean.

Nick




On 2 May 2016 at 21:52, Dave C-J <dce...@gmail.com> wrote:
Adam,

have re-created the base problem here now... (ie deploy flow before install) - and indeed not running is not how it should behave... so will investigate to see what's up.

--

Adam S

unread,
May 3, 2016, 7:40:24 AM5/3/16
to Node-RED
You are correct about the tab node.  What I was doing was select all>settings>export>clipboard which does not include the tab node.  I'll make an exact copy of the working file and run my script again to see if I see the same thing you did.

Adam S

unread,
May 3, 2016, 9:24:23 AM5/3/16
to Node-RED
Confirming that including the tab node starts the flows as expected.
Reply all
Reply to author
Forward
0 new messages