Unable to start Node-red upon boot

Thanks. The user/group in the nodered.service file were both root. Journalctl output is

/usr/bin/node-red-start: line 91: update-nodejs-and-nodered: command not found

root@raspbx:~# which node-red-start
/usr/bin/node-red-start
root@raspbx:~#
root@raspbx:~#

When you use node-red-start does it say it is using the systemd startup script?

It doesn't seem to say? I've posted a screenshot

Ok... here is a new node-red-start file

can you backup/rename the one in /usr/bin/node-red-start and try this one instead.

#!/bin/bash
#
# Copyright 2016,2017 JS Foundation and other contributors, https://js.foundation/
# Copyright 2015,2016 IBM Corp.
#
# 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.
echo -e '\033]2;'Node-RED console'\007'
if [[ $(which node-red) ]]; then
    if [[ ! $(which npm) ]]; then
        echo -e "\033[0m                                                  \033[0m"
        echo -e "\033[0m    npm is not installed, it is recommended       \033[0m"
        echo -e "\033[0m    to install the latest by running:             \033[0m"
        echo -e "\033[0m        update-nodejs-and-nodered                 \033[0m"
        echo -e "\033[0m                                                  \033[0m"
        echo -e " "
    fi
    HOSTIP=`hostname -I | cut -d ' ' -f 1`
    if [ "$HOSTIP" = "" ]; then
        HOSTIP="127.0.0.1"
    fi
    echo -e "\033[1mStart \033[38;5;88mNode-RED\033[0m"
    echo " "
    echo "Once Node-RED has started, point a browser at http://$HOSTIP:1880"
    echo "On Pi Node-RED works better with the Firefox or Chrome browser"
    echo " "
    if groups | grep -q -w sudo; then
        echo -e "Use   \033[0;36mnode-red-stop\033[0m                          to stop Node-RED"
        echo -e "Use   \033[0;36mnode-red-start\033[0m                         to start Node-RED again"
        echo -e "Use   \033[0;36mnode-red-log\033[0m                           to view the recent log output"
    fi
    echo -e "Use   \033[0;36msudo systemctl enable nodered.service\033[0m  to autostart Node-RED at every boot"
    echo -e "Use   \033[0;36msudo systemctl disable nodered.service\033[0m to disable autostart on boot"
    echo " "
    echo "To find more nodes and example flows - go to http://flows.nodered.org"
    if [ "$nv" = "v0" ]; then
        echo "You may also need to install and upgrade npm"
        echo -e "      \033[0;36msudo apt-get install npm\033[0m"
        echo -e "      \033[0;36msudo npm i -g npm@2.x\033[0m"
    fi
    if groups $USER | grep -q -w sudo; then
        # Current user is member of sudo group, start node-red through systemd
        sudo systemctl start nodered
        echo " "
        echo "Starting as a systemd service."
        sudo journalctl -f -n 0 -u nodered -o cat
    elif groups $USER | grep -q -w root; then
        systemctl start nodered
        echo " "
        echo "Starting as root systemd service."
        journalctl -f -n 0 -u nodered -o cat
    else
        # Start node-red as unprivileged user
        echo " "
        echo "Starting as a normal user."
        node-red-pi
    fi
else
    echo "Node-RED is not yet fully installed."
    bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
    if [ $? -eq 0 ]; then
        read -p "Would you like to start Node-RED now (y/N) ? " yn
        case $yn in
            [Yy]* )
                node-red-start
            ;;
            * )
                echo " "
                exit
            ;;
        esac
    fi
fi

Once created you may need to make it executable - chmod +x node-red-start

Thank you - sadly this one just seems to hang

root@raspbx:~# rm /usr/bin/node-red-start
root@raspbx:~# nano /usr/bin/node-red-start
root@raspbx:~# chmod +x /usr/bin/node-red-start
root@raspbx:~# sudo systemctl start nodered
root@raspbx:~# sudo journalctl -f -n 0 -u nodered -o cat


root@raspbx:~# sudo journalctl -f -n 0 -u nodered -o cat


root@raspbx:~# sudo journalctl -f -n 0 -u node-red -o cat


