Exec Node, connection refused in service mode, ok when lnode red launched from terminal

Hello,
I have a flow executing commands to pulseaudio on a raspberry pi.
The flow works great when i launch node-red from the terminal (trough ssh), but when node red run as a service it is doing this error:
"
Command failed: pactl list sink-inputs
Connection failure: Connection refused
pa_context_connect() failed: Connection refused
"

I found this topic which i think is related:

If i understood well this is "because pulseaudio requires an Xwindow environment to run"

So how should i change the nodered.service file to enable the Xwindow environnement in service mode?

Thanks a lot for your help, i'm pretty new to linux and any help will be much appreciated!

Having done some research (ie google) it appears that it may be that if you want to access pulseaudio from node-red running as a system service then you will have to run pulseaudio as a system service too. Apparently it runs by default as a User service rather than a System service. I am working at the edge of my knowledge here though, so I might be wrong. As to how to run pulseaudio as a system service rather than a user service I don't know.

hi Colin and thanks for your answer.

Indeed, after questionning chatGPT for some time, it finally helped me to find a solution which is working!

If i understood well, it is indeed needed to start pulseaudio as a service.

So there is it's solution:

Modifying the file node-red.service with this content will make sure that pulseaudio runs as a service before starting node-red:

[Unit]
Description=Node-RED graphical event wiring tool
Wants=network.target
# here
After=pulseaudio.service
Documentation=http://nodered.org/docs/hardware/raspberrypi.html

[Service]
Type=simple
User=pi
Group=pi
WorkingDirectory=/home/pi

Environment="NODE_OPTIONS=--max_old_space_size=2048"
EnvironmentFile=-/home/pi/.node-red/EnvironmentFile

# and here
ExecStartPre=/usr/bin/pulseaudio --start
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
KillSignal=SIGINT
Restart=on-failure
RestartSec=20
SyslogIdentifier=Node-RED

[Install]
WantedBy=multi-user.target

at least it works for me!

1 Like

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