Why a command launched in the terminal doesn't return the same result when it is launched by node-red?

Hello I have created a detailled post in the node-red forum. <- Clic on the left line My problem is that the same command, launched in the terminal and an exec node don’t behave in the same way. As you will see in the detailled post on the node-red forum, it seems that the involved application ‘gactions’ hasn’t a correct access to a credential file (but this file exists, and has got the correct rights). when looking in details at the responses, we can see that ‘gactions’ seems to not send the same POST. But I think that it is either a problem of rights in node-red, or in the AXC F 2152 wich doesn’t recognize the ‘admin’ user being the same if it is in the terminal or inside node-red. Can the AXC F 2152 reacts differently when a command is passed from different locations? Even if the user is the same?

Hi Michel, Firstly: I am really interested to see that you are using Actions on Google, and I am looking forward to seeing a Makers Blog post once you have this working … a lot of people will be interested in this. To your question - without having looked too deeply at the specifics of node-red and gactions, I think that the answer from afelix (13 in the thread) is correct. Commands from different applications may behave differently if (for example) environment variables are missing or are different in the different application contexts. There is nothing special about the operating system on the AXC F 2152 that would make it behave differently to a standard linux OS in this respect. I may have missed this detail on the node-red forum, but have you tried doing this from node-red on a desktop Linux system like Debian or Ubuntu? If you can investigate and solve the problem there, then it may be easier to solve the problem on the PLC. If you cannot reproduce the problem on a PC, then we would have to figure out why it works there but not on the PLC. I don’t know if this helps … perhaps someone else on the Forum has used Actions on Google with node-red and has some more information. Martin.

Hello Martin As requested, I made a test at home with my PC running ubuntu. node-red is started with pm2 I use the same versions as on the AXC F 2152. 1 Jul 22:19:40 - [info] Node-RED version: v0.20.5

1 Jul 22:19:40 - [info] Node.js version: v10.15.3

And there, I can see that the creds.data file is correctly created when the gaction is started from an exec node in node-red Only one difference : my account is not admin, but mike : this is the one I created on my home PC : -rwxrwxr-x 1 mike mike 5716640 mai 1 18:36 gactions Node-red is ran as mike : 1127 mike 20 0 1260724 147092 29592 S 9,6 5,2 0:14.31 node-red Node red is located here : /usr/local/bin/node-red So, with this test, it seems that there is really a difference in the system itself. The AXC F 2152 doesn’t react like it should react using node-red or gActions.

Hi Michel, I understand from the node-red forum that this now works in node-red on the PLC, but only if you launch node-red from a command line, not if you launch it from a script in init.d. Is that correct? I still think Lena (afelix) is on the right track. Can you post the contents of your init.d script? I would like to see if it is possible to start node-red as admin user from this script, like you do when starting node-red from the command line.

Here is my init.d file. It is the one taken in the PlcNext community. I only changed the user and the logs directory.

start_nodered.pdf

Thanks Michel. After the problem happens in node-red, do you see any useful information in the log file (/opt/plcnext/node-red.log) ? I understand that you do not see the same problem when starting node-red as admin from the command line. Do you see the same problem if you start node-red as admin from the command line with some or all of the options in the script, in particular the option --userDir='/opt/plcnext/.node-red' ?

Hi Michel, I got this to work by putting the creds.data file in the root directory of the PLC, i.e. “/” Alternatively, you can add the -d (or --chdir) option to the start-stop-daemon command in your /etc/init.d/start_nodered file, so that it starts node-red from the directory that already has your creds.data file. From the man page for start-stop-daemon:

**-d** , **--chdir** _path_
              Chdir to _path_ before starting the process. This is done after
              the chroot if the **-r** |**--chroot** option is set. When not
              specified, **start-stop-daemon** will chdir to the root directory
              before starting the process.

This explains why putting the creds.data file into the root directory works. Martin.