Unable to start Node-red upon boot

I'm trying to autorun Node-red on a laptop running Ubuntu 18.04.3 LTS Bionic.
I followed below web page...

"node-red" command works.
But I can get Node-red to run on boot!
Can anyone help me troubleshoot this, please?

Thank
IDeeW

I also tried below solution but the issue is still there...

If you install node red using the pi install script, which also works on Ubuntu, that will setup the systemd script for you. Doing this will not destroy your existing flows, though I am sure you have backups anyway.

That tutorial says that it installs nodejs version 4.x, which went out of support years ago You need at least 10.x to run the current node red version.

Ok. Let me try the Pi scripts.
Trying out Node-Red for the first time. So no existing flows to back up..
will update the results...

Thanks

this is what happens after I run "node-red" command

But "sudo systemctl start node-red" will not run Node-red.
image

It does run node-red, but in the background. node-red-start is like an alias that combines the background starting with viewing the log file. See sudo systemctl status nodered to verify that it runs. Or node-red-log to view the logs at any time.
To have it start on boot, sudo systemctl enable nodered.

ok. I enabled it.

But still nothing after reboot.

Thanks

and what does node-red-log say? or sudo systemctl status nodered for that matter?

Here's what it looks like on my ubuntu server 19.10, installed through the script and set to run on boot through sudo systemctl enable nodered.

if it didn't start because of an error, it will show in the status command

ohh...
This is whats on mine.....:frowning:

node-reg-log.....nothing!
image

What does node-red-start show. That should start it with systemd and then show the startup messages

Odd, post here /lib/systemd/system/nodered.service I suspect there is an issue there. Can you copy/paste logs and file contents rather than screenshot, it is much easier to deal with? Thanks.

[Edit] Also what do
ls -l /usr/bin/env
and
which env
show?

I have the script on the below path

/etc/systemd/system/node-red.servic

I added the .txt to the end
node-red.service.txt (380 Bytes)


indika@WEERAServer:~$ node-red-start

Start Node-RED

Once Node-RED has started, point a browser at http://192.168.0.96:1880
On Pi Node-RED works better with the Firefox or Chrome browser

Use node-red-stop to stop Node-RED
Use node-red-start to start Node-RED again
Use node-red-log to view the recent log output
Use sudo systemctl enable nodered.service to autostart Node-RED at every boot
Use sudo systemctl disable nodered.service to disable autostart on boot

To find more nodes and example flows - go to http://flows.nodered.org
[sudo] password for indika:

Starting as a systemd service.
nodered.service: Service hold-off time over, scheduling restart.
nodered.service: Scheduled restart job, restart counter is at 1.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.
nodered.service: Failed to determine user credentials: No such process
nodered.service: Failed at step USER spawning /usr/bin/env: No such process
nodered.service: Main process exited, code=exited, status=217/USER
nodered.service: Failed with result 'exit-code'.
nodered.service: Service hold-off time over, scheduling restart.
nodered.service: Scheduled restart job, restart counter is at 2.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.
nodered.service: Failed to determine user credentials: No such process
nodered.service: Failed at step USER spawning /usr/bin/env: No such process
nodered.service: Main process exited, code=exited, status=217/USER
nodered.service: Failed with result 'exit-code'.
nodered.service: Service hold-off time over, scheduling restart.
nodered.service: Scheduled restart job, restart counter is at 3.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.
nodered.service: Failed to determine user credentials: No such process
nodered.service: Failed at step USER spawning /usr/bin/env: No such process
nodered.service: Main process exited, code=exited, status=217/USER
nodered.service: Failed with result 'exit-code'.
nodered.service: Service hold-off time over, scheduling restart.
nodered.service: Scheduled restart job, restart counter is at 4.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.
nodered.service: Failed to determine user credentials: No such process
nodered.service: Failed at step USER spawning /usr/bin/env: No such process
nodered.service: Main process exited, code=exited, status=217/USER
nodered.service: Failed with result 'exit-code'.
nodered.service: Service hold-off time over, scheduling restart.
nodered.service: Scheduled restart job, restart counter is at 5.
Stopped Node-RED graphical event wiring tool.
nodered.service: Start request repeated too quickly.
nodered.service: Failed with result 'exit-code'.
Failed to start Node-RED graphical event wiring tool.


indika@WEERAServer:~$ sudo systemctl status nodered

