exec node fails to run a command variant

819 views
Skip to first unread message

Waqas Aslam

unread,
Jul 18, 2017, 8:55:34 AM7/18/17
to Node-RED
Hi
I'm using exec node to check the status of services running on my Ubuntu machine.


For example, when a qbittorrent service is up and running and I execute the following command through exec node:

sudo systemctl is-active qbittorrent

I get the following output in debug - which is totally fine:

and its corresponding syslog:

Jul 18 14:31:07 home-server node-red[21890]: 18 Jul 14:31:07 - [info] [exec:Service Status] sudo systemctl is-active qbittorrent
Jul 18 14:31:07 home-server sudo[23897]:    yolo : TTY=unknown ; PWD=/home/yolo ; USER=root ; COMMAND=/bin/systemctl is-active qbittorrent
Jul 18 14:31:07 home-server sudo[23897]: pam_unix(sudo:session): session opened for user root by (uid=0)
Jul 18 14:31:07 home-server sudo[23897]: pam_unix(sudo:session): session closed for user root

However, when I manually stop the service from terminal and run the exact same flow then I get the following output:

with syslog:

Jul 18 14:35:30 home-server node-red[21890]: 18 Jul 14:35:30 - [info] [exec:Service Status] sudo systemctl is-active qbittorrent
Jul 18 14:35:30 home-server sudo[24320]:    yolo : TTY=unknown ; PWD=/home/yolo ; USER=root ; COMMAND=/bin/systemctl is-active qbittorrent
Jul 18 14:35:30 home-server sudo[24320]: pam_unix(sudo:session): session opened for user root by (uid=0)
Jul 18 14:35:30 home-server node-red[21890]: 18 Jul 14:35:30 - [info] [exec:Service Status] error:Error: Command failed: sudo systemctl is-active qbittorrent


I don't understand why is it failing to read the service status when it is stopped?
Everything used to work fine when I was running Node v4.2.6.
The problem started to appear when I updated to v8.0.0 in order to use Node-Red v0.17.4 as mentioned here. I even downgraded to Node v6.11.0 but no luck.

Node-red startup syslog:
Jul 18 14:44:18 home-server node-red[25198]: 18 Jul 14:44:18 - [info] Node-RED version: v0.17.4
Jul 18 14:44:18 home-server node-red[25198]: 18 Jul 14:44:18 - [info] Node.js  version: v8.0.0
Jul 18 14:44:18 home-server node-red[25198]: 18 Jul 14:44:18 - [info] Linux 4.4.0-71-generic ia32 LE
Jul 18 14:44:19 home-server node-red[25198]: 18 Jul 14:44:19 - [info] Loading palette nodes
Jul 18 14:44:22 home-server node-red[25198]: 18 Jul 14:44:22 - [info] Dashboard version 2.4.2 started at /ui

FYI, I have added NOPASSWD rights to systemctl command in sudoers.
Also, when I run the command in terminal, they work just fine in both start/stop cases.

Regards

Colin Law

unread,
Jul 18, 2017, 10:04:10 AM7/18/17
to node...@googlegroups.com
The exit code from is-active is 1 if the service is not active, which is an error. That is provided in order to make scripting easy, as one can just test the exit code rather than having to look at what is sent to stdout.  You can use the exit code output from the exec node to decide what to do.

Colin

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/476eb978-6fa2-4b91-818b-ac94486fdb95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Waqas Aslam

unread,
Jul 18, 2017, 10:10:51 AM7/18/17
to Node-RED
But the code i get is 3. Never received 1.
Also, it used to work fine in Node v4.2.6, so why changed now?

To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

Colin Law

unread,
Jul 18, 2017, 10:21:44 AM7/18/17
to node...@googlegroups.com
The images you posted are not working (for me at least). What do you see on the three outputs for the running and stopped conditions? Also post the flow for the exec node please.

Colin

To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Waqas Aslam

unread,
Jul 18, 2017, 10:26:20 AM7/18/17
to Node-RED
The images should be visible now.

Colin Law

unread,
Jul 18, 2017, 10:42:02 AM7/18/17
to node...@googlegroups.com
In fact I was wrong, if you run, in a terminal
systemctl is-active servicename; echo $?
you will see that is-active returns 3 when service is inactive.  So node-red is running exactly as expected. Why it has changed for you I don't know.  I am running node 4.8.4 and see the same in the debug windows as you are.  Are you sure you have not changed anything else in your flow? Perhaps you were running the exec node in exec rather than spawn mode.

By the way you don't need to use sudo with is-active

Colin

To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Waqas Aslam

unread,
Jul 18, 2017, 10:45:53 AM7/18/17
to Node-RED
Yes, I am running it in exec mode - not spawn.

Waqas Aslam

unread,
Jul 18, 2017, 10:49:47 AM7/18/17
to Node-RED
Also, how would I know what return codes should I expect?
Is there a list? as I couldn't find such info in "info" tab or internet for the node.

Waqas Aslam

unread,
Jul 18, 2017, 11:04:42 AM7/18/17
to Node-RED
If the behavior is as expected then why is node-red returning the message "Command failed: sudo systemctl is-active qbittorrent" in debug.

Colin Law

unread,
Jul 18, 2017, 11:36:17 AM7/18/17
to node...@googlegroups.com
The return code is not from node-red it is from systemctl. Look at the docs for systemctl, it should be there. The command (systemctl) *has* failed as far as node red is concerned because the return code is not 0. If you run in spawn mode then the return code is in the payload of o/p three. Or you can use the text of o/p 1 to tell you what is happening.

Colin

To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Julian Knight

unread,
Jul 18, 2017, 12:36:25 PM7/18/17
to Node-RED
I think the behaviour changed slightly with NR v0.17, it cropped up in another thread (or on Slack, I forget).

It is always assumed that a successful command returns zero. That is standard behaviour on all platforms. 

Dave C-J

unread,
Jul 18, 2017, 5:09:15 PM7/18/17
to node...@googlegroups.com
Yes there was a slight change in behaviour for the exec node in 0.17 - existing flows should continue to work - but new nodes will use the new output style - which as has been pointed out includes the error codes etc...
However there is a checkbox that can be used to revert to the old behaviour
Inline images 1

Waqas Aslam

unread,
Jul 19, 2017, 3:29:10 AM7/19/17
to Node-RED
Hi
Seems like there's no effect even when I'm enabling "Use old style output" since it still returns 3 as error code in std:error rather than digesting/ignoring it.

Dave C-J

unread,
Jul 19, 2017, 4:56:21 AM7/19/17
to node...@googlegroups.com
the error code is still correct - 3 - so is still an error state that is returned on the return code output (3rd output). Not sure what the real problem is here - as you can just use the first output (stdout) and detect active or inactive ?  First output is from the top pin (stdout), bottom is from the rc.
Inline images 1

Waqas Aslam

unread,
Jul 20, 2017, 4:12:23 AM7/20/17
to Node-RED
Hi Dave,
Before updating to newer version, I never used to receive any error code for this command and this is what I was expecting when enabling "Use old style output". 
Anyhow, for the moment I have resolved this by marking the execution as SPAWN - though it's better suited for EXEC. Now I don't get an entry in syslog mentioning that the command execution was failed.
Reply all
Reply to author
Forward
0 new messages