root@raspbx:~# node-red-start

Start Node-RED

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

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

Starting as root systemd service.
Node-RED is not yet fully installed.

Root user detected. Typically install as a normal user. No need for sudo.

-no further activity-

Getting closer (though it may not seem like it)
and this one... (no need to backup the last one :slight_smile:

#!/bin/bash
#
# Copyright 2016,2020 JS Foundation and other contributors, https://js.foundation/
# Copyright 2015,2016 IBM Corp.
#
# 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.
echo -e '\033]2;'Node-RED console'\007'
if [[ $(which node-red-pi) ]]; then
    if [[ ! $(which npm) ]]; then
        echo -e "\033[0m                                                  \033[0m"
        echo -e "\033[0m    npm is not installed, it is recommended       \033[0m"
        echo -e "\033[0m    to install the latest by running:             \033[0m"
        echo -e "\033[0m        update-nodejs-and-nodered                 \033[0m"
        echo -e "\033[0m                                                  \033[0m"
        echo -e " "
    fi
    HOSTIP=`hostname -I | cut -d ' ' -f 1`
    if [ "$HOSTIP" = "" ]; then
        HOSTIP="127.0.0.1"
    fi
    echo -e "\033[1mStart \033[38;5;88mNode-RED\033[0m"
    echo " "
    echo "Once Node-RED has started, point a browser at http://$HOSTIP:1880"
    echo "On Pi Node-RED works better with the Firefox or Chrome browser"
    echo " "
    if groups | grep -q -w sudo; then
        echo -e "Use   \033[0;36mnode-red-stop\033[0m                          to stop Node-RED"
        echo -e "Use   \033[0;36mnode-red-start\033[0m                         to start Node-RED again"
        echo -e "Use   \033[0;36mnode-red-log\033[0m                           to view the recent log output"
    fi
    echo -e "Use   \033[0;36msudo systemctl enable nodered.service\033[0m  to autostart Node-RED at every boot"
    echo -e "Use   \033[0;36msudo systemctl disable nodered.service\033[0m to disable autostart on boot"
    echo " "
    echo "To find more nodes and example flows - go to http://flows.nodered.org"
    if [ "$nv" = "v0" ]; then
        echo "You may also need to install and upgrade npm"
        echo -e "      \033[0;36msudo apt-get install npm\033[0m"
        echo -e "      \033[0;36msudo npm i -g npm@2.x\033[0m"
    fi
    if groups $USER | grep -q -w sudo; then
        # Current user is member of sudo group, start node-red through systemd
        sudo systemctl start nodered
        echo " "
        echo "Starting as a systemd service."
        sudo journalctl -f -n 0 -u nodered -o cat
    elif groups $USER | grep -q -w root; then
        # Current user is member of root group, start node-red through systemd
        systemctl start nodered
        echo " "
        echo "Starting as root systemd service."
        journalctl -f -n 0 -u nodered -o cat
    else
        # Start node-red as unprivileged user
        echo " "
        echo "Starting as a normal user."
        node-red-pi
    fi
else
    echo "Node-RED is not yet fully installed."
    bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) --confirm-root --confirm-install
    if [ $? -eq 0 ]; then
        read -p "Would you like to start Node-RED now (y/N) ? " yn
        case $yn in
            [Yy]* )
                node-red-start
            ;;
            * )
                echo " "
                exit
            ;;
        esac
    fi
fi
1 Like

Does this help?


root@raspbx:~# node-red-start

Start Node-RED

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

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

Starting as root systemd service.
Node-RED is not yet fully installed.

Root user detected. Typically install as a normal user. No need for sudo.



This script will remove versions of Node.js prior to version 7.x, and Node-RED a                                 nd
if necessary replace them with Node.js 12.x LTS (erbium) and the latest Node-RED                                  from Npm.

It also moves any Node-RED nodes that are globally installed into your user
~/.node-red/node_modules directory, and adds them to your package.json, so that
you can manage them with the palette manager.

It also tries to run 'npm rebuild' to refresh any extra nodes you have installed
that may have a native binary component. While this normally works ok, you need
to check that it succeeds for your combination of installed nodes.