[sudo] password for indika:
â—Ź nodered.service - Node-RED graphical event wiring tool
Loaded: loaded (/lib/systemd/system/nodered.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2019-10-31 12:55:58 EDT; 45min ago
Docs: Redirecting…
Process: 1362 ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS (code=exited, status=217/USER)
Main PID: 1362 (code=exited, status=217/USER)

Oct 31 12:55:58 WEERAServer systemd[1]: nodered.service: Service hold-off time over, scheduling restart.
Oct 31 12:55:58 WEERAServer systemd[1]: nodered.service: Scheduled restart job, restart counter is at 5.
Oct 31 12:55:58 WEERAServer systemd[1]: Stopped Node-RED graphical event wiring tool.
Oct 31 12:55:58 WEERAServer systemd[1]: nodered.service: Start request repeated too quickly.
Oct 31 12:55:58 WEERAServer systemd[1]: nodered.service: Failed with result 'exit-code'.
Oct 31 12:55:58 WEERAServer systemd[1]: Failed to start Node-RED graphical event wiring tool.
indika@WEERAServer:~$


indika@WEERAServer:~$ node-red

31 Oct 13:43:31 - [info]

Welcome to Node-RED

31 Oct 13:43:31 - [info] Node-RED version: v1.0.2
31 Oct 13:43:31 - [info] Node.js version: v8.10.0
31 Oct 13:43:31 - [info] Linux 4.15.0-66-generic x64 LE
31 Oct 13:43:33 - [info] Loading palette nodes
31 Oct 13:43:43 - [info] Settings file : /home/indika/.node-red/settings.js
31 Oct 13:43:43 - [info] Context store : 'default' [module=memory]
31 Oct 13:43:43 - [info] User directory : /home/indika/.node-red
31 Oct 13:43:43 - [warn] Projects disabled : editorTheme.projects.enabled=false
31 Oct 13:43:43 - [info] Flows file : /home/indika/.node-red/flows_WEERAServer.json
31 Oct 13:43:43 - [warn]


Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.

31 Oct 13:43:43 - [info] Starting flows
31 Oct 13:43:43 - [info] Started flows
31 Oct 13:43:43 - [info] Server now running at http://127.0.0.1:1880/

That is not the right service file. Look at the systemd status output and you will see it is where I suggested. Also the one you have posted is node-red.service, whereas the correct one is nodered.service.
Sorry, I didn't mean you to repost all the stuff you had already posted, I just meant for the future, the systemd script for example. I you click the </> button above the edit box when posting and paste the text there it will stop the forum from reformatting it.

Also what do
ls -l /usr/bin/env
and
which env
show?

indika@WEERAServer:~$ ls -l /usr/bin/env
-rwxr-xr-x 1 root root 35000 Jan 18  2018 /usr/bin/env
indika@WEERAServer:~$ which env
/usr/bin/env
indika@WEERAServer:~$

Also make sure you systemctl disable node-red or it will be trying to run that one on boot as well as nodered.service.

Well env looks alright, so I think it is back to the systemd script, if you can find the right one. It must be there as systemd status found it.

found it under "/lib/systemd/system/"
nodered.service.txt (917 Bytes)

Thanks

[edit]
YES....that's it...
everything is working as soon as I change the user & group to "indika".....

Thanks u so much Colin and everyone.

....can not reply my daily limit is over....

Below is the log /var/log/nodered-install.log

***************************************

Started : Thu Oct 31 00:01:23 EDT 2019
Running for user indika at /home/indika
Failed to stop nodered.service: Unit nodered.service not loaded.
Found global nodes:   :

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package nodered
Now install nodejs
Updating nodejs v0
Not using nodesource.list

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
Package 'nodejs-legacy' is not installed, so not removed
Package 'npm' is not installed, so not removed
Package 'nodejs' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 15 not upgraded.
dpkg: warning: ignoring request to remove nodejs which isn't installed
dpkg: warning: ignoring request to remove node which isn't installed

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
0 upgraded, 0 newly installed, 0 to remove and 15 not upgraded.
Grab the LTS bundle

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Hit:1 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Err:4 http://plex.r.worldssl.net/PlexMediaServer/ubuntu-repo lucid InRelease
  Could not resolve 'plex.r.worldssl.net'
Get:5 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Fetched 252 kB in 2s (150 kB/s)
Reading package lists...
Building dependency tree...
Reading state information...
15 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: Failed to fetch http://plex.r.worldssl.net/PlexMediaServer/ubuntu-repo/dists/lucid/InRelease  Could not resolve 'plex.r.worldssl.net'
W: Some index files failed to download. They have been ignored, or old ones used instead.

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...

Well that is very odd, the install script has not put your user name in the script. I presume you were logged in as your normal user when you ran the script, and didn't use sudo. Whatever, to fix it edit that file and change the user and group from pi to your user name (indika). Then so that systemd will reload it
sudo systemctl daemon-reload
then
node-red-start
Assuming that fixes it I would like to understand what went wrong. Can you post the install log please, /var/log/nodered-install.log

[Edit] Oh, change the Working Directory too.