# Exec node - help with how it spawns

**URL:** <https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957>\
**Category:** General\
**Created:** [12 March 2025 23:12 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957 "2025-03-12T23:12:30Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![StrongTown](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@StrongTown](https://discourse.nodered.org/u/StrongTown)\
**Post date:** [12 March 2025 23:12 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/1 "2025-03-12T23:12:30Z")

</div>

I've searched and read other msgs on this however none really helped.

My rpi3 died and took the SD card with it (sigh). So I took the opportunity to create a completely new system install (everything) on my rpi4 with 64bit Debian Bookwork (boot image from Raspberry Pi Imager). Fresh install of NR using the `'curl`' command. My project appears to be running fine again (yes I back up key files frequently).

> Side note: _All the GPIO's are working properly now, no yellow 'OK' indications however HTOP still showing python nrgpio.py processes using between 2 and 4+ % cpu each, they fluctuate rapidly._

The exec node challenge I have is with a seemingly simple command (other msgs were with more complicated scenarios with apps I don't use). It has to do with the alsa sound system.

When I SSH (remote) and enter [:~ $] "amixer set Master 65%" all is good and I get:

> Simple mixer control 'Master',0  
> Capabilities: pvolume pswitch pswitch-joined  
> Playback channels: Front Left - Front Right  
> Limits: Playback 0 - 65536  
> Mono:  
> Front Left: Playback 42598 [65%] [on]  
> Front Right: Playback 42598 [65%] [on]

Using a local terminal via XRDP works just as perfectly also however when I send the exact same command through an exec node I get:

> Command failed: amixer set Master 65%  
> amixer: Unable to find simple control 'Master',0

What is different about the (core) exec node that it can't complete this (seemingly) simple request? TIA

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 March 2025 09:36 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/2 "2025-03-13T09:36:07Z")

</div>

Can you put together a small flow inject-\>exec-\>debug (set to display the complete msg object) and run the flow.

Then copy the oputut and paste it to a reply and export the flow and paste it to a reply,

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [13 March 2025 09:45 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/3 "2025-03-13T09:45:01Z")

</div>

I have not read your full post but did see you were having issues with issuing amixer commands from an exec node.

I faced a similar issue and after much digging found that adding the below Env Var to the environment before launching Node-RED solved it.

```bash
XDG_RUNTIME_DIR=/run/user/$(id -u) node-red

```

If you run Node-RED as a service, then you will need to identify the user (often this is `pi`) and explicitly set the value e.g.

```bash
# get the uid of user pi
id -u pi
# outputs 1000

```

modify the service

```bash
sudo systemctl edit node-red.service

```

Then add:

```bash
[Service]
Environment=XDG_RUNTIME_DIR=/run/user/1000

```

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [13 March 2025 09:45 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/4 "2025-03-13T09:45:21Z")

</div>

There are many issues playing sounds from the exec node for various reasons.

I suggest doing a bit of a search on the forum with different keywords and see if any of the solutions sort your problem

---

<div class="post-metadata">

**Author:** ![StrongTown](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@StrongTown](https://discourse.nodered.org/u/StrongTown)\
**Post date:** [13 March 2025 11:42 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/5 "2025-03-13T11:42:35Z")

</div>

![](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/24/2773_2.png)[cymplecy](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/4) ... Just so you know, I've searched the forum, the internet and tried dozens of different things before I even considered posting here. After hours of trying to fix what seems like a simple thing one gives up.

This issue is important for me because controlling volume controls how loud the synthesized voice is throughout the house. Speaking messages is one of the primary output (and purpose) of my NR system.

---

<div class="post-metadata">

**Author:** ![StrongTown](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@StrongTown](https://discourse.nodered.org/u/StrongTown)\
**Post date:** [13 March 2025 12:03 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/6 "2025-03-13T12:03:09Z")

</div>

![amixer error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c8484a4c25572a800666f9d80837187e18a05bd.gif)

```auto
[
    {
        "id": "5d37a6637afed554",
        "type": "inject",
        "z": "37226bbddff3ddf4",
        "name": "Vol 65",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "65",
        "payloadType": "num",
        "x": 830,
        "y": 320,
        "wires": [
            [
                "bc8940c463e86bcb"
            ]
        ]
    },
    {
        "id": "5506f86556f4fc3d",
        "type": "inject",
        "z": "37226bbddff3ddf4",
        "name": "Vol 87",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "87",
        "payloadType": "num",
        "x": 830,
        "y": 400,
        "wires": [
            [
                "bc8940c463e86bcb"
            ]
        ]
    },
    {
        "id": "bc8940c463e86bcb",
        "type": "function",
        "z": "37226bbddff3ddf4",
        "name": "Set Volume",
        "func": "var volumeLvl = {payload: \"amixer set Master \" + msg.payload + \"%\" };\nreturn volumeLvl;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 970,
        "y": 360,
        "wires": [
            [
                "1d391b7178d86e58",
                "ce50027a90e312b9"
            ]
        ]
    },
    {
        "id": "1d391b7178d86e58",
        "type": "exec",
        "z": "37226bbddff3ddf4",
        "command": "",
        "addpay": "payload",
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 1110,
        "y": 300,
        "wires": [
            [],
            [],
            [
                "447540c35ed16284"
            ]
        ]
    },
    {
        "id": "ce50027a90e312b9",
        "type": "debug",
        "z": "37226bbddff3ddf4",
        "name": "Cmnd",
        "active": true,
        "tosidebar": false,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1050,
        "y": 420,
        "wires": []
    },
    {
        "id": "447540c35ed16284",
        "type": "debug",
        "z": "37226bbddff3ddf4",
        "name": "Err",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1170,
        "y": 380,
        "wires": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![StrongTown](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@StrongTown](https://discourse.nodered.org/u/StrongTown)\
**Post date:** [13 March 2025 12:06 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/7 "2025-03-13T12:06:02Z")

</div>

Thanks ![](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/24/4826_2.png)[Steve-Mcl](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/3) however I've not messed with NR environment before. Where exactly do I put these?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [13 March 2025 13:14 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/8 "2025-03-13T13:14:43Z")

</div>

How do you start Node-RED and what account runs Node-RED?

---

<div class="post-metadata">

**Author:** ![StrongTown](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@StrongTown](https://discourse.nodered.org/u/StrongTown)\
**Post date:** [13 March 2025 13:55 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/9 "2025-03-13T13:55:24Z")

</div>

EDIT: I just boot and it runs however manually I use `node-red-start` and 'pi' is the user.

> pi@Homecontroller:~ $ who  
> pi tty1 2025-03-12 12:57  
> pi tty7 2025-03-12 12:57 (:0)  
> pi pts/0 2025-03-12 18:51 (192.168.2.85)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [13 March 2025 14:39 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/10 "2025-03-13T14:39:59Z")

</div>

ok, so you installed using the node-red installer script.

Try this...

1. open a terminal
2. run `node-red-stop` (to stop node-red)
3. enter `export XDG_RUNTIME_DIR=/run/user/$(id -u)`
4. enter `node-red`
5. test your exec nodes

If this works, edit your service file as described in my previous post & restart the pi

---

<div class="post-metadata">

**Author:** ![StrongTown](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@StrongTown](https://discourse.nodered.org/u/StrongTown)\
**Post date:** [13 March 2025 15:14 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/11 "2025-03-13T15:14:36Z")

</div>

![](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/24/4826_2.png)[Steve-Mcl](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/10) I did as you suggest and after the 5 steps above it worked perfectly.

I then stopped NR and edited the service file as follows and rebooted:

```auto
### Editing /etc/systemd/system/node-red.service.d/override.conf
### Anything between here and the comment below will become the new contents of the file

[Service]
Environment=XDG_RUNTIME_DIR=/run/user/1000

### Lines below this comment will be discarded

### /etc/systemd/system/node-red.service

```

This did not work, problem returned. Not sure I should have however as a test, I tried this with a reboot:

```auto
### Editing /etc/systemd/system/node-red.service.d/override.conf
### Anything between here and the comment below will become the new contents of the file

[Service]
Environment=XDG_RUNTIME_DIR=/run/user/$(id -u)

### Lines below this comment will be discarded

### /etc/systemd/system/node-red.service

```

This does not work either. Stumped again ..

EDIT: It does not work when I let NR start naturally (auto) after a reboot however if I stop NR and restart using` node-red` it work.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [13 March 2025 15:42 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/12 "2025-03-13T15:42:29Z")

</div>

ok, try this:

1. `sudo systemctl edit nodered`
2. add as below:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2eab3c7228a051b8f7cad9bb49695786a3f04207.png)
3. save
4. run `node-red-stop`
5. run `node-red-start`

Then import the below flow...

```auto
[{"id":"1d55bee380340552","type":"inject","z":"20165f674cef3579","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":1450,"y":160,"wires":[["201910ef30ee3451"]]},{"id":"60ff7f8dbb9a49fe","type":"debug","z":"20165f674cef3579","name":"debug 10","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1500,"y":280,"wires":[]},{"id":"201910ef30ee3451","type":"function","z":"20165f674cef3579","name":" process.env","func":"msg.payload = process.env\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"process","module":"process"}],"x":1480,"y":220,"wires":[["60ff7f8dbb9a49fe"]]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1bf1964722864f36a7827b9dcbd512d2bb1d6145.png)

---

<div class="post-metadata">

**Author:** ![StrongTown](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@StrongTown](https://discourse.nodered.org/u/StrongTown)\
**Post date:** [13 March 2025 16:00 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/13 "2025-03-13T16:00:56Z")

</div>

Made changes. Rebooted. Results of your flow (FYI: '`amixer set Master 65%`' not working)

```auto
3/13/2025, 11:58:02 AM[node: debug 10](http://192.168.2.155:1880/#)msg.payload : Object

object

USER: "pi"

HOME: "/home/pi"

OLDPWD: "/usr/lib/node_modules/node-red/bin"

NODE_OPTIONS: "--max_old_space_size=1024"

SYSTEMD_EXEC_PID: "2165"

LOGNAME: "pi"

JOURNAL_STREAM: "8:12536"

PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

INVOCATION_ID: "fd671343e8524660a224b0d19f32eb66"

LANG: "en"

SHELL: "/bin/bash"

PWD: "/home/pi"

NODE_RED_HOME: "/usr/lib/node_modules/node-red"

PYTHONUNBUFFERED: "1"

```

```auto
### Editing /etc/systemd/system/node-red.service.d/override.conf
### Anything between here and the comment below will become the new contents of the file

[Service]
Environment="TEST=321"
Environment="XDG_RUNTIME_DIR=/run/user/1000"

### Lines below this comment will be discarded

### /etc/systemd/system/node-red.service

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [13 March 2025 16:18 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/14 "2025-03-13T16:18:42Z")

</div>

> [@StrongTown](#):
>
> Results of your flow

As you can see, the env vars did NOT make it into your Node-RED.

I also see you are editing `node-red.service` not `nodered.service`

> [@StrongTown](#):
>
> `### Editing /etc/systemd/system/node-red.service.d/override.conf`

Did you by some chance _create_ this using `Run 'systemctl edit --force --full node-red.service' to create a new unit.` ?

What happens if you do **exactly** what I said...

> [@Steve-Mcl](#):
>
> - `sudo systemctl edit nodered`
> - add as below:
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2eab3c7228a051b8f7cad9bb49695786a3f04207.png)
> 
> - save
> - run `node-red-stop`
> - run `node-red-start`

---

<div class="post-metadata">

**Author:** ![StrongTown](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@StrongTown](https://discourse.nodered.org/u/StrongTown)\
**Post date:** [13 March 2025 16:38 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/16 "2025-03-13T16:38:02Z")

</div>

My apologies` Steve-Mcl`. I did do it incorrectly. 😚 With the proper edit command it now works properly.

THANK YOU so much for your assistance. I would NEVER have figured his out on my own! 🙏

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 March 2025 16:39 UTC](https://discourse.nodered.org/t/exec-node-help-with-how-it-spawns/95957/17 "2025-03-27T16:39:01Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
