Problem with exec node

Hello
I think I have problem with the exec node.
I don't get the same result when I use the same command in an exec node or in the putty console.
For example, I try to use ngrok. (but I don't use the ngrok node, because that doesn't work at all, but this is an other topic)
my working directory is /opt/plcnext
In this directory, there is my application ngrok, and some dependent directory /.ngrok and /.ngrok2
When I run the command : /opt/plcnext/ngrok http https://localhost:8081 (this is a command to expose my port 8081 in https to the web), the result is correct, and I get a correct answer.
When I use exactly the same command in an exec node, the answer returned by ngrok is different, and unfortunately, it stops my process.
My node :slight_smile:
[{"id":"341023e0.15f71c","type":"exec","z":"97efe9eb.ab5778","command":"/opt/plcnext/ngrok http https://localhost:8081","addpay":false,"append":"","useSpawn":"true","timer":"","oldrc":true,"name":"Envoi commande de publication","x":470,"y":140,"wires":[["bea63b85.69e798"],["bea63b85.69e798"],["bea63b85.69e798"]]}]

My command line :slight_smile:
/opt/plcnext/ngrok http https://localhost:8081

Can it be that both commands are not interpreted in the same way, depending if they are coming from the console or from Node Red?
Please notice that I have installed nodered with 'npm install -g node-red' command. Is this correct?

I also use an othe exec node, to register an url on google actions, and the behavior is different if I send the command from the exec node of node-red or from the console. I don't get the same result.
what can it be?

I use NR 0.20.5, node.js 10.15.3, and my OS is Linux 4.14.63-rt40-pxc arm LE
Thanks for your help

Please post the output from both the commandline and node red, so that we can see the difference.

And yes they can be different as you may use a different shell. Also you are using spawn so it keeps running, correct ?

To install (correctly) use:
bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)
As per documentation.

Hello, and thanks for your reply

I will make a snapshot ASAP to show the different results of the CLI and the Node.

What about the link you sent me?

So I have to use it as it is, or do I have to adapt it?

I made a test with an other nodered install, WICH is running on a Linux PC.

There, with the command top, I have seen that nodered is ran by the admin user. In my PLC where I have a problem, I can see that nodered is ran as Root user.

CAN this be the reason of the differences of behaviour?

If yes, how can I make nodered run as admin instead of root? For information, nodered is started automatically with a script.

Envoyé de mon iPhone

I found a beginning of solution.
I discovered that node-red is autostarted (with my startup script) as root.
And when I tried to use ngrok, an auth mecahnism was necessary.
When I did this in the console, I was as Admin. But even if the auth token was present, it was not taken in account when the command was coming from node-red with the exec node, as root.
so I have changed the way to make the auth, and logged as root in the console, and there it worked.

But my second problem is with an application called gactions. I use it to create and publish my google action.
So, I made some chnages in my file settings, so that the gaction file is now owned by the root, instead of the admin.
But, when i launch the application in the console as root, I get a correct reply :slight_smile:

root@axcf2152:/opt/plcnext/# /opt/plcnext/gactions test -preview_mins 9999999 -action_package /opt/plcnext/action1.json -project  my-test-app-12345
Pushing the app for the Assistant for testing...
Your app for the Assistant for project my-test-app-d13de is now ready for testing on Actions on Google enabled devices or the Actions Web Simulator at https://console.actions.google.com/project/my-test-app-12345/simulator/

This is a correct result

But when I send the same command using the exec node, I get this reply :slight_smile:
11/05/2019 à 23:24:53node: 7b39c83b.d95988msg : Object

object

payload: "Pushing the app for the Assistant for testing...↵"

_msgid: "f67910a9.5eb5a"

11/05/2019 à 23:24:53[node: 7b39c83b.d95988](http://192.168.1.52:1880/#)msg : Object

object

payload: "Gactions needs access to your Google account. Please copy & paste the URL below into a web browser and follow the instructions there. Then copy and paste the authorization code from the browser back here.↵Visit this URL: ↵ https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=111111111111-o6vu1tjkq8oqjub8jilj6v1111111111.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Factions.builder&state=state ↵Enter authorization code: ↵"

_msgid: "f67910a9.5eb5a"

So, we can see here that instead of accepting the connection, Gaction requests a registration token.

why can there be a such behaviour difference, while the user and the command are the same?

Rather than trying to run everything as root, did you try changing your autostart script to run as admin ?

HI

Yes I tried, but in that case, nodered doesn’t start anymore

I have use a croit in WICH it is written user=root, so I modified it to user =admin, but it seems that the script is either not taken in account or not working properly after reboot.

Thé script I used is here:

https://www.plcnext-community.net/index.php?option=com_content&view=article&id=379:how-to-start-node-red-automatically-on-boot-using-init-d&catid=78&Itemid=366&lang=en

Do you see something else to change in the script file so that nodered is started as admin?

Envoyé de mon iPhone

No - only the line user=root . But then again I don't know the plc or how else they may have restricted the admin user - they may not have access to run node-red. But if you can run node-red command from the admin command line then it should be possible to make it work...
Then again the line with the userdir '/opt/plcnext/.node-red' - that must also be read write accessible to admin so it can save the flow files etc.