Yes, it does just that.
The bottom line is that my script doesn't run when I sudo node red start...
.
Only when node red start.....
I test it printenv
That does not make sense. Do you mean your script runs if you use
node-red
but not if you use
sudo systemctl start nodered
The first runs node red in the command window environment, the second runs it as a systemd service. The difference is not the sudo, it is the way it is being run that is different.
If it is as I have described then it is the environment difference that is causing the problem, so try printenv as I suggested.
That makes sense.
I'm testing printenv now
GalZoli@raspberrypi:~ $ sudo node-red-start
printenv :
LANGUAGE=hu_HU.UTF-8
USER=GalZoli
HOME=/home/GalZoli
OLDPWD=/usr/lib/node_modules/node-red/bin
NODE_OPTIONS=--max_old_space_size=1024
LOGNAME=GalZoli
JOURNAL_STREAM=8:14428
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
INVOCATION_ID=428915xxxxxxxxxxx69d26d
LANG=hu_HU.UTF-8
SHELL=/bin/bash
PWD=/home/GalZoli
NODE_RED_HOME=/usr/lib/node_modules/node-red
NTBA_FIX_319=1
PYTHONUNBUFFERED=1
/////////////////////////////////////////////////////////////////////////
GalZoli@raspberrypi:~ $ node-red
printenv :
SHELL=/bin/bash
LANGUAGE=hu_HU.UTF-8
NO_AT_BRIDGE=1
PWD=/home/GalZoli
LOGNAME=GalZoli
XDG_SESSION_TYPE=tty
MOTD_SHOWN=pam
HOME=/home/GalZoli
LANG=hu_HU.UTF-8
LS_COLORS=rs=0:di=01;3............... etc
That's exactly what I mean!
Probably something in there is making the difference.
I moved my script to the .node-red folder. debug bigexec:
: Error terminating PortAudio: PortAudio not initialized [PaErrorCode -10000]
_terminate() File "/home/GalZoli/.local/lib/python3.9/site-packages/sounddevice.py", line 2851, in _terminate
Expression 'parameters->channelCount <= maxChans' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1513
Expression 'ValidateParameters( inputParameters, hostApi, StreamDirection_In )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2813
This results in this:
NODE_RED_HOME=/usr/lib/node_modules/node-red
So your Node-RED userDir is in a location only accessible to root. Also, Node-RED can now to ANYTHING to your system. See the recent thread on hacked instances if you need more help in understanding why this is a bad idea. But also, one slip of a flow could easily destroy your whole system.
For example, run an exec node with the command rm -R /etc
(hint - really don't run that!)
You also aren't telling us some important stuff. When you say your script doesn't run, do you mean Node-RED itself doesn't run - and if so, please show use the error log. Or simply that your flow doesn't run - in which case show use the errors from your flow.
Is this the error from your flow? If so, this proves what people have been trying to tell you. When you run Node-RED in the way that fails, it is because ALSA can't run because the environment is wrong.
None of this has anything to do with Node-RED itself. Sort out running Node-RED correctly first, then sort out the ALSA environment.
PS: In my view, Audio is a bag of spanners on Linux. If it doesn't work first time, you will probably spend weeks hunting through forums trying to get it to work - at least that's my experience.
I don't think that is correct. node-red-start
runs sudo systemctl start nodered
so sudo should make little difference.
sudo node-red
is definitely a bad idea though.
sudo node-red
is definitely a bad idea though.
I tested sudo node-red.
It says
Starting as root systemd service.
But the node-red process is still owned by pi. (systemd always runs as root, username is derived from systemd script.)
pi 2154269 1 58 21:55 ? 00:00:22 node-red
I can't see any difference in the environment within Node-red started like that or sudo systemctl start nodered.
I tested sudo node-red.
It says
Starting as root systemd service.
Are you sure that was from sudo node-red
?
What does this show
which node-red
I would expect it to say /usr/bin/node-red, and if you look in that file I would expect it to start with
#!/usr/bin/env node
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
if (process.argv[2] === 'admin') {
try {
require("node-red-admin")(process.argv.slice(3)).catch(err => {
process.exit(1);
})
} catch(err) {
Are you sure that was from
sudo node-red
?
Nope. It was sudo node-red-start.
Can I blame autocomplete?
sudo node-red does indeed start it as root with User directory : /root/.node-red and which node-red is /usr/bin/node-red
I've always found it confusing that you can start Node-red with node-red
, node-red start
or node-red-start
but the right way seems to be sudo systemctl start nodered
node-red start
That starts node red, expecting the files file to be in a file called start, so you probably never want to do that.
node-red-start runs the systemctl command to start node red as a service and then shows the node red log in the terminal. I normally use node-red-start, there is normally little need to use the command node-red
on a pi.
node-red - starts Node-RED as the current user in the users environment.
sudo systemctl start nodered - start Node-RED as a system service using the user specified in the service file. Useful for starting long running service that keeps running if you close session.
node-red-start - easier to type alias for above that also then tails the log file so you see what is happening. This is the recommended way to do it.
node-red start - starts Node-RED as the local user with a parameter ( the flow file name) of start. Def wrong way to do it.
Also ( if installed using our script)
node-red-stop - stops the service
node-red-log - just tail the current log file.
node-red-reload - stop and restart the service
It is for these reasons I learn to start and stop things directly and learn the direct way to install and update things - so that I don't confuse myself.
node-red-start - easier to type alias for above that also then tails the log file so you see what is happening. This is the recommended way to do it.
I find tailing the log file a pain in the tail!
But on the occasions when I do want to see the output, eg after a reinstall, I find node-red
does the job.
node-red start - starts Node-RED as the local user with a parameter ( the flow file name) of start. Def wrong way to do it.
I almost always use sudo systemctl restart nodered
.
But if you search through this forum you can find many examples of people saying they ran node-red start
If as a beginner you do run node-red start
you get an empty editor, no sign that you made a mistake. If you deploy it creates a flowfile called start (not start.json) and now you must always use node-red start
to see your flows.
Perhaps the node-red script would be better if it accepted a flag -f flowfilename and to avoid breaking changes, a warning if a parameter was used as the flow file name without this flag?
ps See this thread for an example of mutual misunderstandings around the start-up command
I find tailing the log file a pain in the tail!
I simply put the journalctl command in to the package.json scripts then I don't have to remember the command.
I almost always use
sudo systemctl restart nodered
.
Again, I put that into package.json. So I can do:
npm restart
or
npm log
Again, I put that into package.json. So I can do:
npm restart
Well yes. You can do sudo service nodered restart
too.
The point I wanted to highlight was that a lot of people say they start Node-red in a manner which @dceejay says is "Def[initely] the wrong way" because of the whole hyphen/no hyphen confusion, and the startup script could be tweeked to warn them.
Or the right commands could be baked into the package.json file.
But I am not disagreeing with you.
the startup script could be tweeked to warn them.
When you run ānode-redā anything it invokes node-red directly skipping any script. So nothing can be tweaked there. It would need to be in the core.