To do all this it runs commands as root - please satisfy yourself that this will
not damage your Pi, or otherwise compromise your configuration.
If in doubt please backup your SD card first.

TERM environment variable not set.
Running Node-RED update for user root at /root on raspbian
    root : TTY=unknown ; PWD=/root ; USER=root ; COMMAND=/usr/bin/tee -a /var/lo                                 g/nodered-install.log
pam_unix(sudo:session): session opened for user root by (uid=0)
pam_unix(sudo:session): session closed for user root
    root : TTY=unknown ; PWD=/root ; USER=root ; COMMAND=/usr/bin/tee -a /var/lo                                 g/nodered-install.log
pam_unix(sudo:session): session opened for user root by (uid=0)
pam_unix(sudo:session): session closed for user root
    root : TTY=unknown ; PWD=/root ; USER=root ; COMMAND=/usr/bin/tee -a /var/lo                                 g/nodered-install.log
pam_unix(sudo:session): session opened for user root by (uid=0)
pam_unix(sudo:session): session closed for user root
    root : TTY=unknown ; PWD=/root ; USER=root ; COMMAND=/usr/bin/tee -a /var/lo                                 g/nodered-install.log
pam_unix(sudo:session): session opened for user root by (uid=0)
pam_unix(sudo:session): session closed for user root
    root : TTY=unknown ; PWD=/root ; USER=root ; COMMAND=/usr/bin/tee -a /var/lo                                 g/nodered-install.log
pam_unix(sudo:session): session opened for user root by (uid=0)
pam_unix(sudo:session): session closed for user root

This can take 20-30 minutes on the slower Pi versions - please wait.
  Stop Node-RED
  Remove old version of Node-RED
  Remove old version of Node.js
  Install Node.js
  Clean npm cache
  Install Node-RED core
  Move global nodes to local
  Install extra Pi nodes
Stopped Node-RED graphical event wiring tool.
  Add shortcut commands
  Update systemd script


Any errors will be logged to   /var/log/nodered-install.log
    root : TTY=unknown ; PWD=/root ; USER=root ; COMMAND=/usr/bin/tee -a /var/log/nodered-install.log
    root : TTY=unknown ; PWD=/root ; USER=root ; COMMAND=/usr/sbin/service nodered stop
pam_unix(sudo:session): session opened for user root by (uid=0)
pam_unix(sudo:session): session opened for user root by (uid=0)
Stopping Node-RED graphical event wiring tool...
pam_unix(sudo:session): session closed for user root
pam_unix(sudo:session): session closed for user root

And what does /var/log/nodered-install.log now contain ?

Just

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

Started : Mon 1 Jun 13:57:06 BST 2020
Running for user root at /root

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

Started : Mon 1 Jun 13:57:42 BST 2020
Running for user root at /root

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

Started : Mon 1 Jun 13:59:26 BST 2020
Running for user root at /root

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

Started : Mon 1 Jun 14:18:24 BST 2020
Running for user root at /root

OK - lets revert to basics..
clear out all the old stuff - nuke it from space.
apt purge nodejs npm
rm -rf /usr/bin/node*
rm -rf /usr/lib/node_modules/*
rm /root/.npm-packages/bin/node-red
rm /var/log/nodered-install.log
then check that node -v returns blank or not found and node-red-start is also not found.
then re run the bash script.
then do a node -v and npm -v and which node-red-pi to check where things are...
then hopefully a node-red-start

Sadly despite your amazing help I'm no better off.

Re: this page

"node-red-start - this starts the Node-RED service and displays its log output. Pressing Ctrl-C or closing the window does not stop the service; it keeps running in the background"

consistently for me this is not the case. As you can hopefully see in the trace below.

dpkg: warning: while removing nodejs, directory '/usr/include/node/openssl/archs/VC-WIN32' not empty so not removed
dpkg: warning: while removing nodejs, directory '/usr/include/node/openssl/archs/aix-gcc' not empty so not removed
dpkg: warning: while removing nodejs, directory '/usr/include/node/openssl/archs/linux-x32' not empty so not removed
dpkg: warning: while removing nodejs, directory '/usr/include/node/openssl/archs/linux64-s390x' not empty so not removed
Processing triggers for man-db (2.7.6.1-2) ...
root@raspbx:~# rm -rf /usr/bin/node*
root@raspbx:~# rm -rf /usr/lib/node_modules/*
root@raspbx:~# rm /root/.npm-packages/bin/node-red
root@raspbx:~# rm /var/log/nodered-install.log
root@raspbx:~# node -v+
-bash: node: command not found
root@raspbx:~# node -v
-bash: node: command not found
root@raspbx:~# node-red-start
-bash: /usr/bin/node-red-start: No such file or directory
root@raspbx:~# bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

Root user detected. Typically install as a normal user. No need for sudo.

Are you really sure you want to install as root ? (y/N) ? y


This script will remove versions of Node.js prior to version 7.x, and Node-RED and
if necessary replace them with Node.js 12.x LTS (erbium) and the latest Node-RED from Npm.

It also moves any Node-RED nodes that are globally installed into your user
~/.node-red/node_modules directory, and adds them to your package.json, so that
you can manage them with the palette manager.

It also tries to run 'npm rebuild' to refresh any extra nodes you have installed
that may have a native binary component. While this normally works ok, you need
to check that it succeeds for your combination of installed nodes.

To do all this it runs commands as root - please satisfy yourself that this will
not damage your Pi, or otherwise compromise your configuration.
If in doubt please backup your SD card first.

Are you really sure you want to do this ? [y/N] ? y

Would you like to install the Pi-specific nodes ? [y/N] ? y

Running Node-RED install for user root at /root on raspbian


This can take 20-30 minutes on the slower Pi versions - please wait.

  Stop Node-RED                       ?
  Remove old version of Node-RED      ?
  Remove old version of Node.js       ?  v0
  Update Node.js LTS                  ?   Node v12.17.0   Npm 6.14.4
  Clean npm cache                     ?
  Install Node-RED core               ?   1.0.6
  Move global nodes to local          -
  Install extra Pi nodes              ?
  Npm rebuild existing nodes          -
  Add shortcut commands               ?
  Update systemd script               ?


Any errors will be logged to   /var/log/nodered-install.log
All done.
  You can now start Node-RED with the command  node-red-start
  or using the icon under   Menu / Programming / Node-RED
  Then point your browser to localhost:1880 or http://{your_pi_ip-address}:1880

Started  Mon  1 Jun 15:17:32 BST 2020  -  Finished  Mon  1 Jun 15:20:31 BST 2020

root@raspbx:~# node -v
+v12.17.0
root@raspbx:~# +npm -v
-bash: +npm: command not found
root@raspbx:~# npm -v
6.14.4
root@raspbx:~# which node-red-pi
/root/.npm-packages/bin/node-red-pi
root@raspbx:~# node-red-start

Start Node-RED

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

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

Starting as a normal user.
1 Jun 15:21:36 - [info]

Welcome to Node-RED
===================

1 Jun 15:21:36 - [info] Node-RED version: v1.0.6
1 Jun 15:21:36 - [info] Node.js  version: v12.17.0
1 Jun 15:21:36 - [info] Linux 4.19.57-v7+ arm LE
1 Jun 15:21:37 - [info] Loading palette nodes
1 Jun 15:21:42 - [info] Settings file  : /root/.node-red/settings.js
1 Jun 15:21:42 - [info] Context store  : 'default' [module=memory]
1 Jun 15:21:42 - [info] User directory : /root/.node-red
1 Jun 15:21:42 - [warn] Projects disabled : editorTheme.projects.enabled=false
1 Jun 15:21:42 - [info] Flows file     : /root/.node-red/flows_raspbx.json
1 Jun 15:21:42 - [info] Creating new flow file
1 Jun 15:21:42 - [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.
---------------------------------------------------------------------

1 Jun 15:21:42 - [info] Starting flows
1 Jun 15:21:42 - [info] Started flows
1 Jun 15:21:42 - [info] Server now running at http://127.0.0.1:1880/
CONTROL-C HAPPENS HERE
1 Jun 15:22:54 - [info] Stopping flows
1 Jun 15:22:54 - [info] Stopped flows
root@raspbx:~# sudo systemctl enable nodered.service
root@raspbx:~# sudo reboot

oh - ok - so the final clue is where it's saying Starting as a normal user.
when of course you are running as root...
can you show me what groups root shows ?

@dclear can i check that you do, for some reason, want to run node-red as root?

one more edit... to /usr/bin/node-red-start
change the elif line at line 56 to be. (IE just check the user is root not the group)

        sudo journalctl -f -n 0 -u nodered -o cat
    elif [ $EUID -eq 0 ]; then
        # Current user is root, start node-red through systemd
        systemctl start nodered

Progress! I edited line 56 to look like the below (couldn't see there was an elif to replace but there was one to add, is that right?)

Screenshot 2020-06-01 at 19.24.38

Anyway, the result the first time I tried node-red-start it DID start the service and it did it like a service, ie the command didn't block, it returned to a command prompt, if that makes sense.

The second time I tried it does the same thing, but doesn't start node-red.

root@raspbx:~# sudo journalctl -f -n 0 -u nodered -o cat
nodered.service: Failed with result 'exit-code'.

Huge thanks for the help on this

well it's already started - so you can't start it again... until after you have stopped it with node-red-stop...

If you're root then you don't need the sudo for the journalctl command.

And thank you for being so patient while we worked through all this. Hopefully I have improved the script in the meantime so that others that follow you don't have quite the same amount of pain...
(but we shall see... :wink:

Thanks :slight_smile: I think we're nearly there. I did a full wipe and reinstalled using the bash script. I saw that the bash script now includes the changes you had me make earlier. But Node-Red still doesn't start. If I do node-red-start I just get this:
Screenshot 2020-06-01 at 20.58.17
If I do systemctl start nodered.service then sudo journalctl -f -n 0 -u nodered -o cat I get this (nothing)
Screenshot 2020-06-01 at 20.58.42
The only thing that actually starts node-red is calling node-red-pi, but then of course it terminates as soon as I ctrl-c or leave the ssh session. It's not running as a service and seems determined not to run as a service. It's only successfully run as a service once, almost seems like a blip because it won't do it again...! I just did a sudo reboot and it hasn't started.
Sorry to bother you...any tips?

EDIT: Just tried to reinstall as nodered user

Running Node-RED install for user nodered at /home/nodered on raspbian

[sudo] password for nodered: 

This can take 20-30 minutes on the slower Pi versions - please wait.

  Stop Node-RED                       ✔
  Remove old version of Node-RED      ✔
  Remove old version of Node.js       ✔  v0
  Update Node.js LTS                  ✔   Node v12.17.0   Npm 6.14.4
  Clean npm cache                     ✔
  Install Node-RED core               ✔   
  Move global nodes to local          -
  Install extra Pi nodes              ✔
  Npm rebuild existing nodes          -
  Add shortcut commands               ✔
  Update systemd script               ✔
                                      

Any errors will be logged to   /var/log/nodered-install.log
All done.
  You can now start Node-RED with the command  node-red-start
  or using the icon under   Menu / Programming / Node-RED
  Then point your browser to localhost:1880 or http://{your_pi_ip-address}:1880

Started  Mon  1 Jun 21:04:07 BST 2020  -  Finished  Mon  1 Jun 21:07:04 BST 2020

nodered@raspbx:~ $ sudo systemctl enable nodered.service
nodered@raspbx:~ $ node-red-start

Node-RED is not yet fully installed. Please re-run the install script again manually.
 
   bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
 
then retry  node-red-start
 
nodered@raspbx:~ $

uuurgh - please don't keep jumping around... either we do this as a user or as root - once you start mixing it up we get int the mess we are in. I thought we were using root as that is where your "old" flows were ?
To get it to autostart you need to do the blue command above (but without sudo as you are already root).
I thought I also said not to use sudo for the journalctl command ? (as you are already root)
You can also drop the -n 0 parameter as that starts it from then onwards rather than showing a few previous lines of history.

Really sorry - I jumped around because I think it might be helpful for debugging. And I was genuinely curious if the whole problem stemmed from the 'root' issue.